File: display_text.sml

package info (click to toggle)
smlsharp 4.2.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 125,348 kB
  • sloc: ansic: 16,737; sh: 4,347; makefile: 2,228; java: 742; haskell: 493; ruby: 305; cpp: 284; pascal: 256; ml: 255; lisp: 141; asm: 97; sql: 74
file content (55 lines) | stat: -rw-r--r-- 1,312 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(**
 * display_text.sml
 *
 * @copyright (C) 2021 SML# Development Team.
 * @author UENO Katsuhiro
 * @version $Id: display_text.sml,v 1.3 2007/04/02 09:42:29 katsu Exp $
 *)

structure Display : DISPLAY =
struct

  structure PS = PowerSpectrum(
                   val numSamples = 2048
                   val samplingFreq = 44100.0
                 )
  structure SA = SpectrumAnalyzer(PS)
  structure IN = Input(PS)

  val interval = floor (PS.interval * 1000000.0)  (* usec *)

  fun dec n =
      let val s = "00" ^ Int.toString n
          val x = size s
      in if x > 3 then substring (s, x - 3, 3) else s
      end

  fun printAryAsInt ary =
      (Array.app (fn x => print (dec (floor x) ^ " ")) ary;
       print "\n")

  val buf = Array.array (20, 0.0)

  fun mainLoop input =
      let
        val _ = IN.fill input
        val _ = IN.read input
      in
        SA.toMonoral (IN.buffer, PS.samples);
        PS.calc ();
        SA.powerToHeight PS.spectrum;
        SA.summarize (PS.spectrum, 0, Array.length PS.spectrum, buf);
        printAryAsInt buf;
        Libc.usleep (interval div 4);
        if IN.finished input then () else mainLoop input
      end

  fun main () =
      let
        val input = IN.openInput ()
      in
        IN.startInput input;
        mainLoop input
      end

end