USBAudio Hello World

Dependencies:   mbed USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Hello World example for the USBAudio library
00002  
00003 #include "mbed.h"
00004 #include "USBAudio.h"
00005  
00006 Serial pc(USBTX, USBRX);
00007  
00008 // frequency: 48 kHz
00009 #define FREQ 48000
00010  
00011 // 1 channel: mono
00012 #define NB_CHA 1
00013  
00014 // 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
00015 #define AUDIO_LENGTH_PACKET 48 * 2 * 1
00016  
00017 // USBAudio
00018 USBAudio audio(FREQ, NB_CHA);
00019  
00020 int main() {
00021     int16_t buf[AUDIO_LENGTH_PACKET/2];
00022     
00023     while (1) {
00024         // read an audio packet
00025         audio.read((uint8_t *)buf);
00026  
00027         // print packet received
00028         pc.printf("recv: ");
00029         for(int i = 0; i < AUDIO_LENGTH_PACKET/2; i++) {
00030             pc.printf("%d ", buf[i]);
00031         }
00032         pc.printf("\r\n");
00033     }
00034 }