waves playing again, still xruns

This commit is contained in:
Sebastian
2025-06-13 02:35:31 +02:00
parent b78060aac2
commit 76f2e0ec28
3 changed files with 72 additions and 46 deletions

View File

@ -18,18 +18,13 @@
#define AURAL 1
#define UI_SAMPLERATE 22050
#define SIZE 1024
#define RINGBUFFER 16384
#define ECHO 24000
#define BUFFERSIZE 1024
#define NSTREAMS 8
int16_t buffer[SIZE];
int16_t buffer2[ECHO];
int16_t buffer[BUFFERSIZE];
WaveStream stream[NSTREAMS];
//File streams[NSTREAMS];
bool streams_loaded = false;
I2S i2s(INPUT_PULLUP);
@ -101,28 +96,18 @@ size_t count;
size_t tape_write = 0;
void codec_transmit() {
// for(int i = 0; i < count; i++){
// buffer2[tape_write] = buffer[i];
// tape_write++;
// if(tape_write == ECHO) tape_write = 0;
// int tape_read = tape_write + 1;
// if(tape_read < 0) tape_read += ECHO;
// buffer[i] += buffer2[tape_read % ECHO];
// }
for(int i = 0; i < count; i++){
int16_t sample = 0;
int j = active % NSTREAMS;
sample = stream[j].get();
buffer[i] += (sample);
buffer[i] += sample;
}
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
}
void codec_receive(){
count = i2s.read((uint8_t *)&buffer, SIZE * sizeof(int16_t)) * sizeof(uint32_t) / sizeof(int16_t);
count = i2s.read((uint8_t *)&buffer, BUFFERSIZE * sizeof(int16_t)) * sizeof(uint32_t) / sizeof(int16_t);
for(int i = 0; i < count; i++){
buffer[i] *= -1;
}
@ -256,7 +241,7 @@ void setup() {
i2s.swapClocks();
i2s.setBitsPerSample(16);
i2s.setBuffers(6, SIZE * sizeof(int16_t) / sizeof(uint32_t));
i2s.setBuffers(4, BUFFERSIZE * sizeof(int16_t) / sizeof(uint32_t));
if(!i2s.begin(48000)){
Serial.println("I2S error!");
@ -265,13 +250,29 @@ void setup() {
if(sdInitialized) {
for(int i = 0; i < NSTREAMS; i++){
stream[i].begin();
char filename[40];
sprintf(filename, "/sound/%d.wav", i+1);
if(SD.exists(filename)){
stream[i].load(SD.open(filename));
stream[i].begin();
//stream[i].play();
Serial.println(stream[i].wavefile.blockalign);
bool loaded = stream[i].load(SD.open(filename));
if(loaded) {
Serial.print("file read: ");
Serial.print(stream[i].wavefile.length);
Serial.print(" bytes | ");
Serial.print(stream[i].wavefile.samplerate);
Serial.print(" kHz | ");
Serial.print(stream[i].wavefile.bitspersample);
Serial.print(" bits | ");
Serial.print(stream[i].wavefile.channels);
Serial.print(" channels | ");
Serial.print(stream[i].wavefile.blockalign);
Serial.println(" bytes");
//stream[i].play();
} else {
Serial.println("file loading error");
}
} else {
for(int k = 0; k < 3; k++){
digitalWrite(6, HIGH);
@ -386,6 +387,11 @@ void loop() {
Serial.println(codec.getVolumeL());
for(int i = 0; i < NSTREAMS; i++){
stream[i].pause();
}
stream[active % NSTREAMS].play();
buttonChanged = false;
}
@ -408,6 +414,15 @@ void loop() {
}
FastLED.show();
if(streams_loaded) {
for(int i = 0; i < NSTREAMS; i++){
stream[i].stream();
}
}
if(i2s.getOverflow()) Serial.println("overflow");
if(i2s.getUnderflow()) Serial.println("underflow");
delay(20); // wait 1ms
}
@ -416,9 +431,5 @@ void setup1(){
}
void loop1(){
if(streams_loaded) {
for(int i = 0; i < NSTREAMS; i++){
stream[i].stream();
}
}
}