Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sound lib haskell

Tags:

haskell

audio

I need to find a sound library for haskell. I have followed instructions of some that are presented in haskell wiki http://www.haskell.org/haskellwiki/Sound_data_structures but couldnt get any to work. All i need is to play audio files, regardless its format. I am developing a game with FunGen, and its time for music. I may have somo problems making them work togather, but I cant even play a simple sound example. Most of my problems are due to cabal installation, or dependancies I cant find anywhare. I am using Windows.

like image 524
Illiax Avatar asked Mar 19 '12 02:03

Illiax


2 Answers

Being on Windows is a major limitation in Haskell audio. Most packages are bindings to C code, and they tend to be either Linux-centric (JACK, Alsa) or at best nominally cross-platform but in practice difficult to build and use on Windows. You'll need to build or install the C library first before installing the Haskell binding.

Have you tried OpenAL? It's probably the most well-suited for what you want to do. If you install the C OpenAL libraries, the Haskell binding should be a fairly simple next step. There are a few add-on packages that are meant to simplify some common tasks, like ALUT and Alure.

Otherwise, most other solutions would actually involve several packages that may not work well together. hsndfile and hsndfile-vector are good for reading audio files (you'll need to have libsndfile installed), but they don't play sound. portaudio will play audio (again, you'll need the C portaudio library), but it hasn't been updated in a while (and some updates are badly needed). You'll also need to be moderately familiar with a C compiler chain (e.g. MinGW or Cygwin) to install the necessary C libraries first.

Another way might be to bind to a dedicated audio language such as Supercollider or Csound. This would be a rather heavyweight solution, but the bindings tend to be better-maintained and at least Csound should be easily installable on Windows (disclosure: I wrote the hCsound package). Sox (C library/executable) might also work for you (I've never tried it on Windows, but it claims to work).

like image 78
John L Avatar answered Sep 27 '22 18:09

John L


All i need is to play audio files, regardless its format.

Your best bet for this will be hsndfile, mentioned in John L.'s excellent answer above. But you may want to make your life easier initially. The WAV file format is a very simple format -- essentially consisting of raw PCM data with minimal headers prepended. Try to get a WAV file to play, and then broaden your horizons from there.

You will be fighting uphill against a lack of sample code -- and you may find yourself needing foreign memory pointers and other not-so-straightforward techniques -- but there's a decent sample for opening and reading a WAV file here.

Also, when developing on Windows, learn to love the -fno-ghci-sandbox flag. It tells ghci that you're connecting to a library that uses its own thread local storage. It's often the only way to get certain external libraries to work in GHCi.

like image 20
rtperson Avatar answered Sep 27 '22 17:09

rtperson