[erlang-questions] ANN: wave.erl
Ivan Uemlianin
ivan@REDACTED
Tue Jun 1 11:28:39 CEST 2010
Dear Kostas
Thank you for your comments.
> why don't you add the following to the file ...
The main reason I hadn't was that I haven't yet read Ch. 18 of Erlang
Programming (Types and Programming). I shall go and do so immediately.
I should like to start off with all this stuff in place.
Best wishes
Ivan
On 01/06/2010 10:19, Kostis Sagonas wrote:
> 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().
>
> ... AND FURTHER DOWN
>
> -spec write(wave(), F) -> {'ok', F} when is_subtype(F, file:filename()).
>
> -spec write(wave(), F, sample_rate()) -> {'ok', F} when is_subtype(F,
> file:filename()).
> --------------------------------------------------------------------------
>
>
> [although I do not see any compelling reason for the write functions
> to return {'ok', F} rather than just 'ok' at the moment.]
>
> Kostis
--
============================================================
Ivan A. Uemlianin
Speech Technology Research and Development
ivan@REDACTED
www.llaisdy.com
llaisdy.wordpress.com
www.linkedin.com/in/ivanuemlianin
"Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
(Schiller, Beethoven)
============================================================
More information about the erlang-questions
mailing list