Plays USB Audio packets through external DAC (Cirrus Logic CS4344). Simple demo code, don't expect a sophisticated I2S library. HW setup: mbed DIP 5 (I2STX_SDA) -> DAC SDIN (Serial Audio Data Input) mbed DIP 6 (I2STX_WS) -> DAC LRCK (Left Right Clock) mbed DIP 7 (I2STX_CLK) -> DAC SCLK (External Serial Clock Input) mbed DIP 30 (I2SRX_CLK) -> DAC MCLK (Master Clock) also needed an extra USB connector wired to mbed. Does not work with built-in USB. Code needs a bit of clean up.
main.cpp@0:bf9e7b99dda5, 2012-04-16 (annotated)
- Committer:
- csorbag
- Date:
- Mon Apr 16 08:28:42 2012 +0000
- Revision:
- 0:bf9e7b99dda5
- Child:
- 1:12e8ee1b7ea2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
csorbag | 0:bf9e7b99dda5 | 1 | #include "mbed.h" |
csorbag | 0:bf9e7b99dda5 | 2 | #include "USBAudio.h" |
csorbag | 0:bf9e7b99dda5 | 3 | #include "I2S.h" |
csorbag | 0:bf9e7b99dda5 | 4 | |
csorbag | 0:bf9e7b99dda5 | 5 | Serial pc(USBTX, USBRX); |
csorbag | 0:bf9e7b99dda5 | 6 | |
csorbag | 0:bf9e7b99dda5 | 7 | // frequency: 48 kHz |
csorbag | 0:bf9e7b99dda5 | 8 | #define FREQ 48000 |
csorbag | 0:bf9e7b99dda5 | 9 | |
csorbag | 0:bf9e7b99dda5 | 10 | // 1 channel: mono |
csorbag | 0:bf9e7b99dda5 | 11 | #define NB_CHA 2 |
csorbag | 0:bf9e7b99dda5 | 12 | |
csorbag | 0:bf9e7b99dda5 | 13 | // length of an audio packet: each ms, we receive 48 * 16bits ->48 * 2 bytes per channel. For stereo multiply by 2 |
csorbag | 0:bf9e7b99dda5 | 14 | #define AUDIO_LENGTH_PACKET 48 * 2 * 2 |
csorbag | 0:bf9e7b99dda5 | 15 | |
csorbag | 0:bf9e7b99dda5 | 16 | // USBAudio |
csorbag | 0:bf9e7b99dda5 | 17 | USBAudio audio(FREQ, NB_CHA,FREQ, NB_CHA,0x7bb8, 0x1112); |
csorbag | 0:bf9e7b99dda5 | 18 | |
csorbag | 0:bf9e7b99dda5 | 19 | int main() { |
csorbag | 0:bf9e7b99dda5 | 20 | int16_t buf[AUDIO_LENGTH_PACKET/2]; |
csorbag | 0:bf9e7b99dda5 | 21 | |
csorbag | 0:bf9e7b99dda5 | 22 | |
csorbag | 0:bf9e7b99dda5 | 23 | setup(&pc); |
csorbag | 0:bf9e7b99dda5 | 24 | pc.printf("Begin new\n"); |
csorbag | 0:bf9e7b99dda5 | 25 | |
csorbag | 0:bf9e7b99dda5 | 26 | while (1) { |
csorbag | 0:bf9e7b99dda5 | 27 | // read an audio packet |
csorbag | 0:bf9e7b99dda5 | 28 | audio.read((uint8_t *)buf); |
csorbag | 0:bf9e7b99dda5 | 29 | |
csorbag | 0:bf9e7b99dda5 | 30 | // send to DAC |
csorbag | 0:bf9e7b99dda5 | 31 | play(buf,AUDIO_LENGTH_PACKET/2); |
csorbag | 0:bf9e7b99dda5 | 32 | } |
csorbag | 0:bf9e7b99dda5 | 33 | } |