ui and sound together is almost ok but not quite there. occasional xruns

This commit is contained in:
Sebastian
2025-06-03 01:16:31 +02:00
parent ef52d50b7c
commit a1efe3cc10
4 changed files with 510 additions and 151 deletions

View File

@ -15,8 +15,15 @@
#define AURAL 1
#define UI_SAMPLERATE 22050
#define SIZE 256
#define ECHO 96000
int16_t buffer[SIZE];
int16_t buffer2[ECHO];
I2S i2s(INPUT_PULLUP);
TLV320AIC3204 codec;
TCA9555 TCA(0x20, &Wire1);
AS5600 ENC(&Wire1);
@ -68,6 +75,29 @@ void loadConfiguration(Config& config) {
file.close();
}
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];
// }
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);
for(int i = 0; i < count; i++){
buffer[i] *= -1;
}
}
void pwm_audio_callback() {
while (ui_snd.availableForWrite()) {
if(click) {
@ -90,8 +120,8 @@ void tca_irq() {
}
void setup() {
Serial.begin();
delay(2000);
//Serial.begin();
//delay(2000);
FastLED.addLeds<NEOPIXEL, 4>(edge_leds, 11);
FastLED.addLeds<NEOPIXEL, 5>(ui_leds, 74);
@ -160,26 +190,37 @@ void setup() {
ui_snd.begin(UI_SAMPLERATE);
digitalWrite(7, LOW);
pinMode(19, OUTPUT); // MCLK enable
digitalWrite(19, HIGH); // enable MCLK
pinMode(20, OUTPUT); // CODEC reset
digitalWrite(20, HIGH);
codec.begin(&Wire1);
i2s.onTransmit(codec_transmit);
i2s.onReceive(codec_receive);
i2s.setDOUT(15);
i2s.setDIN(14);
i2s.setBCLK(16); // Note: LRCLK = BCLK + 1
i2s.setMCLK(18);
i2s.setMCLKmult(256); // 12.288.000Hz
i2s.swapClocks();
i2s.setBitsPerSample(16);
i2s.setBuffers(6, SIZE * sizeof(int16_t) / sizeof(uint32_t));
if(!i2s.begin(48000)){
Serial.println("I2S error!");
while(100);
}
digitalWrite(6, HIGH);
delay(50);
digitalWrite(6, LOW);
// i2s.setDOUT(14);
// i2s.setDIN(15);
// i2s.setBCLK(16); //
// i2s.swapClocks();
// i2s.setMCLK(18);
// i2s.setBitsPerSample(16);
// i2s.setFrequency(48000);
// i2s.setSysClk(48000);
// i2s.begin();
// while (1) {
// int16_t l, r;
// i2s.read16(&l, &r);
// i2s.write16(l, r);
// }
}
int active = 0;
@ -262,6 +303,6 @@ void loop() {
}
FastLED.show();
delay(1); // wait 1ms
//delay(1); // wait 1ms
}