plugh
Posts: 41
Joined: Sun Dec 02, 2012 6:58 pm

ALSA asoundrc capture config help?

Sun Aug 31, 2014 5:29 pm

I've been wrestling with this for a couple days and am stuck.
I have a digital microphone capture device attached via I2S.
$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: sndrpisimplecar [snd_rpi_simple_card], device 0: simple-card_codec_link dmic-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
I can record with it, for example:
$ arecord -D hw:1 -c 2 -f s24 -r 8000 -d 2 -v xxx
Recording WAVE 'xxx' : Signed 24 bit Little Endian, Rate 8000 Hz, Stereo
Hardware PCM card 1 'snd_rpi_simple_card' device 0 subdevice 0
Its setup is:
stream : CAPTURE
access : RW_INTERLEAVED
format : S24_LE
subformat : STD
channels : 2
rate : 8000
exact rate : 8000 (8000/1)
msbits : 32
buffer_size : 4000
period_size : 1000
period_time : 125000
tstamp_mode : NONE
period_step : 1
avail_min : 1000
period_event : 0
start_threshold : 1
stop_threshold : 4000
silence_threshold: 0
silence_size : 0
boundary : 2097152000
appl_ptr : 0
hw_ptr : 0
hexdump of file shows reasonable(?) data, and aplay plays it.
However, volume is WAY to low. OK, I think, lets use 'softvol'
Created a minimal .asoundrc file, for example:

Code: Select all

pcm.dmic_hw {
    type hw
    card 1
}
pcm_slave.dmic_sl {
    pcm dmic_hw
}
pcm.dmic {
    type softvol
    slave dmic_sl
    control {
        name "volume"
    }
    min_dB -2.2250738585072014E-308
    max_dB 50.0
}
$ arecord -D dmic_hw -c 2 -f s24 -r 8000 -d 2 -v xxx
works, but...
$ arecord -D dmic -c 2 -f s24 -r 8000 -d 2 -v xxx
Recording WAVE 'xxx' : Signed 24 bit Little Endian, Rate 8000 Hz, Stereo
arecord: set_params:1059: Broken configuration for this PCM: no configurations available
I've tried lots of variations on the soundrc file, all to no avail.
Looking at the source for set_params wasn't very helpful

Code: Select all

 static void set_params(void)
{
	snd_pcm_hw_params_t *params;
	snd_pcm_sw_params_t *swparams;
	snd_pcm_uframes_t buffer_size;
	int err;
	size_t n;
	unsigned int rate;
	snd_pcm_uframes_t start_threshold, stop_threshold;
	snd_pcm_hw_params_alloca(&params);
	snd_pcm_sw_params_alloca(&swparams);
	err = snd_pcm_hw_params_any(handle, params);
	if (err < 0) {
		error(_("Broken configuration for this PCM: no configurations available"));
		prg_exit(EXIT_FAILURE);
	}
and snd_pcm_hw_params_any wasn't any more informative

Code: Select all

{
      _snd_pcm_hw_params_any(params);
      return snd_pcm_hw_refine(pcm, params);
}
Anybody got any suggestions?

User avatar
PeterO
Posts: 3745
Joined: Sun Jul 22, 2012 4:14 pm

Re: ALSA asoundrc capture config help?

Sun Aug 31, 2014 5:32 pm

Have you tried changing settings with alsamixer ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: ALSA asoundrc capture config help?

Sun Aug 31, 2014 5:35 pm

Doesn't your device have a built in mixer?? i.e. alsamixer -c1

Richard S.

plugh
Posts: 41
Joined: Sun Dec 02, 2012 6:58 pm

Re: ALSA asoundrc capture config help?

Sun Aug 31, 2014 11:43 pm

Doesn't your device have a built in mixer??
No, no hardware mixer.

It is an ADMP441 Digital MEMS Microphone IC with I2S output, mounted on a OSH Park board, connected to the P5 lines of a model B, using simple-card and dmic ASoC drivers to talk to it via the bcm2708 i2s (with this fix) and dma drivers on "Linux raspberrypi 3.12.22+". I don't understand what the below is telling me
pi@raspberrypi ~ $ amixer -c1
Simple mixer control 'Mic',0
Capabilities: volume penum
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 255
Front Left: 74 [29%] [28.86dB]
Front Right: 74 [29%] [28.86dB]
Simple mixer control 'volume',0
Capabilities: pswitch penum
Playback channels: Front Left - Front Right
Mono:
Front Left: Playback [on]
Front Right: Playback [on]
Did I somehow auto-magically get a software mixer with volume control instantiated and attached to my driver stack? How did ALSA know it was a "Mic"? How do I invoke arecord such that I get this in the pcm path?
pi@raspberrypi ~ $ arecord -D Mic -c 2 -f s24 -r 8000 -d 2 -v xxx
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM Mic
arecord: main:682: audio open error: No such file or directory
The only thing I've gotten to 'work' is -D hw:1. What is the critical bit of knowledge I'm missing?

Thanks!

plugh
Posts: 41
Joined: Sun Dec 02, 2012 6:58 pm

Re: ALSA asoundrc capture config help?

Mon Sep 01, 2014 7:07 pm

The plot thickens...

I rebooted system, reloaded drivers, and now
amixer -c1
gives no output - no error msg, no device info, zip

(ref above .asoundrc file) I then do
pi@raspberrypi ~ $ arecord -D dmic_hw -c 2 -r 8000 -f s24 -d 2 xxx
Recording WAVE 'xxx' : Signed 24 bit Little Endian, Rate 8000 Hz, Stereo
pi@raspberrypi ~ $ amixer -c1
pi@raspberrypi ~ $
And STILL no amixer output. Now I do
pi@raspberrypi ~ $ arecord -D dmic -c 2 -r 8000 -f s24 -d 2 xxx
Recording WAVE 'xxx' : Signed 24 bit Little Endian, Rate 8000 Hz, Stereo
arecord: set_params:1059: Broken configuration for this PCM: no configurations available
pi@raspberrypi ~ $ amixer -c1
Simple mixer control 'volume',0
Capabilities: pswitch penum
Playback channels: Front Left - Front Right
Mono:
Front Left: Playback [on]
Front Right: Playback [on]
so...
1) The 'mixer' IS being auto-magically created when I try to use the softvol pcm device defined in asoundrc.
2) The 'mixer' setup shown in the preceding post must have been a leftover from one of the (many) variations I tried before starting this thread.
3) The only way to get rid of a 'mixer' once it has been auto-magically created is to unload the card driver.
4) I STILL have a problem with capture via softvol pcm mixer/device.

