bcrowell2 has asked for the wisdom of the Perl Monks concerning the following question:
I'm currently at the design stage on a perl app that will graph a sound spectrum from the mic in real time. Before I hitch my wagon to a sound input library that I'll regret, does anyone have any advice? I would prefer something that is well maintained, well documented, and available in a debian package rather than only from CPAN. It would be nice if it was cross-platform, but if it's linux-only that's OK. Here's what I've found so far:
Reading straight from /dev/dsp works, and in theory doesn't even require a library. However, Audio:OSS provides a mechanism for grabbing all the relevant constants out of soundcard.h so that you can set the sample rate, etc., via ioctl. The mechanism they use for this is that the Makefile.PL compiles a C program, which #includes soundcard.h, then outputs the relevant constants. These constants are then interpolated into the perl code that gets installed. I like the fact that this approach is pure-perl, because poorly engineered or poorly maintained XS can often be a problem. Disadvantages: not packaged for Debian, requires the end user to have a C compiler installed, some missing functionality (for setting mono input, which I therefore have to do by calling ioctl).
Audio::DSP seems easier to use than Audio::OSS, but there is a 7-year-old bug report of a memory leak that has never been fixed.
Are there other options I should know about? I'm planning to use gtk2-perl for the GUI. GTK does have some sound in its APIs (libcanberra), but so far I haven't succeeded in finding anything for sound input. If there is such a thing buried somewhere deep in the massive GTK API, that would be great, because gtk2-perl is packaged for Debian.
Re the constants in soundcard.h, are these actually subject to change, or not? I understand the philosophy in Audio::OSS of not hardcoding magic numbers in more than one place, but their approach forces me to impose dependencies on my end users that include a C compiler. It doesn't seem like soundcard.h can actually be generated by the OS on the fly with different constants depending on your sound card -- e.g., you can have two sound cards, but you can only have one soundcard.h. If the only real benefit I'm getting out of Audio::OSS is defining some constants, then it seems like I'd be better off ditching the Audio::OSS dependency and just hardcoding the constants myself.
Note that although there are various ways of popping up a dialog box to record a sound (by shelling out, etc.), these will not work for my application, which is supposed to use a live mic in real time.
Since my app will run on linux, I'm a little concerned about depending on ALSA's OSS emulation. I've had some experiences where the quality and performance of OSS emulation had some regressions during the recent period when sound on linux was going through growing pains. Is there any convenient way to access ALSA from perl?
TIA!
-Ben
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sound input library?
by zentara (Cardinal) on Dec 21, 2010 at 18:17 UTC |