Same as ADC_DAC Reverse play

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
STM32Workshop
Date:
Tue Nov 07 13:06:56 2017 +0000
Parent:
2:9b47f309e601
Commit message:
Small Code updates

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Jul 25 09:18:43 2016 +0000
+++ b/main.cpp	Tue Nov 07 13:06:56 2017 +0000
@@ -12,7 +12,10 @@
 Ticker Audio_Sample_Ticker;
 
 // Audio Buffer
-#define BUFFERSIZE 30000 // Sample rate 10 Khz, 3 sec record 30*10^3 samples
+#define BUFFERSIZE 50000 // Sample rate 10 Khz, 5 sec record 50*10^3 samples
+#define RECORD_US 100 // recording delay
+#define PLAY_US 100  // play back delay
+#define GAIN 2.0f
 uint16_t ABuffer[BUFFERSIZE]={0};
 // variables to store buffer position and lenght
 int BufferEnd=0;
@@ -42,7 +45,7 @@
 int main() { // setup loop
   
   // attach Ticker object
-  Audio_Sample_Ticker.attach_us(&Audio_Sample, 100); // create 10Khz Ticker
+  Audio_Sample_Ticker.attach_us(&Audio_Sample, RECORD_US); // create 10Khz Ticker
   
   while(1) { // infinite loop
     if (Audio_Sample_Flag){
@@ -60,7 +63,8 @@
             CurY=AHPF*(LastY+CurU-LastU);
             
             // Amplify, add dc offset and add to buffer;
-            AudioSignal=CurY*2.0f+0.5f;//*10.0f+0.5f);
+            AudioSignal=CurY*GAIN+0.5f;
+            // trim signal
             if (AudioSignal>1){
                 AudioSignal=1;
             }else if (AudioSignal<0){
@@ -72,7 +76,7 @@
           if (LastButtonState){ // first sample
               Buffer_i=0;
               // Re-set Ticker object
-              Audio_Sample_Ticker.attach_us(&Audio_Sample, 100); // create 10Khz Ticker
+              Audio_Sample_Ticker.attach_us(&Audio_Sample, RECORD_US); // create 10Khz Ticker
           }
           // Record samples
            //ABuffer[Buffer_i]=AudioIn.read_u16();
@@ -94,7 +98,7 @@
         }else if (ButtonState) { //Button is unpressed
           if (!LastButtonState){ // first sample
               // Re-set Ticker object
-              Audio_Sample_Ticker.attach_us(&Audio_Sample, 150); // create 10Khz Ticker
+              Audio_Sample_Ticker.attach_us(&Audio_Sample, PLAY_US); // create 10Khz Ticker
               Buffer_i=BufferEnd;
           }
           myled.write(0); // LED Off
--- a/mbed.bld	Mon Jul 25 09:18:43 2016 +0000
+++ b/mbed.bld	Tue Nov 07 13:06:56 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/fb8e0ae1cceb
\ No newline at end of file