Still looking for suggestions...

plugh
Posts: 41
Joined: Sun Dec 02, 2012 6:58 pm

Re: ALSA asoundrc capture config help?

Tue Sep 02, 2014 6:51 pm

Well... finally got the softvol attached. The issues:

1) Strictly speaking, the admp441 produces "S24_LE" format samples (ie 24 bits in the low 3 bytes of 32 bit word). However it seems softvol only supports S16_LE/BE, S32_LE/BE, and S24_3LE (ie 24 bits packed in 3 bytes).
Software option: convert the S24_LE to S24_3LE (or S32_LE) via the cpu.
Hardware option: the admp441 tri-states its output during the last 8 bits of each 32 bit period. A pull down on the data line results in the pi seeing zeros for these bits when i2s is config'd for S32_LE.
I now have configs for both options and am evaluating them.

2) Another complicating factor is that apparently alsa plugin system requires "mmap emulation" for pi's i2s streams, and correctly using it in asoundrc for anything other than simple cases seems tricky.

3) Finally, a truly obscure factoid about the softvol plugin: it parses the name you supply for the control and sets up based upon what it finds. In this case I have to append "Capture Volume" to the name. (Note name of control in asoundrc .vs. amixer output)

Below is my setup for the 'hardware option' case

Code: Select all

