Skip to contentSkip to conversation

ahwmon: alsa "hw" what-you-hear recorder

PoC Sergey 2 participants 2 messages Jan 12, 2016 – Jan 21, 2016

lore
Share & tools
lore

Sergey

author
#0 lore raw

Hello.

I needed a tool to test if anything loud is playing right now. So I wrote "ahwmon" - alsa hw monitoring tool. It's based on dmix idea: it gets "hw" shared playback buffer, but reads from the buffer instead of writing.

Code is mostly copied from alsa-lib, but it uses kernel /dev/snd/pcm* files directly and doesn't depend on alsa-lib or dmix. May work for other apps playing to "hw", including pulseaudio and jackd.

What do you think about it? Can something like this get into alsa-lib or alsa-utils or alsa-plugins? It could be a capture side of "dmix" plugin, which has no capture now. Maybe someone with strong dmix knowledge can port it to dmix?

Build:
gcc -o ahwmon ahwmon.c

Usage:
./ahwmon [-v] [-v] <card_index> <device_index> [<subdevice_index>]
subdevice 0 is used by default
it outputs .wav stream to stdout

Use cases:
* Card VUmeter:
./ahwmon 0 0 | aplay -V stereo -D null
* Dump what you hear:
./ahwmon 0 0 > audiodump.wav
* Duplicate output of one card to another:
./ahwmon 0 0 | aplay -D plughw:1,0
* Stream what you hear to another pc:
./ahwmon 0 0 | nc 192.168.1.10 12345

Known limitations:
* supports S16_LE and S32_LE only.
* breaks clients attempting to close and reopen "hw"

Any ideas are welcome!

Signature · 1 line
  Sergey
#1 lore raw
Quoted 7 lines · Sergey

Hello.

I needed a tool to test if anything loud is playing right now. So I wrote "ahwmon" - alsa hw monitoring tool. It's based on dmix idea: it gets "hw" shared playback buffer, but reads from the buffer instead of writing.

Quoted 8 lines

Code is mostly copied from alsa-lib, but it uses kernel /dev/snd/pcm* files directly and doesn't depend on alsa-lib or dmix. May work for other apps playing to "hw", including pulseaudio and jackd.

What do you think about it? Can something like this get into alsa-lib or alsa-utils or alsa-plugins? It could be a capture side of "dmix" plugin, which has no capture now. Maybe someone with strong dmix knowledge can port it to dmix?

This is an interesting idea. I like the simplicity of your method, despite the known limitations. I suppose it can be well implemented as a normal alsa-lib plugin?

thanks,

Takashi

Quoted 26 lines

Build:
gcc -o ahwmon ahwmon.c

Usage:
./ahwmon [-v] [-v] <card_index> <device_index> [<subdevice_index>]
subdevice 0 is used by default
it outputs .wav stream to stdout

Use cases:
* Card VUmeter:
./ahwmon 0 0 | aplay -V stereo -D null
* Dump what you hear:
./ahwmon 0 0 > audiodump.wav
* Duplicate output of one card to another:
./ahwmon 0 0 | aplay -D plughw:1,0
* Stream what you hear to another pc:
./ahwmon 0 0 | nc 192.168.1.10 12345

Known limitations:
* supports S16_LE and S32_LE only.
* breaks clients attempting to close and reopen "hw"

Any ideas are welcome!

Signature · 1 line
  Sergey