Files
ESP8266lib/io/teensy/I2SBaseIRQ.h
2021-02-27 15:39:26 +01:00

58 lines
1.3 KiB
C

void addSamples() {
// TODO, NOT YET IMPLEMENTED
if (freeEntries < SAMPLES_PER_BUFFER) {return false;}
//int16_t* dst = &audioBuffer[bufHead];
//memcpy(dst, samples, SAMPLES_PER_BUFFER*sizeof(int16_t));
//bufHead = (bufHead + SAMPLES_PER_BUFFER) % NUM_ENTRIES;
//curBuffer = (curBuffer + 1) % NUM_BUFFERS;
for (uint16_t i = 0; i < SAMPLES_PER_BUFFER; ++i) {
audioBuffer[bufHead] = samples[i];
bufHead = (bufHead + 1) % NUM_ENTRIES;
}
freeEntries -= SAMPLES_PER_BUFFER;
arm_dcache_flush_delete(audioBuffer, NUM_ENTRIES*sizeof(int16_t));
return true;
#endif
}
void setup() {
attachInterruptVector(IRQ_SAI2, isrAudio);
NVIC_ENABLE_IRQ(IRQ_SAI2);
NVIC_SET_PRIORITY(IRQ_SAI2, 127);
I2S2_TCSR |= 1<<8;
}
// interrupt service routine
static void isrAudio() {
// TODO, not yet implemented
static constexpr volatile uint16_t* txReg = (uint16_t *)((uint32_t)&I2S2_TDR0 + 2);
//static constexpr uint16_t* txReg = (uint16_t *)((uint32_t)&I2S2_TDR0 );
//if (CHANNELS == 2) {
const uint16_t sample1 = audioBuffer[bufTail];
//*txReg = sample1;
bufTail = (bufTail + 1) & (NUM_ENTRIES-1);
if (freeEntries < NUM_ENTRIES) {++freeEntries;}
*txReg = sample1;
//}
}