The PDM mic gain is being set incorrectly in the Arduino examples. Currently PDM.setGain() is called before PDM.begin(). When it is done in this order, it doesn’t appear to change the mic levels. However, if you call setGain() after begin(), the levels change. This can be easily tested out using the PDMSerialPlotter(). I am not sure if this impacts performance at all though, since the audio gets normalized anyhow.
PDM.setBufferSize(4096);
// initialize PDM with:
// - one channel (mono mode)
// - a 16 kHz sample rate
if (!PDM.begin(1, EI_CLASSIFIER_FREQUENCY)) {
ei_printf("Failed to start PDM!");
microphone_inference_end();
return false;
}
PDM.setGain(80);
We’ve been looking at the Nano gain for quite a bit when we did the first port and never realized why this wasn’t working. Result is low volume when recording which can be fixed now, and I think it’ll help a bit with inferencing too.
Haha! yea, this one was bugging me for a while because it didn’t seem like the gain had any effect. I happened to just try swapping the functions order on a whim. However, I just saw this weekend that the TF Micro speech example sets the Gain after the Begin:
That was exactly what I have been also looking for. Thank you!
One more question. How do you tweak the mic gain when using the edge-impulse-deamon to record audio data? Are you using a custom code to collect the wav recordings in order to train the neural net?
Thank you for the prompt response! I appreciate it
By the way, in my case i placed the gain at “/src/sensors/ei_microphone.cpp” after the PDM.begin() function in order to make it work
I have a couple of changes for the nano33 edge firmware, one of which is the PDM gain fix mentioned previously. Building and flash on MacOS with arduino_build.sh results in an mbed crash.
No changes made to any code, just freshly cloned.
The binary created this way is 3/5ths the size of the bin used in flash_mac.command.
I have a FTDI connected so I can see the crash output. Can that be used to narrow down the crash stack ?
I am new to Edge Impulse and nano 33 ble. The problem is that it captures audio from the nano 33’s microphone at a very low level that is almost indistinguishable from noise and is not suitable for training the model. Please tell me how to fix it. Thank you.
@Robotastic post for the code is the fix. I changed ei_microphone.cpp to set the gain after PDM.begin() for my purposes. I don’t think it is fixed yet in the edge impulse repository, @janjongboom can verify or you can take a look at the edge impulse github repository to see if it is updated.
Hi @tototek this has now been released. You can get new firmware from the Nano 33 BLE Sense page, and the examples are updated when you export a new Arduino library from the Deployment page in the Studio.
OK. Now the audio level in the acquisition works correct.Thank you.
But now it happens to me that when acquiring data from the microphone it gives me a timeout error and I have to exit the edgeimpulse daemon and log in again.
On the nano33 ble, the yellow led is flashing, it is waiting to read from the device .
Attachment capture:
Incoming sampling request {
path: ‘/ api / training / data’,
label: ‘pit22’,
length: 10000,
interval: 0.0625,
hmacKey: ‘ca3e5c5363bc82053fb969f449cf82de’,
sensor: ‘Built-in microphone’
}
[SER] Configured upload settings
[SER] Sampling started
[SER] Sampling done
[SER] Device not connected to WiFi directly, reading from buffer (bytes 0 - 323828, expecting to read ~ 431770 bytes …
Failed to sample data Timeout when waiting for> (timeout: 130000) AT + READBUFFER = 0.323828
All my software is update.In my humble opinion, the serial port capture stop order fails.I have tried it with different sample length 8.9,10 sec.