Sound Spectrum Analysis
It reads 16 bit raw stereo sound stream data using C and POSIX library functions, it then uses GNU Scientific Library to compute sound spectrum, and it finally graphically display the result using Open GL library.
Here is a screen shot.
For those interested, the following is an outline of the code.
- It reads raw sound streem as signed 16-bit data stream from stdin using fdopen(3) and fread(3).
- Its SML# code converts the input 16 bit stream data into floating point data and stores into real arrays, and perform windowing.
- It calls FFT function in GSL library to perform fourier transformation.
- Its SML# code calculates the power spectrum from the result of the fourier transformation, and then converts them to decibel scale.
- Its SML# code prepares histgram data from the power spectrum and then graphically displays the result by calling OpenGL and GLUT.
- Repeat the above 1-5 steps.
As you can see, it successfully performs realtime animation despite the fact that functional code performs lots of floating point data manipulation on its virtual machine. We should also note that this entire program is a plain user-level SML# code, without using any special stubs or ''data conversion libraries'' etc.
This program require GNU Scientific Library installed.
It also uses experimental CConfig library. To run the program, consult the example of Graphical Animation Using Open GL and set the necessary environment variables.
env CPPFLAGS='-I/usr/X11R6/include -I/usr/local/include' \ LDFLAGS='-L/usr/X11R6/lib -L/usr/local/lib' smlsharp load.sml
Mac OS X:
env CPPFLAGS=-I/sw/include LDFLAGS=-L/sw/lib \ LDD='otool -L' smlsharp load.sml
env CPPFLAGS=-I/usr/X11R6/include LDFLAGS=-L/usr/X11R6/lib \ LIBNAME_SUFFIX=.dll LDD=cygcheck ARCSEP='\' smlsharp load.sml
You also need to prepare sound data stream in signed 16bit stereo raw format. If you do not have any sound stream tool at hand, then try the spectrum sample with the sine wave generator by compiling sine.c file.