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
|