Problems when trying to csvstream data from i2s source #748
-
Hello,
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
Today I was trying to do something similar: I tried to send the data directly in binary format and read it from a linux device. Here seems to be the challenge: with the data as binary 44100 bytes per second would require a bit rate of 882000. I am not sure what rates are realistic... What OS are you using ? It would be interresting to see if you run into the same issues if you just copy the data to Serial... |
Beta Was this translation helpful? Give feedback.
-
I tried to measure the performance... Here is the Arduino Sketch: #include "AudioTools.h"
AudioInfo info(8000,1,16);
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
StreamCopy copier(Serial, sound); // copies sound into serial
// Arduino Setup
void setup(void) {
AudioLogger::instance().begin(Serial2, AudioLogger::Error);
// Open output
Serial.begin(500000);
Serial.setTxBufferSize(1024);
// Setup sine wave
sineWave.begin(info, N_B4);
}
// Arduino loop - copy sound to out
void loop() {
copier.copy();
} And on the PC I was receiving the data with a Python script import serial
import numpy as np
import array
import time
sendSerial = serial.Serial ("/dev/ttyUSB5", 500000)
start_time = time.time()
total = 0;
#while True:
for count in range(100):
byte_array = sendSerial.read(1024)
data = array.array('h',byte_array)
total = total + len(data);
#print(len(data))
# print(data)
end_time = time.time()
run_time = end_time-start_time
print("samples:", total, "time:", run_time, "=> sample_rate: ", total/run_time) Here is the result I was getting on my 10 years old Macbook with Linux |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Here is my understanding what's happening: when sending binary data it is critical to read the data with the proper int16_t allignement. If you just start to read after mssing one byte you will get noise. The same is happening when you loose a byte in the middle of the processing: your proper signal just turns into noise and after loosing another byte turns into a proper signal again. So it turns out sending binary audio data over serial will not work because of this. I also tried to send mp3 data: the transmission started properly but after about 10 or 20 seconds I was running into dropped frames. I guess for the very same reason that the binary was not working. Honestly, I am surprised that Serial (over USB) is so unreliable... |
Beta Was this translation helpful? Give feedback.
I tried to measure the performance...
Here is the Arduino Sketch: