[erlang-questions] ANN: wave.erl

Kostis Sagonas <>
Tue Jun 1 11:19:26 CEST 2010

Ivan Uemlianin wrote:
> Dear All
> Please find below wave.erl, an erlang script for reading and writing 
> .wav audio files.  I am releasing it under the ISC license.
> The script exports functions read/1, write/3 and write/2, and the wave 
> record:
>     -record(wave, {audio_format, sample_rate, data}).
> where:
> - audio_format is an unsigned integer (currently only 1, i.e. pcm 
> encoding, is supported);
> - sample_rate is an unsigned integer (i.e., samples per second, in kHz);
> - data is a list of lists of signed integers, one list for each channel 
> (e.g., stereo will have two lists of integers).
> read(FileName) reads a wav file and returns a wave record.
> write(WavRecord, FileName, BitsPerSample) writes the wave record 
> WavRecord to the file FileName with the sample size BitsPerSample.
> write(WavRecord, FileName) just calls write/3 with BitsPerSample = 16.

Rather than writing all the above, which is just words in a mail, why 
don't you add the following to the file which is machine-checkable 
documentation which is now part of the code?

-type audio_format() :: 1. % non_neg_integer() see wav docs for formats
-type sample_rate()  :: non_neg_integer().
-record(wave, {audio_format :: audio_format(),
                sample_rate  :: sample_rate(),
                data         :: [[integer()]]}).
-type wave() :: #wave{}.

-spec read(file:filename()) -> wave().


-spec write(wave(), F) -> {'ok', F} when is_subtype(F, file:filename()).

-spec write(wave(), F, sample_rate()) -> {'ok', F} when is_subtype(F, 

[although I do not see any compelling reason for the write functions to 
return {'ok', F} rather than just 'ok' at the moment.]


More information about the erlang-questions mailing list