Samuel Mokrani
/
USBAudio_micro
USBAudio example using a microphone
main.cpp@3:e6a29c83ac52, 2011-12-19 (annotated)
- Committer:
- samux
- Date:
- Mon Dec 19 15:46:17 2011 +0000
- Revision:
- 3:e6a29c83ac52
- Parent:
- 0:539ec61e1fbb
- Child:
- 4:bef3b485f22e
ok we can send a music from an sdcard but readings are time to time slow...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux |
0:539ec61e1fbb | 1 | #include "mbed.h" |
samux |
0:539ec61e1fbb | 2 | #include "USBAudio.h" |
samux |
3:e6a29c83ac52 | 3 | #include "SDFileSystem.h" |
samux |
0:539ec61e1fbb | 4 | |
samux |
0:539ec61e1fbb | 5 | extern "C" void HardFault_Handler() { |
samux |
0:539ec61e1fbb | 6 | error("Hard Fault!\n"); |
samux |
0:539ec61e1fbb | 7 | } |
samux |
0:539ec61e1fbb | 8 | |
samux |
0:539ec61e1fbb | 9 | USBAudio audio(8000, 1, 0x74ac, 0x8788); |
samux |
3:e6a29c83ac52 | 10 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board |
samux |
3:e6a29c83ac52 | 11 | AnalogIn mic(p20); |
samux |
3:e6a29c83ac52 | 12 | DigitalOut p(p21); |
samux |
0:539ec61e1fbb | 13 | |
samux |
3:e6a29c83ac52 | 14 | /* Wav file header data, for setting up the transfer protocol */ |
samux |
3:e6a29c83ac52 | 15 | short channels; |
samux |
3:e6a29c83ac52 | 16 | long sampleRate; |
samux |
3:e6a29c83ac52 | 17 | short wordWidth; |
samux |
3:e6a29c83ac52 | 18 | |
samux |
3:e6a29c83ac52 | 19 | int16_t buf[8]; |
samux |
0:539ec61e1fbb | 20 | |
samux |
0:539ec61e1fbb | 21 | int main() { |
samux |
3:e6a29c83ac52 | 22 | FILE * fp; |
samux |
3:e6a29c83ac52 | 23 | |
samux |
3:e6a29c83ac52 | 24 | fp = fopen("/sd/3.wav", "r"); |
samux |
3:e6a29c83ac52 | 25 | if (fp == NULL) { |
samux |
3:e6a29c83ac52 | 26 | error("Could not open file for write\n"); |
samux |
0:539ec61e1fbb | 27 | } |
samux |
3:e6a29c83ac52 | 28 | |
samux |
3:e6a29c83ac52 | 29 | printf("test\r\n"); |
samux |
3:e6a29c83ac52 | 30 | /* Parse wav file header */ |
samux |
3:e6a29c83ac52 | 31 | fseek(fp, 22, SEEK_SET); |
samux |
3:e6a29c83ac52 | 32 | fread(&channels, 2, 1, fp); |
samux |
3:e6a29c83ac52 | 33 | fseek(fp, 24, SEEK_SET); |
samux |
3:e6a29c83ac52 | 34 | fread(&sampleRate, 4, 1, fp); |
samux |
3:e6a29c83ac52 | 35 | fseek(fp, 34, SEEK_SET); |
samux |
3:e6a29c83ac52 | 36 | fread(&wordWidth, 2, 1, fp); |
samux |
3:e6a29c83ac52 | 37 | |
samux |
0:539ec61e1fbb | 38 | while (1) { |
samux |
3:e6a29c83ac52 | 39 | p = 1; |
samux |
3:e6a29c83ac52 | 40 | for (int i = 0; i < 8; i++) { |
samux |
3:e6a29c83ac52 | 41 | if (!feof(fp)) { |
samux |
3:e6a29c83ac52 | 42 | fread(buf + i, 2, 1, fp); |
samux |
3:e6a29c83ac52 | 43 | } else { |
samux |
3:e6a29c83ac52 | 44 | fseek(fp, 36, SEEK_SET); |
samux |
3:e6a29c83ac52 | 45 | } |
samux |
3:e6a29c83ac52 | 46 | } |
samux |
3:e6a29c83ac52 | 47 | p = 0; |
samux |
0:539ec61e1fbb | 48 | audio.write((uint8_t *)buf); |
samux |
0:539ec61e1fbb | 49 | } |
samux |
0:539ec61e1fbb | 50 | } |