Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Alsa and audio capture
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 24 Nov 2003
Posts: 232
Location: Fort Collins, CO

PostPosted: Sun Mar 28, 2004 6:00 am    Post subject: Alsa and audio capture Reply with quote

I had thought about this before after visiting an artists web site and being dismayed that the free offerings were all streaming media. It made me wonder, what if I somehow make /dev/dsp a file or something. I tried and, of course, failed. Months later, my wife planned a course lesson around a radio show she had found which was offered in this format. She was quite upset to find after arriving in class that the network was down and she couldn't get the track... I did some research and found a solution.

If you have alsa drivers (or kernel > 2.6), alsa-oss, and alsa-utils installed, then you can capture streaming media directly. NOTE: I tried this under kde-3.1 and it did not work (even after disabling artsd), but under kde-3.2+, it works fine.

Edit the .asoundrc file in your home directory to look like this:

    pcm.copy {
        type plug
        slave {
          pcm hw
        route_policy copy

Now, in one terminal, try playing some audio:

play /usr/kde/3.2/share/sounds/KDE_Startup.wav

In another terminal, use this command:

arecord -f cd -t wav -D copy > capture.wav

This tells the alsa record utility to use cd quality sound in wav format using your defined 'copy' pcm device and put the output in capture.wav.

You will have to hand time this or write some script to synchronize these commands, but to simply test, the terminals work fine.

OK, now for the good stuff.

realplay file.smil

In one terminal and

arecord -f cd -t wav -d copy | lame - file.mp3

in another and you have just captured your streaming media and encoded it on the fly :)

You may get more mileage using the aoss LD_PRELOAD wrapper for the playing application, but I found this was not neccessary for the aforementioned app, as it seems to play directly to the native sound device.

NOTE: You may also get things to work by simply using:

arecord -f cd -t wav -d hw

My sound card is es1371, BTW.

Have fun
Back to top
View user's profile Send private message

Joined: 11 Jun 2003
Posts: 591
Location: Ontario, Canada

PostPosted: Wed Oct 06, 2004 9:44 pm    Post subject: Reply with quote

Thanks -- a useful tip! I had a bit of trouble getting it to work at first, though, since I use alsa's dmix plugin to allow playing sounds from multiple sources simultaneously: arecord gave me an error of "The dmix plugin supports only playback stream".

Fortunately, the problem was easily fixed with a bit of reconfiguration; alsa needs to use the alsa asym plugin to get both playback and capture working together. This alsa config (also in the wiki) was what I needed. Then, after adding the 'copy' pcm device as you describe, and enabling 'capture' on the PCM entry in alsamixer (with the space bar), I could record with arecord.

If it matters, this is with in-kernel alsa, with a 2.6.9-rc3 kernel, and a cmipci sound device.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum