Samuel Mokrani
/
USBAudio_micro
USBAudio example using a microphone
Diff: main.cpp
- Revision:
- 4:bef3b485f22e
- Parent:
- 3:e6a29c83ac52
- Child:
- 5:b49b6a8ca111
diff -r e6a29c83ac52 -r bef3b485f22e main.cpp --- a/main.cpp Mon Dec 19 15:46:17 2011 +0000 +++ b/main.cpp Mon Dec 19 16:13:32 2011 +0000 @@ -1,47 +1,25 @@ #include "mbed.h" #include "USBAudio.h" -#include "SDFileSystem.h" extern "C" void HardFault_Handler() { error("Hard Fault!\n"); } USBAudio audio(8000, 1, 0x74ac, 0x8788); -SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board AnalogIn mic(p20); DigitalOut p(p21); -/* Wav file header data, for setting up the transfer protocol */ -short channels; -long sampleRate; -short wordWidth; - int16_t buf[8]; + int main() { - FILE * fp; - - fp = fopen("/sd/3.wav", "r"); - if (fp == NULL) { - error("Could not open file for write\n"); - } - - printf("test\r\n"); - /* Parse wav file header */ - fseek(fp, 22, SEEK_SET); - fread(&channels, 2, 1, fp); - fseek(fp, 24, SEEK_SET); - fread(&sampleRate, 4, 1, fp); - fseek(fp, 34, SEEK_SET); - fread(&wordWidth, 2, 1, fp); while (1) { p = 1; for (int i = 0; i < 8; i++) { - if (!feof(fp)) { - fread(buf + i, 2, 1, fp); - } else { - fseek(fp, 36, SEEK_SET); + buf[i] = (mic.read_u16() >> 3) - 4100; + if (i != 7) { + wait_us(110); } } p = 0;