Does readBytes() have delay? #1712
-
I currently have an ESP32 that initially receives from the I2S microphone and sends the data via Serial to a Python program using Pyaudio for playback. However, I'm using readBytes() to read 2048 bytes of raw data, then keeping one channel's data and using a for loop to separate the data before sending it. I'm not sure where the delay is causing the playback to sound like it's slightly under-sampled. Can you tell me what I might have done wrong? and this is my arduino code:
2024-09-23.07-44-48.mp4 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Why so complicated ? your code is quite difficult to understand: If I get your logic right, you just want to write out binary data delimited with a line feed. I suggest to do something like this instead: loop() {
int16_t sample;
size_t bytes_read = i2sStream.readBytes((uint8_t*) &sample, sizeof(int16_t));
assert(bytes_read==sizeof(int16_t)); // i2s uses blocking read, so this should always be treu
Serial.write((uint8_t*)&sample, sizeof(int16_t));
Serial.print('\n'); // for cr or Serial.println() for cr lf
} There is still one issue however: you generate 2 * 3 (=2 bytes + delimiter) * 16000 * 8 bits per second = 768000 but your Serial transmission rate is much lower. This can't work.... |
Beta Was this translation helpful? Give feedback.
Why so complicated ? your code is quite difficult to understand: If I get your logic right, you just want to write out binary data delimited with a line feed.
I suggest to do something like this instead:
There is still one issue however: you generate 2 * 3 (=2 bytes + delimiter) * 16000 * 8 bits per second = 768000 but your Serial transmission rate is much lower. Th…