USBAudio example using a microphone

Dependencies:   USBDevice mbed

Files at this revision

API Documentation at this revision

Comitter:
samux
Date:
Tue Dec 20 11:17:33 2011 +0000
Parent:
5:b49b6a8ca111
Child:
7:6b0012b8fd01
Commit message:
works for m0 and m3 with cleaning up

Changed in this revision

USBDevice/USBAudio/USBAudio.cpp Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBAudio/USBAudio.h Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBAudio/USBAudio_Types.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/USBDevice/USBAudio/USBAudio.cpp	Tue Dec 20 10:44:10 2011 +0000
+++ b/USBDevice/USBAudio/USBAudio.cpp	Tue Dec 20 11:17:33 2011 +0000
@@ -274,4 +274,4 @@
         'M',0,'b',0,'e',0,'d',0,' ',0,'A',0,'u',0,'d',0,'i',0,'o',0 //bString iProduct - Mbed Audio
     };
     return stringIproductDescriptor;
-}
+}
\ No newline at end of file
--- a/USBDevice/USBAudio/USBAudio.h	Tue Dec 20 10:44:10 2011 +0000
+++ b/USBDevice/USBAudio/USBAudio.h	Tue Dec 20 11:17:33 2011 +0000
@@ -182,10 +182,7 @@
     // boolean showing that the SOF handler has been called. Useful for readNB.
     volatile bool SOF_handler;
     
-    // Is there an interrupt
     volatile bool interruptIN;
-    
-    // write has been done
     volatile bool writeIN;
 
 };
--- a/USBDevice/USBAudio/USBAudio_Types.h	Tue Dec 20 10:44:10 2011 +0000
+++ b/USBDevice/USBAudio/USBAudio_Types.h	Tue Dec 20 11:17:33 2011 +0000
@@ -22,6 +22,19 @@
 
 #define DEFAULT_CONFIGURATION (1)
 
+// Audio Request Codes
+#define REQUEST_SET_CUR     0x01
+#define REQUEST_GET_CUR     0x81
+#define REQUEST_SET_MIN     0x02
+#define REQUEST_GET_MIN     0x82
+#define REQUEST_SET_MAX     0x03
+#define REQUEST_GET_MAX     0x83
+#define REQUEST_SET_RES     0x04
+#define REQUEST_GET_RES     0x84
+
+#define MUTE_CONTROL        0x01
+#define VOLUME_CONTROL      0x02
+
 
 // Audio Descriptor Sizes
 #define CONTROL_INTERFACE_DESCRIPTOR_LENGTH       0x09
--- a/main.cpp	Tue Dec 20 10:44:10 2011 +0000
+++ b/main.cpp	Tue Dec 20 11:17:33 2011 +0000
@@ -1,6 +1,10 @@
 #include "mbed.h"
 #include "USBAudio.h"
 
+extern "C" void HardFault_Handler() {
+    error("Hard Fault!\n");
+}
+
 // frequency: 8 kHz
 #define FREQ 8000
 
@@ -10,14 +14,15 @@
 // 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, 0xaac0, 0xa734);
+USBAudio audio(FREQ, NB_CHA, 0x1111, 0x78ab);
+
 AnalogIn mic(p20);
 DigitalOut p(p19);
 
-// length of buffer = AUDIO_LENGTH_PACKET/2 because we are handling int16 and not bytes.
 int16_t buf[AUDIO_LENGTH_PACKET/2];
 
 int main() {
+
     double mic_mean = 0.0;
     double mic_value;
 
@@ -28,16 +33,14 @@
     }
 
     while (1) {
-
-        // read 8 micro samples
+        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(110);
+                wait_us(80);
             }
         }
-        // send
+        p = 0;
         audio.write((uint8_t *)buf);
-
     }
 }