Samuel Mokrani
/
USBAudio_HelloWorld
USBAudio Hello World
main.cpp@4:d7e8697d8bd3, 2013-03-01 (annotated)
- Committer:
- samux
- Date:
- Fri Mar 01 13:12:35 2013 +0000
- Revision:
- 4:d7e8697d8bd3
- Parent:
- 3:c16e446c439a
use latest USBDevice lib (FRDM-KL25Z support)
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 | 3:c16e446c439a | 2 | |
samux | 0:3a00949fdb07 | 3 | #include "mbed.h" |
samux | 0:3a00949fdb07 | 4 | #include "USBAudio.h" |
samux | 3:c16e446c439a | 5 | |
samux | 0:3a00949fdb07 | 6 | Serial pc(USBTX, USBRX); |
samux | 3:c16e446c439a | 7 | |
samux | 0:3a00949fdb07 | 8 | // frequency: 48 kHz |
samux | 0:3a00949fdb07 | 9 | #define FREQ 48000 |
samux | 3:c16e446c439a | 10 | |
samux | 0:3a00949fdb07 | 11 | // 1 channel: mono |
samux | 0:3a00949fdb07 | 12 | #define NB_CHA 1 |
samux | 3:c16e446c439a | 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 | 3:c16e446c439a | 16 | |
samux | 0:3a00949fdb07 | 17 | // USBAudio |
samux | 0:3a00949fdb07 | 18 | USBAudio audio(FREQ, NB_CHA); |
samux | 3:c16e446c439a | 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 | 3:c16e446c439a | 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 | 3:c16e446c439a | 34 | } |