8 simultaneous streams working, but playback has artifacts

This commit is contained in:
Sebastian
2025-06-04 10:20:37 +02:00
parent 15733e8b36
commit 76ff73791a
2 changed files with 47 additions and 22 deletions

View File

@ -100,8 +100,8 @@ class TLV320AIC3204{
// LO GAIN // LO GAIN
cw(0x00, 0x01); cw(0x00, 0x01);
cw(0x12, 0b00000001); // LOL gain 0dB cw(0x12, 0b00000000); // LOL gain 0dB
cw(0x13, 0b00000001); // LOR gain 0dB cw(0x13, 0b00000000); // LOR gain 0dB
// POWER UP // POWER UP
// ADC // ADC
@ -113,8 +113,8 @@ class TLV320AIC3204{
// DAC VOLUME 0b00000000 = 0dB, 10000001 = -63.5dB, 0b00110000 = +24dB // DAC VOLUME 0b00000000 = 0dB, 10000001 = -63.5dB, 0b00110000 = +24dB
cw(0x00, 0x00); // select page 0 cw(0x00, 0x00); // select page 0
cw(0x41, 0b11111001); // LEFT cw(0x41, 0b11110001); // LEFT
cw(0x42, 0b11111001); // RIGHT cw(0x42, 0b11110001); // RIGHT
// ADC VOLUME 0b1101000 = -12dB, 0b00000000 = 0dB, 0b0101000 = +20dB // ADC VOLUME 0b1101000 = -12dB, 0b00000000 = 0dB, 0b0101000 = +20dB
cw(0x00, 0x00); // select page 0 cw(0x00, 0x00); // select page 0

View File

@ -19,7 +19,7 @@
#define RINGBUFFER 16384 #define RINGBUFFER 16384
#define ECHO 24000 #define ECHO 24000
#define NSTREAMS 4 #define NSTREAMS 8
int16_t buffer[SIZE]; int16_t buffer[SIZE];
int16_t buffer2[ECHO]; int16_t buffer2[ECHO];
@ -27,6 +27,7 @@ int16_t buffer2[ECHO];
RingBuffer<int16_t> ringbuffer[NSTREAMS]; RingBuffer<int16_t> ringbuffer[NSTREAMS];
File streams[NSTREAMS]; File streams[NSTREAMS];
bool streams_loaded = false;
I2S i2s(INPUT_PULLUP); I2S i2s(INPUT_PULLUP);
@ -105,10 +106,11 @@ void codec_transmit() {
for(int i = 0; i < count; i++){ for(int i = 0; i < count; i++){
int16_t sample = 0; int16_t sample = 0;
for(int j = 0; j < NSTREAMS; j++){ // for(int j = 0; j < NSTREAMS; j++){
int j = active % NSTREAMS;
if(!ringbuffer[j].isEmpty()) sample = ringbuffer[j].pop(); if(!ringbuffer[j].isEmpty()) sample = ringbuffer[j].pop();
buffer[i] += (sample / 4); buffer[i] += (sample);
} // }
} }
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t)); i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
@ -273,6 +275,7 @@ void setup() {
} }
} }
} }
streams_loaded = true;
} }
// if(!ringbuffer.isFull()){ // if(!ringbuffer.isFull()){
@ -298,20 +301,20 @@ void loop() {
if(sd_card_detected) edge_leds[8] = CRGB(0,10,0); if(sd_card_detected) edge_leds[8] = CRGB(0,10,0);
if(!sd_card_detected) edge_leds[8] = CRGB(10,0,0); if(!sd_card_detected) edge_leds[8] = CRGB(10,0,0);
for (int i = 0; i < NSTREAMS; i++) { // for (int i = 0; i < NSTREAMS; i++) {
if(!ringbuffer[i].isFull()){ // if(!ringbuffer[i].isFull()){
int cnt = 0; // int cnt = 0;
while (!ringbuffer[i].isFull() && cnt < 10000) { // while (!ringbuffer[i].isFull() && cnt < 10000) {
uint8_t samplebyte[2]; // uint8_t samplebyte[2];
streams[i].read(samplebyte, 2); // streams[i].read(samplebyte, 2);
if(!streams[i].available()) streams[i].seek(44, SeekSet); // if(!streams[i].available()) streams[i].seek(44, SeekSet);
int16_t sample = (samplebyte[1] << 8) + samplebyte[0]; // int16_t sample = (samplebyte[1] << 8) + samplebyte[0];
ringbuffer[i].push(sample); // ringbuffer[i].push(sample);
cnt++; // cnt++;
} // }
} // }
} // }
// EDGE LEDs // EDGE LEDs
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
@ -387,7 +390,29 @@ void loop() {
ui_leds[lut_ring_ccw[i]] = CRGB(50, 0, 25); ui_leds[lut_ring_ccw[i]] = CRGB(50, 0, 25);
} }
//FastLED.show(); FastLED.show();
//delay(1); // wait 1ms //delay(1); // wait 1ms
} }
void setup1(){
}
void loop1(){
if(streams_loaded) {
for (int i = 0; i < NSTREAMS; i++) {
if(!ringbuffer[i].isFull()){
int cnt = 0;
while (!ringbuffer[i].isFull() && cnt < 10000) {
uint8_t samplebyte[2];
streams[i].read(samplebyte, 2);
if(!streams[i].available()) streams[i].seek(44, SeekSet);
int16_t sample = (samplebyte[1] << 8) + samplebyte[0];
ringbuffer[i].push(sample);
cnt++;
}
}
}
}
}