views:

192

answers:

1

I am going to apologize in advance for being extremely vague, but my knowledge in this area is somewhat limited so I don't know the neccessary "keywords" to make my point/question clear. Sorry.

What I want to do is to find a way to obtain access to raw audio data as it is being output, say, when some external application is playing back music, when data is passed from the microphone to the output device and so on. I want to have access to that data in real time (well, almost real time, anyway), so that I can analyze/visualize it, etc.

I know, that it is certainly possible, as I've done it a long time ago in Java (I think I was using Processing and Minim libraries). This was done in windows by enabling a sort of "loopback" input device on the sound card (I think my vendor called it "Wave Out Mix" or something). How would one approach the same problem under a Linux-based OS?

I intend to use python for the analyzing/visualization part, however I can work in C if it is neccessary to get to the raw data.

Thanks in advance for any information.

+4  A: 

Whether you can access the "wave out" or "loopback" depends on your sound card and drivers.

The native sound API on Linux is called ALSA. Search for the ALSA docs and sample code and you should be able to get some code to record from your sound card, then hopefully set up your mixer so that you're recording from "wave out" instead of from the microphone.

The older Linux sound API (/dev/dsp) is called OSS. It's slightly simpler and ALSA emulates most of this API - but ALSA is the preferred solution if you want full access to your sound card.

You may want to check out Jack - it's a system for routing the audio output from one application to the input of another, in a big chain or all sorts of other configurations. There are lots and lots of compatible programs, and if everything you need already supports Jack, then you'll find it's by far the most straightforward API for this type of thing.

Finally, this may sound stupid, but you can get an analog loopback cable - a male-to-male stereo mini jack - and loop it from your headphone jack to your line in jack, and record "wave out" that way, no matter what soundcard you have. It's a stupid hack with an analog hole, but it does work, and depending on what you're trying to record, it may be good enough.

dmazzoni
Ok, thanks for the tips. I've skimmed through the Jack specification and it seems, that it could be something, that I need. I must stress, however, that in general I don't want to capture the output of a particular app, but rather, the resulting "wave out" output of the system. I'll see what can be done. Nice "hardware" hack with the analogue cord! :P I've, of course, done this before, for testing purposes.
shylent
oh my, somehow it seems that this got extremely complicated, I've spent quite some time figuring out how to enable analog loopback (alsa doesn't see it, even though it is seen under windows, whatever that means). I guess I'll have to find some other way. Thanks for the effort though.
shylent
I'm sorry to hear that; I know it can be frustrating.Depending on your goals and budget, maybe you could just buy a $10 sound card that's known to work for this purpose under Linux?
dmazzoni