Build C++ Library with STM32CubeIDE

I think 32 kHz is too fast. The example I use is 16 kHz, which is what Edge Impulse uses by default. Even though my I2S mic samples at 32 kHz, I drop every other sample to make it 16 kHz. I know, I should be using a low-pass filter to avoid aliasing if I’m down-sampling, but that would take what little resources I have, so I just have to assume that I won’t encounter frequencies above 8 kHz (as my application is for vocal range anyway).

If you look for audio_buffer_inference_callback() function in my main.cpp of the L476 example, you can see where I drop samples and convert the 24-bit audio to 16-bit audio.

6400 is the size of my I2S buffer. Every time half of that is filled up, it calls the audio_buffer_inference_callback() function. Here, the audio samples are converted to 16-bit PCM and 16 kHz and stored in one of the inference.buffers (it’s a double buffer). The size of that buffer is EI_CLASSIFIER_SLICE_SIZE.

One of these inference.buffers is sent to run_classifier_continuous() each time it’s filled up. That function should take no more than 250 ms to perform feature extraction (MFCCs) and inference, as it needs to meet the goal of performing inference 4 times per second.

Hope that helps!

1 Like

Thank you so much for your support!

I did some debug with the oscilloscope, and I found a strange behavior.
The inference algorithm seems to work properly for the first 3 times and then, it takes too much time.

I put a toggle pin UP-DOWN across “run_classifier_continuous” function The YELLOW

and a toggle pin UP-DOWN across half callback and complete callback --> the BLUE signal

The project I tried is the one downloaded from the repository (same BOARD and MIC), compile with timing optimization

If I can give you other information let me know.

Thank you so much

What is the “timing optimization” option? It’s been a couple of months since I made that project, so I may not remember. Is there a particular checkbox in preferences or flag you set that’s different from my example project?

Good morning,
I did two tests:

  • The first test with all the same preferences you set, but the behaviour is the same as the image I posted.
  • The second one with “timing optimization” (is in properties-> C/C++ build -> Settings-> MCU GCC Compiler-> Optimization) With the same result.

Do you have some other suggestion?

thank you so much

@Fede99 if you set EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW to 2 does it not time out?

I tried now, but it goes in overrun anyway.

@Fede99 so a full frame of inference costs 480ms. when doing only half that this will be even further reduced, so I’m surprised about that. I’d follow Shawn’s suggestion and downsample to 16KHz on the device.

Hello Edge Team,
I had followed the instructions to include *.pack library into STM32CubeIDE but after compiling the c++ project i got below compiler error:

./Middlewares/Third_Party/EdgeImpulse_AudioPCBM_MachineLearning/edgeimpulse/edge-impulse-sdk/dsp/spectral/processing.hpp:26:10: fatal error: vector: No such file or directory
26 | | #include

same for #include

looks like below two include file are not able to fine into below include path from g++ include settings
…/Middlewares/Third_Party/EdgeImpulse_AudioPCBM_MachineLearning/edgeimpulse/

Kindly help me to resolve the compiler error related to header file not able locate in above path.

-Vikas B

Hi @vikas Are you sure you have a C++ project? Do you have C++11 or higher selected?

it is select as
image

Any updates or suggestion to resolve the compiler issue?

I could able to compile the code by creating new cubeMx C++ project but now I’m getting the RAM memory overflow error by 3KiB but i look at deployment result as shown below it far less than the memory on STMF401VC i.e it has 256KiB Flash and 64KiB RAM.

So why there is huge difference that will overflow RAM usage with edge impulse Library?

@vikas can you email me your project at jan@edgeimpulse.com ?

I had email the source project .

@vikas in main.cpp mark your features array as const:

static const float features[] = {

Otherwise this whole array is loaded into RAM. Fixed this in the docs!

Thanks Jan, That had fixed the compiler issue , but Question remains same why the Flash code is more(>30KiB) than what is mention at time of deployment?

So you have the features hardcoded right now, these take up 16000 * 4 bytes = 64K of flash. Normally you don’t have this hardcoded (it gets generated by your sensors on board) so you don’t have this overhead in a normal application/

Ohh then it will take more memory, but late say I would feed the audio raw data to library then what is the procedure to integrate such code?

@vikas You’ll need an audio buffer, but it can be small. E.g. 250ms. slice in int16 format. See https://docs.edgeimpulse.com/docs/continuous-audio-sampling for some docs on how to set this up. The example firmware for ST IoT Discovery Kit has this fully setup, and the Arduino libraries also come with examples on using PDM microphones.

I know it’s dated, but in case someone else is struggling with this, I wanted to share an alternative to this [1] issue stated at the beginning of this post.

A dual core project in STM32CubeIDE imposes a structure that’s not compatible with step 2. Tons of errors, unresolved includes, and missing definitions, even though the includes were added as in step 3.

In place if step 2 and 3, I made a separate folder at the project level and copied edge-impulse-sdk , tflite-model and model-parameters here.

Right click on the project and navigate to Properties > C/C++ General > Paths and Symbols The two tabs of interest here are Library Paths and Source Location. At both of these locations, click on Add/Add Folder or Link Folder and use the file system to provide the absolute path to the folder you created. After this, the folder should appear in the project explorer with an icon that indicates that it contains source files to be compiled.

Now to take care of the includes, just right click on the folder from the project explorer, and select Add/remove include path…

Hope this helps save someone time.

1 Like