Thanks so much for responding @aurel !
Yes, I have made live classifications and it works correctly. The Edge Impulse part of creating the models works just fine. To verify it, I uploaded the project to a Nano 33 BLE Sense, and I confirmed that it worked incredibly good.
The part that I am struggling is to adapt the I2S to retrieve data for the buffers. I sort of make it, and it works, but I belive that the problem is there because the classification is not accurate.
My project ID is 75837
An the code of the project is very long, but the part that retrieves data is this (Everything else is almost the same):
//************************* I2S Configuration *************************//
#include <driver/i2s.h>
#define I2S_NUM I2S_NUM_0 // 0 or 1
#define I2S_SAMPLE_RATE 16000
#define I2S_PORT I2S_NUM_0
#define I2S_PIN_CLK 2
#define I2S_PIN_WS 15
#define I2S_PIN_DOUT I2S_PIN_NO_CHANGE
#define I2S_PIN_DIN 13
void initI2S(){
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = I2S_SAMPLE_RATE,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 6,
.dma_buf_len = 1024,
.use_apll = false,
.tx_desc_auto_clear = false,
.fixed_mclk = 0
};
i2s_pin_config_t pin_config = {
.bck_io_num = I2S_PIN_CLK,
.ws_io_num = I2S_PIN_WS,
.data_out_num = I2S_PIN_DOUT,
.data_in_num = I2S_PIN_DIN,
};
i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM, &pin_config);
i2s_set_clk(I2S_NUM, I2S_SAMPLE_RATE, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO);
}
/**
* @brief i2s buffer full callback
* Get data and call audio thread callback
*/
static void i2s_data_ready_inference_callback(void*arg){
size_t bytesRead;
int i2s_read_len=5333;
i2s_read(I2S_PORT, (void*) sampleBuffer, i2s_read_len, &bytesRead, portMAX_DELAY);
if (record_ready == true) {
for (int i = 0; i<bytesRead>> 1; i++) {
inference.buffers[inference.buf_select][inference.buf_count++] = sampleBuffer[i];
if (inference.buf_count >= inference.n_samples) {
inference.buf_select ^= 1;
inference.buf_count = 0;
inference.buf_ready = 1;
}
}
}
i2s_driver_uninstall(I2S_NUM_0);
vTaskDelete(NULL);
}