Additional material: Sonification and code (without Matlab)
Files for sound use extensions like .wav, .snd, .aiff, or .au,
cryptic headers, and arcane formats. Here's a simple way to get .snd
or .wav files with C code, which should then be playable on PCs and
UNIX machines. It's not the only way to proceed, of course, but it
should do the trick.
First, we write a raw data file:
- Declare your output variable as type float:
- Open a file for writing:
FILE *fopen(), *fdatafloat; /* file for output */
and
fdatafloat = fopen("data.flt", "w");
- Then write each point as raw data:
fwrite(&y,4,1,fdatafloat);
This should produce a raw data file called data.flt.
Then convert this to .snd format using Perry Cook's utility:
- Download the source of
float2wv.c;
plus the file waveio.h,
which needs to be included in your directory when you compile.
- Compile, with something like
lcc -o float2wv float2wv.c
- Then your output file can be converted with
float2wv data.flt out.snd
Important Note: The byte order is different on different
machines, and you need to choose which one you need by
commenting-in the appropriate definition in wavio.h (see the comments
in that file). I use
BIGENDIAN because I'm running on a SUN machine. I therefore
get .snd files. If you use BIGENDIAN you'll get .wav
files. Either should play on PCs and most other machines.
Another Note: If you're running on a Solaris machine, you
may find you need to use the Standard Desktop Environment so
that sdtaudio works properly.
Acknowledgements:
Thanks to guru and header therapist Prof. Perry Cook for
float2wav, among other goodies.
Ken Steiglitz, 8/12/02