0

I2S MEMS microphone - S16_LE
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

I2S MEMS microphone - S16_LE

by GoldstreamSolar on Wed Jul 28, 2021 10:26 pm

Hiya- I am using this MEMS microphone with pocketsphinx to recognize words. Pocketsphinx (apparently) only works with 16-bit audio. The Adafruit tutorial for the I2S MEMS microphone uses S32_LE throughout and this works fine with this command

/usr/bin/arecord -D dmic_sv -c2 -r 48000 -f S32_LE -t wav -d 2 -V mono -v -q myS32.wav

Then I use ffmpeg to convert the 32-bit audio file to a 16-bit audio file, and Pocketsphinx works just fine. It seems like it would all work faster if arecord created a 16-bit audio file in the first place.

If I edit .asoundrc to change this
format S32_LE
to
format S16_LE

and change my run command to the new format

/usr/bin/arecord -D dmic_sv -c2 -r 48000 -f S16_LE -t wav -d 2 -V mono -v -q myS16.wav

then the VU meter quits working and the new .wav file has no audible content however it is played back.

Can the I2S microphone record 16-bit data on a Pi Zero or is this simply not possible?

GoldstreamSolar
 
Posts: 29
Joined: Wed Aug 05, 2020 5:02 pm

Re: I2S MEMS microphone - S16_LE

by mikeysklar on Thu Jul 29, 2021 10:53 pm

@GoldstreamSolar,

Recording S16_LE is possible. There is a great thread on this.

https://github.com/mpromonet/v4l2rtspserver/issues/94

Code: Select all | TOGGLE FULL SIZE
apt-get install ladspa-sdk


/etc/asound.conf

Code: Select all | TOGGLE FULL SIZE
pcm.pluglp {
    type ladspa
    slave.pcm "plughw:1,0"
    path "/usr/lib/ladspa"
    capture_plugins [
   {   
      label hpf
      id 1042
   }
        {
                label amp_mono
                id 1048
                input {
                    controls [ 30 ]
                }
        }
    ]
}

pcm.lp {
    type plug
    slave.pcm pluglp
}


Code: Select all | TOGGLE FULL SIZE
arecord -D lp -c1 -r 48000 -f S16_LE -t wav -V mono -v recording.wav
v4l2rtspserver -F 25 -W 1280 -H 720 -P 8555 /dev/video0,lp -A 48000 -a S16_LE

mikeysklar
 
Posts: 5520
Joined: Mon Aug 01, 2016 8:10 pm

Re: I2S MEMS microphone - S16_LE

by GoldstreamSolar on Fri Jul 30, 2021 12:45 pm

I will have a look. Thanks very much for the tip, Mikey!

GoldstreamSolar
 
Posts: 29
Joined: Wed Aug 05, 2020 5:02 pm

Re: I2S MEMS microphone - S16_LE

by mikeysklar on Fri Jul 30, 2021 1:36 pm

No problem. I think the crux of it is the -c2 you had been passing versus -c1 (stereo vs. mono). Let us know what you experience.

mikeysklar
 
Posts: 5520
Joined: Mon Aug 01, 2016 8:10 pm

Re: I2S MEMS microphone - S16_LE

by GoldstreamSolar on Sat Jul 31, 2021 4:11 pm

It worked like a charm, Mikey. In fact, it works so well that I would suggest that the Adafruit tutorial for the I2S microphone should use it instead of what it's got now, because this version of the .asoundrc file solves the low recording volume at the same time as it switches to writing in 16 bit.

I would add a little note. If I type this:

Code: Select all | TOGGLE FULL SIZE
[size=85]pi@raspberrypi:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: sndrpii2scard [snd_rpi_i2s_card], device 0: simple-card_codec_link snd-soc-dummy-dai-0 [simple-card_codec_link snd-soc-dummy-dai-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0[/size]


it suggests that I change the hardware designation for the microphone in the .asoundrc file to this:

Code: Select all | TOGGLE FULL SIZE
pcm.pluglp {
    type ladspa
    slave.pcm "plughw:0"
    path "/usr/lib/ladspa"
    capture_plugins [
   {   
      label hpf
      id 1042
   }
        {
                label amp_mono
                id 1048
                input {
                    controls [ 30 ]
                }
        }
    ]
}

pcm.lp {
    type plug
    slave.pcm pluglp
}


And there is one more thing for Pocketsphinx: the sampling rate has to be dropped down to 16000, so the record command is now

Code: Select all | TOGGLE FULL SIZE
arecord -D lp -c1 -r 16000 -f S16_LE -d 2 -t wav -V mono -v file.wav


Once again, Mikey, thanks very much for your help with this!

GoldstreamSolar
 
Posts: 29
Joined: Wed Aug 05, 2020 5:02 pm

Re: I2S MEMS microphone - S16_LE

by mikeysklar on Mon Aug 02, 2021 6:25 pm

Awesome, glad this worked out so well. Thank you for the suggestions for improving our guide and the volume boost you noticed.

mikeysklar
 
Posts: 5520
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.