Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] reading audio

38 views
Skip to first unread message

Vu Ngoc San

unread,
Dec 4, 2006, 4:22:39 AM12/4/06
to Caml Mailing List
Hello

is there a library available for reading wav files in ocaml and, say,
convert it to a bigarray or something equivalent ?

I had a look at sdl_mixer, which does read wav files, but it seems that
you don't have physical accesss to the audio if you wanted to modifiy it
in memory. (or I missed something). All you can do is play/mix it. I
guess it should not be too hard to look at the C code and come up with a
nice ocaml interface for converting the audio chunk into a bigarray, but
that's beyond my capabilities.

I looked at the list archive and back in 2003 some people had similar
whishes. Maybe this have evolved ?

Thanks for you help.


San


_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

David Baelde

unread,
Dec 4, 2006, 4:35:35 AM12/4/06
to Vu Ngoc San
Hi,

It would be nice to have a binding of libsndfile for that kind of
purpose. Unfortunately I don't think we have one yet.

For what it's worth, there is a Wav module at
<https://svn.sourceforge.net/svnroot/savonet/trunk/liquidsoap/src/tools/>.
Simply remove the conversion of format to Mixer.format and there
shouldn't be any external dependency left.

I know that it doesn't handle some formats, but .. it's good enough
for us most of the time. If anybody does ocaml-libsndfile I'd be happy
to use it instead.

Cheers.
--
David

Erik de Castro Lopo

unread,
Dec 4, 2006, 5:04:34 AM12/4/06
to caml...@yquem.inria.fr
David Baelde wrote:

> Hi,
>
> It would be nice to have a binding of libsndfile for that kind of
> purpose. Unfortunately I don't think we have one yet.

Since I (the main author of libsndfile) is also an Ocaml user
I really should get around to doing that.

However, the Ocaml version would not ba able to have functions
for reading shorts or ints, just a function for reading doubles
(as Ocaml floats). Same for the write side.

libsndfile would however do the conversion between the ocaml
level floats at whatever the disk file format required.

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+
"The problem with using C++ ... is that there's already a strong
tendency in the language to require you to know everything before
you can do anything." -- Larry Wall

Vu Ngoc San

unread,
Dec 4, 2006, 5:39:53 AM12/4/06
to Erik de Castro Lopo
Erik de Castro Lopo a écrit :

> David Baelde wrote:
>
>> Hi,
>>
>> It would be nice to have a binding of libsndfile for that kind of
>> purpose. Unfortunately I don't think we have one yet.
>
> Since I (the main author of libsndfile) is also an Ocaml user
> I really should get around to doing that.


That would be great. I am in fact teaching some signal processing, and
showing off my demos using ocaml instead of (****bad***) would be wonderful.

San

Richard Jones

unread,
Dec 4, 2006, 6:51:21 AM12/4/06
to Vu Ngoc San
On Mon, Dec 04, 2006 at 10:19:34AM +0100, Vu Ngoc San wrote:
> is there a library available for reading wav files in ocaml and, say,
> convert it to a bigarray or something equivalent ?

The WAV format is pretty simple. Have you tried just mapping the
file? You'll need to ignore the first "data samples" covering the
first 44 bytes of the file (the header).

http://ccrma.stanford.edu/courses/422/projects/WaveFormat/

Rich.

--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Internet Marketing and AdWords courses - http://merjis.com/courses - NEW!
Merjis blog - http://blog.merjis.com - NEW!

Erik de Castro Lopo

unread,
Dec 4, 2006, 2:33:49 PM12/4/06
to caml...@inria.fr
Richard Jones wrote:

> The WAV format is pretty simple. Have you tried just mapping the
> file? You'll need to ignore the first "data samples" covering the
> first 44 bytes of the file (the header).
>
> http://ccrma.stanford.edu/courses/422/projects/WaveFormat/

Yes, the most common WAV files are easy to parse but there are
a gazzillion extensions and corner cases to take care of.

So *please* don't lead people down that path, bcause next thing
they will be writting WAV files as well and they will make
a mistake and not follow the spec (so called) correctly and their
software will become popular and I (as the author of libsndfile)
will have to add yet another hack to work around someone else's
broken WAV file (libsndfile is already full of these).

I'm busy ATM, but give me a couple of weeks and I will make an
ocaml-libsndfile.

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+

"Whenever the C++ language designers had two competing ideas as to
how they should solve some problem, they said, "OK, we'll do them
both". So the language is too baroque for my taste." -- Donald E Knuth

0 new messages