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 56 57 58 59 60 61 62 63 64 65 66
|
(**
* display_curses.sml
*
* @copyright (C) 2021 SML# Development Team.
* @author UENO Katsuhiro
* @version $Id: display_curses.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 repeat 0 f = ()
| repeat n f = (f n; repeat (n - 1) f)
val buf = Array.array (80, 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);
Libcurses.clear ();
Array.appi
(fn (x, h) =>
repeat (floor (h / 100.0 * 20.0))
(fn y =>
(Libcurses.move (20 - y, x);
Libcurses.addch #"#")))
buf;
Libcurses.refresh ();
Libc.usleep (interval div 4);
if IN.finished input then () else mainLoop input
end
fun main () =
let
val input = IN.openInput ()
in
Libcurses.initscr ();
Libcurses.nocbreak ();
Libcurses.noecho ();
Libcurses.nonl ();
Libcurses.clear ();
Libcurses.refresh ();
IN.startInput input;
mainLoop input;
IN.closeInput input;
Libcurses.endwin ()
end
end
|