kouchikosen kairohan
/
USBAudio_PWM
USBAudio play by PWM.
Fork of USBAudio_HelloWorld by
main.cpp@1:d712dff4f9ca, 2011-11-30 (annotated)
- Committer:
- samux
- Date:
- Wed Nov 30 10:31:06 2011 +0000
- Revision:
- 1:d712dff4f9ca
- Parent:
- 0:3a00949fdb07
- Child:
- 3:c16e446c439a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:3a00949fdb07 | 1 | // Hello World example for the USBAudio library |
samux | 0:3a00949fdb07 | 2 | |
samux | 0:3a00949fdb07 | 3 | #include "mbed.h" |
samux | 0:3a00949fdb07 | 4 | #include "USBAudio.h" |
samux | 0:3a00949fdb07 | 5 | |
samux | 0:3a00949fdb07 | 6 | Serial pc(USBTX, USBRX); |
samux | 0:3a00949fdb07 | 7 | |
samux | 0:3a00949fdb07 | 8 | // frequency: 48 kHz |
samux | 0:3a00949fdb07 | 9 | #define FREQ 48000 |
samux | 0:3a00949fdb07 | 10 | |
samux | 0:3a00949fdb07 | 11 | // 1 channel: mono |
samux | 0:3a00949fdb07 | 12 | #define NB_CHA 1 |
samux | 0:3a00949fdb07 | 13 | |
samux | 0:3a00949fdb07 | 14 | // length of an audio packet: each ms, we receive 48 * 16bits ->48 * 2 bytes. as there is one channel, the length will be 48 * 2 * 1 |
samux | 1:d712dff4f9ca | 15 | #define AUDIO_LENGTH_PACKET 48 * 2 * 1 |
samux | 0:3a00949fdb07 | 16 | |
samux | 0:3a00949fdb07 | 17 | // USBAudio |
samux | 0:3a00949fdb07 | 18 | USBAudio audio(FREQ, NB_CHA); |
samux | 0:3a00949fdb07 | 19 | |
samux | 0:3a00949fdb07 | 20 | int main() { |
samux | 1:d712dff4f9ca | 21 | int16_t buf[AUDIO_LENGTH_PACKET/2]; |
samux | 0:3a00949fdb07 | 22 | |
samux | 0:3a00949fdb07 | 23 | while (1) { |
samux | 0:3a00949fdb07 | 24 | // read an audio packet |
samux | 1:d712dff4f9ca | 25 | audio.read((uint8_t *)buf); |
samux | 0:3a00949fdb07 | 26 | |
samux | 0:3a00949fdb07 | 27 | // print packet received |
samux | 0:3a00949fdb07 | 28 | pc.printf("recv: "); |
samux | 1:d712dff4f9ca | 29 | for(int i = 0; i < AUDIO_LENGTH_PACKET/2; i++) { |
samux | 0:3a00949fdb07 | 30 | pc.printf("%d ", buf[i]); |
samux | 0:3a00949fdb07 | 31 | } |
samux | 0:3a00949fdb07 | 32 | pc.printf("\r\n"); |
samux | 0:3a00949fdb07 | 33 | } |
samux | 0:3a00949fdb07 | 34 | } |