Hello everyone! I have problem.
I getting audio chunks from INPM411 mic though i2s interface and send to little web server (where I join chunks to one audio file).
And everything OK, but on the end of chunks I have glitches - for example, if I have 8096 samples to read from mic and send, I have glitch approximately one per second.
If I read 512 samples - I have little glitches, approximately few tens in second
I tried independent tasks, two queues, ring queue - but I hear glitches anyway.
And if I set 512 samples, may be it’s OK, but my S3 overheat after 5-7 minutes, cause a lot of little chunks.
For me enough chunks with any size, I need to remove that glitches
#include <WiFi.h>
#include <WiFiUdp.h>
#include "driver/i2s.h"
#include "driver/rtc_io.h"
// === Wi-Fi / UDP ===
const char* ssid = "*";
const char* password = "*";
WiFiUDP udp;
const char* udpAddress = "192.168.1.221";
const int udpPort = 5011;
// === I2S ===
#define SAMPLE_RATE 16000
#define I2S_WS 8
#define I2S_SD 43
#define I2S_SCK 7
// #define BLOCK_SIZE 32768
#define BLOCK_SIZE 8096
// #define BLOCK_SIZE 4048
// #define BLOCK_SIZE 2048
int32_t i2sBuffer[BLOCK_SIZE];
int16_t sendBuffer[BLOCK_SIZE];
void setupI2S() {
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = SAMPLE_RATE,
.bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = 1,
.dma_buf_count = 40,
.dma_buf_len = 1024,
.use_apll = true
};
i2s_pin_config_t pin_config = {
.bck_io_num = I2S_SCK,
.ws_io_num = I2S_WS,
.data_out_num = I2S_PIN_NO_CHANGE,
.data_in_num = I2S_SD
};
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM_0, &pin_config);
}
void setup() {
Serial.begin(115200);
Serial.println("Device started, waiting for button press...");
// Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi connected!");
Serial.println(WiFi.localIP());
udp.begin(udpPort);
setupI2S();
}
void loop() {
size_t bytesRead;
i2s_read(I2S_NUM_0, i2sBuffer, sizeof(i2sBuffer), &bytesRead, portMAX_DELAY);
int samplesRead = bytesRead / 4;
for (int i = 0; i < samplesRead; i++) {
int32_t sample32 = i2sBuffer[i];
int32_t s = sample32 >> 13;
if (s > 32767) s = 32767;
if (s < -32768) s = -32768;
sendBuffer[i] = (int16_t)s;
}
udp.beginPacket(udpAddress, udpPort);
udp.write((uint8_t*)sendBuffer, samplesRead * 2);
udp.endPacket();
}