2
votes

I'm using ALSA to configure a mic, but after some hours of search on stackoverflow/alsa doc/other sources, I don't understand how arecord work...

I'm trying to set a default record

Signed 16 bit Little Endian, Fréquence 48000 Hz, Stéréo

The equivalent arecord CLI command is (in my case) :

arecord /tmp/test.wav -f dat -D sysdefault:CARD=1

I try to do that with /etc/asound.conf

I write this :

pcm.!default {
  type asym
  playback.pcm {
    type plug
    slave.pcm "hw:1,0"
  }
  capture.pcm "multi"
}

pcm.multi {
  type plug
  slave.pcm "multiapps"
}

pcm.multiapps {
  type dsnoop
  ipc_key 666666
  slave {
    pcm "hw:1,0"
    format "S16_LE"
    rate 48000
  }
}

ctl.!default {
  type hw
  card 1
}

But when I try a simple :

arecord /tmp/test.wav or arecord /tmp/test.wav -D default

It fails with

Capture WAVE '/tmp/test.wav' : Unsigned 8 bit, Fréquence 8000 Hz, Mono arecord: set_params:1299: Ce format d'échantillonage n'est pas disponible Available formats: - S16_LE

Just to test, I try with

arecord /tmp/test.wav -D multi

I have a half success, it works but with bad configuration

Capture WAVE '/tmp/test.wav' : Unsigned 8 bit, Fréquence 8000 Hz, Mono

Can someone explain to me what I missed ? :|

Thanks !

-- EDIT --

I realize that /etc/asound.conf is overlapped by ~/.asound.

So, I copied the first in the second.

No more fatal on default, but always in 8k/8bit...

2

2 Answers

1
votes

Putting entries like format and rate into a slave definition restricts the possible configurations that an application can choose.

Most applications ask the device what configurations it actually supports. However, aplay/arecord do not; they always try to use the configuration you have set with parameters (or their silly defaults).

1
votes

The accepted answer is wrong:

You need to put format and rate entries in a slave definition if you are not happy with the default configuration (set by the soundcard driver I think) of the hardware. (In my case, the default is 16-bit audio, but I want 24-bit because mic signals can be very silent.)

Also in the application you need to specify format and rate if you are not happy with the default. In case of arecord, the default is the telephony standard 8b/8kHz (so not at all silly! - although I prefer 16b/32kHz).

If you have provided the correct ALSA elements that can convert the hardware format to the application format, it will be converted automatically (do arecord -v to see the conversions). You use 'plug' in 'pcm.multi' so that is OK.

So you only need now to specify the format you want in your application. So please RTFM, man aplay will do:

arecord -D multi -c 1 -r 48000 -f S16_LE -v -t wav /tmp/test.wav

(About RTFM, I agree that it was hard to find out how it all works :-)