Samuel Mokrani
/
USBAudio_micro
USBAudio example using a microphone
Diff: main.cpp
- Revision:
- 7:6b0012b8fd01
- Parent:
- 6:be128039be16
- Child:
- 8:caede7b4c444
--- a/main.cpp Tue Dec 20 11:17:33 2011 +0000 +++ b/main.cpp Tue Dec 20 11:41:31 2011 +0000 @@ -1,9 +1,5 @@ #include "mbed.h" -#include "USBAudio.h" - -extern "C" void HardFault_Handler() { - error("Hard Fault!\n"); -} +#include "USBAudioOUT.h" // frequency: 8 kHz #define FREQ 8000 @@ -14,15 +10,13 @@ // 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 #define AUDIO_LENGTH_PACKET (FREQ/500) * NB_CHA -USBAudio audio(FREQ, NB_CHA, 0x1111, 0x78ab); +USBAudioOUT audio(FREQ, NB_CHA, 0x1111, 0x78ab); AnalogIn mic(p20); -DigitalOut p(p19); int16_t buf[AUDIO_LENGTH_PACKET/2]; int main() { - double mic_mean = 0.0; double mic_value; @@ -33,14 +27,12 @@ } while (1) { - p = 1; for (int i = 0; i < AUDIO_LENGTH_PACKET/2; i++) { buf[i] = (mic.read_u16() >> 3) - mic_mean; if (i != AUDIO_LENGTH_PACKET/2) { wait_us(80); } } - p = 0; audio.write((uint8_t *)buf); } }