starX has asked for the wisdom of the Perl Monks concerning the following question:

Once upon a time I started working on a project that would fade a sound file to a specified volume level over a specified amount of time. Fairly simple in theory, but in some of the theatrical work I do getting something like this working would go a long way. Here's the catch: I wrote it in C on a Linux based system, so the majority of my artistic brethren who want to know nothing of "this Lunocks thing" (as one so quaintly put it) can't use it.

Having recently found myself in a position where I'm leaving a barely trained operator in charge of a mildly complex run, I've decided that it's time to pull the thing off the shelf (where it's been gathering dust for three or four years) and remake it in a more cross-platform friendly format.

In the intervening time, I've become rather fond of Perl, but I've never done any audio programming in anything except C and Java. Has anyone around here created a Perl sound file player (Wav, MP3, Ogg, etc)? Any advice on some pitfalls I might run into? Does Perl implement mixer controls in a platform independent way, or will I still be needing to build for specific environments?

Any and all advice is appreciated.

Replies are listed 'Best First'.
Re: Audio programming portability
by zentara (Cardinal) on Jan 04, 2007 at 19:41 UTC
    Here is a basic demo for a Tk front end for SDL-> Tk Game Sound demo

    It handles separate channels, with separate volume for each. The problem you will run into is lack of drivers for all audio formats, but you could use some utility to temporarily convert them to wav or mp3.

    Another big project going now, is gstreamer , but it is significantly more complex than SDL. There is a Perl module for gstreamer, but is poorly documented. So for something quick and easy, use SDL, but for a long term major project, use gstreamer. Gstreamer has a good maillist where you can find answers, and if you need some help putting sliding volume controls on my Tk app, I can help you with that. It ought to be pretty easy. Remember, both SDL and Tk are event-loop systems, but you can use Tk's event-loop to handle SDL events, so it's a good match.

    P.S. SDL is probably easier cross-platform, since ActiveState has a module for it (for windows), whereas Gtk2 is still a bit tricky to make work on windows.


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Audio programming portability
by Joost (Canon) on Jan 04, 2007 at 19:28 UTC
Re: Audio programming portability
by Corion (Patriarch) on Jan 04, 2007 at 19:06 UTC

    I've done some audio programming, but I skipped on the hard parts and just used the fmod library. This was on Windows, but likely you'd be able to write an XS wrapper to make fmod do your bidding. I just loaded the fmod.dll via Win32::API, which isn't that portable.

Re: Audio programming portability
by toma (Vicar) on Jan 05, 2007 at 06:00 UTC
    I recommend that you use sox and wrap it in perl. Sox has a windows binary available.

    From the sox README:
    SoX (also known as Sound eXchange) translates sound files between different file formats, and optionally applies various sound effects.
    SoX is intended as the Swiss Army knife of sound processing tools. It doesn't do anything very well, but sooner or later it comes in very handy.

    Sox is also recommended in the TODO section of Audio::MPEG.

    If you need more effects than the batch processes that sox provides, you probably need a good UI - use Audacity.

    It should work perfectly the first time! - toma
Re: Audio programming portability
by starX (Chaplain) on Jan 10, 2007 at 18:17 UTC
    Thanks to everyone who responded to me on this. There certainly seem to be a lot of options available, and it looks like I've got quite a bit of research ahead of me.