pcm.dmic_hw {
    type hw
    card mysimplecard
    channels 2
    format S32_LE
}
pcm.dmic_mm {
    type mmap_emul
    slave.pcm dmic_hw
}
pcm.dmic_sv {
    type softvol
    slave.pcm dmic_mm
    control {
        name "Boost Capture Volume"
        card mysimplecard
    }
    min_dB -2.2250738585072014E-308
    max_dB 50.0
}
pi@raspberrypi ~ $ alsacap -R -d dmic_sv
*** Exploring configuration space of device `dmic_sv' for recording ***
2 channels
Sampling rate 8000..192000 Hz
Sample formats: S32_LE
Significant bits: 32
pi@raspberrypi ~ $ arecord -D dmic_sv -c 2 -r 48000 -f s32 -d 2 -v xxx
Recording WAVE 'xxx' : Signed 32 bit Little Endian, Rate 48000 Hz, Stereo
Soft volume PCM
Control: Boost Capture Volume
min_dB: -2.22507e-308
max_dB: 50
resolution: 256
Its setup is:
stream : CAPTURE
access : RW_INTERLEAVED
format : S32_LE
subformat : STD
channels : 2
rate : 48000
exact rate : 48000 (48000/1)
msbits : 32
buffer_size : 24000
period_size : 6000
period_time : 125000
tstamp_mode : NONE
period_step : 1
avail_min : 6000
period_event : 0
start_threshold : 1
stop_threshold : 24000
silence_threshold: 0
silence_size : 0
boundary : 1572864000
Slave: Mmap emulation PCM
Its setup is:
stream : CAPTURE
access : MMAP_INTERLEAVED
format : S32_LE
subformat : STD
channels : 2
rate : 48000
exact rate : 48000 (48000/1)
msbits : 32
buffer_size : 24000
period_size : 6000
period_time : 125000
tstamp_mode : NONE
period_step : 1
avail_min : 6000
period_event : 0
start_threshold : 1
stop_threshold : 24000
silence_threshold: 0
silence_size : 0
boundary : 1572864000
Slave: Hardware PCM card 1 'my_simple_card' device 0 subdevice 0
Its setup is:
stream : CAPTURE
access : RW_INTERLEAVED
format : S32_LE
subformat : STD
channels : 2
rate : 48000
exact rate : 48000 (48000/1)
msbits : 32
buffer_size : 24000
period_size : 6000
period_time : 125000
tstamp_mode : NONE
period_step : 1
avail_min : 6000
period_event : 0
start_threshold : 1572864000
stop_threshold : 24000
silence_threshold: 0
silence_size : 0
boundary : 1572864000
appl_ptr : 0
hw_ptr : 0
pi@raspberrypi ~ $ amixer -c1
Simple mixer control 'Boost',0
Capabilities: cvolume penum
Capture channels: Front Left - Front Right
Limits: Capture 0 - 255
Front Left: Capture 255 [100%] [48.45dB]
Front Right: Capture 255 [100%] [48.45dB]

LisaJK
Posts: 14
Joined: Sat Jul 11, 2015 6:21 am

Re: ALSA asoundrc capture config help?

Sat Jul 11, 2015 6:42 am

Hi Plugh,

I have a Knowles I2S microphone, similar to the Invensense/Analog devices one, which I want to connect to the Pi.

I used your excellent log showing how to make and load the simple I2S driver, with one or 2 issues due to lots of stuff having been updated since you made it.

I have everything built and can load the driver, but in the log I see:

[ 95.409720] asoc-simple-card asoc-simple-card.0: ASoC: CPU DAI bcm2708-i2s.0 not registered
[ 95.409845] platform asoc-simple-card.0: Driver asoc-simple-card requests probe deferral

Any ideas?

RickTracer
Posts: 1
Joined: Thu Jul 27, 2017 12:14 pm

Re: ALSA asoundrc capture config help?

Thu Jul 27, 2017 12:28 pm

This post was great at helping me get the volume increased on my Adafruit I2S MEMS Microphone Breakout - SPH0645LM4H. However I had some trouble getting it working so sharing a few hints here.

First I had to replace "card mysimplecard" with "card sndrpisimplecar" - obtained by arecord -l and the name shown between : and [
arecord.JPG
arecord.JPG (28.47 KiB) Viewed 1837 times
Second, I had to run alsamixer, F6 (select my "snd_rpi_simple_card") F4 for capture device volume and arrow up to about 50%.
AlsaMixer.JPG
AlsaMixer.JPG (40.21 KiB) Viewed 1837 times
Lastly I had to specify -D dmic_sv -c2 in the arecord as follows :

Code: Select all

arecord -D dmic_sv -c2 -r 48000 -f S32_LE -t wav -V mono -v myfile.wav
Here's my .asoundrc (sudo nano ~./adsoundrc) :

Code: Select all

#The below 2 sections are commented, they control the default sound card to use
#This set up is for a Pi with an I2S microphone attached using the guide
#from adafruit at
# https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout
#Uncomment and the I2S will be your default card (assuming same setup)
#but you won't get audio playback because both recording and playback will be
#defaulted
#TODO - Figure out how to set default for recording separately
#To adjust use aplay -l to work out the devices you have and their card number
#For recording devices use arecord -l

#pcm.!default {
#	type hw
#	card 1
#}

#ctl.!default {
#	type hw           
#	card 1
#}

#This section makes a reference to your I2S hardware, adjust the card name
# to what is shown in arecord -l after card x: before the name in []
#You may have to adjust channel count also but stick with default first
pcm.dmic_hw {
	type hw
	card sndrpisimplecar
	channels 2
	format S32_LE
}

#This is the software volume control, it links to the hardware above and after
# saving the .asoundrc file you can type alsamixer, press F6 to select
# your I2S mic then F4 to set the recording volume and arrow up and down
# to adjust the volume
# After adjusting the volume - go for 50 percent at first, you can do
# something like 
# arecord -D dmic_sv -c2 -r 48000 -f S32_LE -t wav -V mono -v myfile.wav
pcm.dmic_sv {
	type softvol
	slave.pcm dmic_hw
	control {
		name "Boost Capture Volume"
		card sndrpisimplecar
	}
	min_dB -3.0
	max_dB 30.0
}


Hope it helps anyone who had difficulties getting the original solution working with their config!

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: No registered users and 8 guests