96kHz-16bit USB Audio Output interface with UDA1345 and 24.576MHz Xtal.
Dependencies: I2S USBDevice mbed
Fork of USBAudioPlayback by
Diff: main.cpp
- Revision:
- 5:ca2316551f3d
- Parent:
- 4:a3aee5fc768a
- Child:
- 6:dc7b32ce4277
--- a/main.cpp Tue Feb 04 15:35:52 2014 +0000 +++ b/main.cpp Wed Feb 05 14:31:03 2014 +0000 @@ -24,7 +24,7 @@ I2S i2s(I2S_TRANSMIT, p5, p6, p7); I2S i2srx(I2S_RECEIVE, p8, p29, p15); -#define CHUNKS 6 +#define CHUNKS 8 int buf_out[LENGTH_AUDIO_PACKET_MIC/sizeof(int)]; int16_t buf_in[CHUNKS][LENGTH_AUDIO_PACKET_SPK/sizeof(int16_t)]; @@ -54,8 +54,13 @@ i2s.write(buf, 8); stream_in += 8; if (stream_in >= stream_in_tail) { - write_pos++; - write_pos %= CHUNKS; + int d = read_pos - write_pos; + if (d < 0) + d += CHUNKS; + if (d > CHUNKS/4) { + write_pos++; + write_pos %= CHUNKS; + } stream_in = buf_in[write_pos]; stream_in_tail = &buf_in[write_pos][LENGTH_AUDIO_PACKET_SPK/sizeof(int16_t)]; }