0

I need to get the actual audio samples sent to a specific sound card. Currently I'm using a Debian distro with Alsa. My searches failed, perhaps due to wrong keywords.

I don't want to record the audio, I just need the samples in real time accessible from my application (best is C++, but also Python is ok). Steal the output from the target sound card is also acceptable if it's not possible to get samples at the same time they are sent to it.

If you need other information please tell me in the comments.

2

"Recording" and "accessing the samples in real time" are basically the same thing.

Debian has Pulseaudio enabled by default, so the simplest way is to record (or "access the samples") from the associated .monitor source of the Pulseaudio sink of your soundcard. This will work out of the box.

From the Pulseaudio sink, the samples go through ALSA and are then sent to the card, so there's a slight delay. But the samples will be the exact samples sent.

There are probably other ways to do that, but all of them are a lot more complicated, and some depend on the type of soundcard you have.

With respect to delay, you should also keep in mind that "accessing the samples" will involve buffering, so there will be a delay, no matter what you do.

If you have more specific requirements, please explain your use case in more detail.

Edit

Pulseaudio sources and sinks are not files, but "objects" which represent, well, audio sources (physical ones like mics on your soundcards as well as virtual ones) and audio sinks (phyiscal ones like the speakers connected to your soundcard as well as virtual ones).

Every Pulseaudio sink like some-source-name has an associated source some-source-name.monitor. By using the Pulseuadio library from C++, from Python or from whatever language you like, you can connect to this source, and get samples in real-time that reflect whatever is put into this sink.

Again, no files involved, neither WAV nor any other format. What happens internally is that your application communicates with the Pulseaudio demon, and gets a buffer with samples in regular intervals.

The library is not trivial to use, have a look at some example code.

  • To be clear, "I don't want to record" means I can't use a program (i.e. arecord) to produce a wave file. If I understand correctly there is a file that I can read? The "associated .monitor source". – Mark Sep 11 at 4:54
  • Just to have a rough idea, would you mind to give me a brief descrition of an alternative (and more complicated) way that doesn't use Pulseaudio? – Mark Sep 14 at 5:53
  • 1
    Alternatives: (1) Use a bunch of ALSA plugins, including the loopback module, which is a bit of a pain to use because you'll have to fix the sample format in advance. (2) Hardware permitting, use a hardware loopback to record the outgoing samples. None of the alternatives will get you around having to use a library (ALSA or Pulseaudio) to get at the samples from your program. – dirkt Sep 14 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.