echo sound see http://mbed.org/users/okini3939/notebook/I2S_TLV320AIC23B/

Dependencies:   I2SSlave TLV320 mbed

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Fri Nov 23 08:24:10 2012 +0000
Commit message:
1st build

Changed in this revision

I2SSlave.lib Show annotated file Show diff for this revision Revisions of this file
TLV320.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2SSlave.lib	Fri Nov 23 08:24:10 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/d_worrall/code/I2SSlave/#aa3e863920d2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TLV320.lib	Fri Nov 23 08:24:10 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/d_worrall/code/TLV320/#7e76c6f56169
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Nov 23 08:24:10 2012 +0000
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "TLV320.h"
+
+#define BUF_SIZE 4000
+
+Serial pc(USBTX, USBRX);
+TLV320 audio(p9, p10, 0x34, p5, p6, p7, p8, p16); // I2S Codec
+DigitalOut myled(LED1);
+
+volatile int count = 0;
+int addr = 0;
+int buffer[BUF_SIZE];
+
+// interrupt TLV320 send/recv
+void isr_audio () {
+    int i, a;
+    short l, r, ll, rr;
+    int buf[4];
+
+    // I2S input
+    audio.read();
+    for (i = 0; i < 4; i ++) {
+        buf[i] = audio.rxBuffer[i];
+    }
+
+    for (i = 0; i < 4; i ++) {
+        l = (buffer[addr + i] >> 16);
+        r = (buffer[addr + i] & 0xffff);
+        ll = (buf[i] >> 16);
+        rr = (buf[i] & 0xffff);
+        l = (ll * 0.66) + (l * 0.33);
+        r = (rr * 0.66) + (r * 0.33);
+        buffer[addr + i] = buf[i];
+        buf[i] = (l << 16) | (r & 0xffff);
+    }
+    addr += 4;
+    if (addr >= BUF_SIZE) addr = 0;
+
+    audio.write(buf, 0, 4);
+
+    count ++;
+}
+
+int main() {
+    int time = 0;
+
+    pc.baud(115200);
+    memset(buffer, 0, sizeof(buffer));
+
+    audio.power(0x02); // mic off
+    audio.outputVolume(1, 1); // headphone off
+    audio.inputVolume(1, 1);
+    audio.frequency(44100);
+    audio.attach(&isr_audio);
+    audio.start(RECEIVE);
+    printf("Audio ready\r\n");
+
+    while (1) {
+        printf("%d / %d\r\n", time, count);
+        printf("L %04x / R %04x\r\n", (buffer[0] >> 16), (buffer[0] & 0xffff));
+        time ++;
+
+        myled = 1;
+        wait(0.5);
+        myled = 0;
+        wait(0.5);
+
+//        if (pc.readable()) break;
+    }
+
+    audio.stop();
+    printf("exit\r\n");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Nov 23 08:24:10 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/24d45a770a51
\ No newline at end of file