[erlang-questions] ANN: wave.erl

Mazen Harake mazen.harake@REDACTED
Tue Jun 1 11:36:00 CEST 2010


Tip: It is Open Source... Submit a patch ;)

/Mazen

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
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>

---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com



More information about the erlang-questions mailing list