Subject: Re: How to capture sound from an application?
To: None <netbsd-help@netbsd.org>
From: Michael Core <520079546242-0001@t-online.de>
List: netbsd-help
Date: 06/25/2002 01:48:25
collver1@attbi.com wrote:

> > > "Michael Core" <520079546242-0001@t-online.de> wrote:
> > > > I want to capture the sound output from some applications and
> > > > redirect it to a file. How can this be done?
> > 
> If the application generating audio comes with source code, it should
> be trivial to modify the application to write to a normal file instead
> of a device file.

Actually, I have the source and I could do this. But I am more
interested in a solution which works even without the source. If the
application is linked dynamically against e.g. libsdl or libossaudio I
could compile a patched version of those which does the same.

> Another solution would be to write a device driver that provides the
> audio ioctl's, but sends the data to a buffer instead of to a dsp.  A
> problem could be reading the buffer frequently enough to ensure you
> have all the data and don't run out of kernel memory.  

I guess you would have to use two devices e.g. /dev/vdsp and
/dev/vdspmem. /dev/dsp would be linked against /dev/vdsp. vdsp offers a
"null" device which just accepts (nearly) anything and holds the samples
in a wrap-around FIFO. vdspmem could be used to read from from the FIFO.
vdsp shouldn't be very difficult and could be made from another
"stripped" sound driver. I'm not sure whether it's easy to access the
FIFO with vdspmem or if there's a limit for the memory usage (I'd prefer
to have at least a buffer for 3-4 seconds i.e. 0.5-1MB).

> Or maybe it could be done where you set up some space in a file, and
> use a utility similar to vnconfig, to have the kernel write the audio
> data to disk itself. 

I'd say you need something to start and stop the recording at any time
because the file can become very big quickly and you might only want a
part from the whole output. 

If there's really no solution yet, I'll maybe try to write such a driver
(pseudo-device). I just hope it isn't that terrible difficult.

Regards,
Michael