alanxyzhou wrote: ↑
Tue Aug 11, 2020 9:07 pm
Has anyone figured out how to enable PDM audio recording on the Pi 4B?
Following on from some pointers from other users in this thread, I have been able to enable PDM mode recording on the RPi Zero W (which has BCM2835 SoC) and successfully recorded audio from 2 different PDM microphones.
Note that this may not be the only way/best way to get PDM recording working, however it worked for me. If anyone has had experience in this feel free to point out an improved method
Here were the specific steps I followed:
- $ cd /linux/sound/soc/bcm (Change directory to the location which contains Linux's I2S sound source file)
- $ sudo nano bcm2835-i2s.c (Open up the I2S sound source file for editing in root mode)
- Go to line ~393/394 and write bclk_rate = 3072000 (This fixes the PCM clock rate at 3.072 MHz which is what we need for PDM microphones)
- Go to line ~590 and write "mode |= BCM2835_I2S_PDMN;" on one line, and "mode |= BCM2835_I2S_PDME" on the next line, before the
"regmap_write(dev->i2s_regmap, BCM2835_I2S_MODE_A_REG, mode) line, be sure to save this! (This ensures PDM mode is enabled and a
decimation factor of N = 32 is
selected during the I2S mode setup).
- $ make -C /lib/modules/($ uname -r )/build M=($ pwd) modules (Now that we have changed the source file, we need to use the 'make'
command to run the Makefile which will compile the changes and generate a .ko kernel object file which is what we want - this file is called
- $ cd /lib/modules/(uname -r)/kernel/sound/soc/bcm (This puts us in the directory of the kernel which contains the existing "snd-soc-bcm2835-
i2s.ko" which needs to be replaced)
- $ sudo rm -r snd-soc-bcm2835-i2s.ko (This removes the existing kernel object so we can replace it with out newly generated .ko file)
- In the /linux/sound/soc/bcm directory, execute the command: sudo cp snd-soc-bcm2835-i2s.ko /lib/modules/([dollar sign] uname -
r)/kernel/sound/soc/bcm (This will copy over the newly generated .ko file with PDM mode enabled to where we need it)
- Reboot the RPi using $ sudo reboot and use the following command to record audio: arecord -D plughw:1 -c1 -r 48000 -f S16_LE -d 60 -t wav -
V mono -v test.wav