96kHz-16bit USB Audio Output interface with UDA1345 and 24.576MHz Xtal.

Dependencies:   I2S USBDevice mbed

Fork of USBAudioPlayback by Samuel Mokrani

Files at this revision

API Documentation at this revision

Comitter:
edy555
Date:
Wed Feb 05 14:31:03 2014 +0000
Parent:
4:a3aee5fc768a
Child:
6:dc7b32ce4277
Commit message:
increase # of chunks, keep in-out interval on ring buffer

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- 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)];
     }