Samuel Mokrani
/
USBAudio_micro
USBAudio example using a microphone
main.cpp
- Committer:
- samux
- Date:
- 2011-12-19
- Revision:
- 3:e6a29c83ac52
- Parent:
- 0:539ec61e1fbb
- Child:
- 4:bef3b485f22e
File content as of revision 3:e6a29c83ac52:
#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); } } p = 0; audio.write((uint8_t *)buf); } }