# MEMS Microphone (SPH0645LM4H) Library Problem

Hello everyone,

I need to convert the output of the microphone into dB and apply a spectrum analysis. I'm using Adafruit MEMS microphone SPH0645LM4H with Arduino Mkr1000.

I am currently working with the ArduinoSound library, however there are couple things that I do not understand.

SPH0645LM4H microphone's output is 24 bits with 18 precision.

Arduino Sound library outputs 32 bits, so I can not get a true output since MEMs microphone and the library does not match in this sense.

Do you know how can I change this bit value in the library to match it with to microphone?

It would be great If you could help me with this problem, thanks.

Do you know how can I change this bit value in the library to match it with to microphone?

Take the microphone output and shift it to the left four times.

`````` inputToFFT = microphone << 4;
``````

Grumpy_Mike:
Take the microphone output and shift it to the left four times.

`````` inputToFFT = microphone << 4;
``````

This is the code I used, which line should be changed?

Circuit:

• Arduino/Genuino Zero, MKRZero or MKR1000 board
• ICS43432:
• GND connected GND
• 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKRZero)
• WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKRZero)
• CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKRZero)
• SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKRZero)

#include <ArduinoSound.h>

// sample rate for the input
const int sampleRate = 12800;

// size of the FFT to compute
const int fftSize = 128;

// size of the spectrum output, half of FFT size
const int spectrumSize = fftSize / 2;

// array to store spectrum output
int spectrum[spectrumSize];

// create an FFT analyzer to be used with the I2S input
FFTAnalyzer fftAnalyzer(fftSize);

void setup() {
// Open serial communications and wait for port to open:
// A baud rate of 115200 is used instead of 9600 for a faster data rate
// on non-native USB ports
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

// setup the I2S audio input for the sample rate with 32-bits per sample
if (!AudioInI2S.begin(sampleRate, 32)) {
Serial.println(“Failed to initialize I2S input!”);
while (1); // do nothing
}

// configure the I2S input as the input for the FFT analyzer
if (!fftAnalyzer.input(AudioInI2S)) {
Serial.println(“Failed to set FFT analyzer input!”);
while (1); // do nothing
}
}

void loop() {
// check if a new analysis is available
if (fftAnalyzer.available()) {

// print out the spectrum
for (int i = 0; i < spectrumSize; i++) {
Serial.print((i * sampleRate) / fftSize); // the starting frequency
Serial.print("\t"); //
Serial.println(spectrum*); // the spectrum value*

• }*
• }*
}

This looks suspicious to me:

``````  // setup the I2S audio input for the sample rate with 32-bits per sample
if (!AudioInI2S.begin(sampleRate, 32)) {
``````

If you admit the samples are 24 bit, it might do a better job...

MarkT:
This looks suspicious to me:

``````  // setup the I2S audio input for the sample rate with 32-bits per sample
``````

if (!AudioInI2S.begin(sampleRate, 32)) {

``````

If you admit the samples are 24 bit, it might do a better job...
``````

No, this line just justifies if its in correct bitrate or not, gives warning and stops the code if its not 32 bps

there are several libraries connected to main code which arranges the sample and its bitrate

audioin or audioini2s could be correct file to fix this issue, but I m unable to analyze

AmplitudeAnalyzer.cpp (1.66 KB)

AmplitudeAnalyzer.h (1.26 KB)

ArduinoSound.h (1.06 KB)

AudioAnalyzer.cpp (888 Bytes)

AudioAnalyzer.h (1.08 KB)

AudioIn.cpp (1.17 KB)

AudioIn.h (1.48 KB)

AudioInI2S.cpp (2.09 KB)

AudioInI2S.h (1.39 KB)

AudioOut.cpp (2.85 KB)

AudioOut.h (1.84 KB)

AudioOutI2S.cpp (3.3 KB)

AudioOutI2S.h (1.4 KB)

FFTAnalyzer.cpp (4.41 KB)

FFTAnalyzer.h (1.43 KB)

SDWaveFile.cpp (4.66 KB)

SDWaveFile.h (1.65 KB)

SoundFile.h (1.18 KB)

This is the code I used, which line should be changed?

Well it is not really a program as such, it is just a piece of code that calls two functions. These functions are implemented in libraries so you would would have to alter the code in those libraries.