Maker Portal

View Original

Recording Stereo Audio on a Raspberry Pi

“As an Amazon Associates Program member, clicking on links may result in Maker Portal receiving a small commission that helps support future projects.”

See this content in the original post

See this content in the original post

Once the Raspberry Pi OS is loaded onto the SD card, insert the card into the RPi board. A Raspberry Pi 4 Model B board is used going forward.

See this content in the original post

We start by installing Python3 and pip:

See this content in the original post

Next, it is good to install the Python Integrated Development Learning Environment (IDLE), where we can write scripts and visualize data a bit easier:

See this content in the original post

Assuming the above did not result in any errors, we can run the .py file that installs the i2smic capability onto the RPi:

See this content in the original post

The following prompt will ask the user whether they want the I2S input to be loaded at boot. ‘y’ should be inputted, unless the user has a preference to keep the boot minimal (not recommended for heavy audio use).

After agreeing to load at boot, the install will take several minutes (depending on internet speed). Once the install completes, the user will again be prompted to reboot. Reboot and then continue with the next step.

See this content in the original post

The following should be outputted to the Python shell:

See this content in the original post

See this content in the original post
  • 1x Raspberry Pi 4B Computer (4GB RAM) - $57.99 [Board Only on: Amazon], $99.99 [Kit on Amazon], $55.00 [2GB from Our Store]

  • 2x INMP441 MEMS Microphones - $10.00 [Our Store]

  • 1x Mini Breadboard - $3.00 [Our Store]

  • 7x Male-to-Male Jumper Wires - $1.05 [Our Store]

  • 5x Male-to-Female Jumper Wires - $0.75 [Our Store]

See this product in the original post

The wiring diagram between the Raspberry Pi computer and the INMP441 MEMS Microphone is given below:

MONO I2S MICROPHONE INPUT

STEREO I2S MICROPHONE INPUT

See this content in the original post

See this content in the original post
  1. Record 1 second of background noise (at 44.1kHz sample rate)

  2. Record 5 seconds of data

  3. Save the recorded audio as a .wav file under a folder called ‘data’ with the filename corresponding to the current date/time

  4. Remove the background noise from the 5 seconds data

  5. Select the peak frequency of the frequency response (computed with the Numpy FFT)

  6. Plot the time series and frequency response of the 5 second recording

See this content in the original post

The resulting output should look similar to the plot shown below:

A 3114Hz signal was inputted using a smartphone frequency generator placed a foot away from the INMP441 MEMS microphone. At this stage, with the frequency response matching the input frequency generated by the app - we are sure that the microphone is being read properly by the Raspberry Pi! It also may be noticeable that the amplitude is quite low on the mic response - we will address this as well as the adjustments to be made to the code in order to permit stereo recording.

See this content in the original post

See this content in the original post

The subsequent output of the code above should result in two channels being plotted in a similar manner to the plot above in the mono input case. The stereo time series and frequency response for a 1012Hz input frequency generated via a smartphone app is given below:

It is easy to perceive exactly what was happening in the test case above: first, channel 0 had the input signal closer to its port; then, channel 1 had the input signal closer to its port - both of which are visible in the amplitude changes in the time series plot.


See this content in the original post

ALL CODES CAN BE FOUND ON OUR GITHUB PAGE:

See this content in the original post

See More in Raspberry Pi and Acoustics

See this content in the original post