ReSpeaker DSP V02

Dependencies:   mbed MbedJSONValue

Revision:
10:273127efdc6e
Parent:
9:7e20c1e5a354
Child:
11:07981b0d28d3
--- a/main.cpp	Sun Aug 26 09:55:14 2018 +0000
+++ b/main.cpp	Mon Aug 27 10:32:08 2018 +0000
@@ -64,7 +64,7 @@
 #define PI_FLOAT  (3.14159f)
 
 // json commad
-#define MSG_BUFFER_SIZE 512
+#define MSG_BUFFER_SIZE 1024
 #define HEADER_SIZE 5
 #define FOOTER_SIZE 2
 
@@ -152,6 +152,21 @@
 uint32_t trigDelay = trigDelaySet; // counter for pulse pass
 uint32_t trigPause = 10; // pause after trigger in microseconds
 
+// Filter variables
+//SOS Matrix limited to order 10
+int   FilterSections=1;
+float SOSMat[5][6]={  // Predefined SOS Matrix (second order 5Khz filter
+        1, -2, 1,  1, -1.961,  0.9624,
+        0,  0, 0,  0,  0,  0,
+        0,  0, 0,  0,  0,  0,
+        0,  0, 0,  0,  0,  0,
+        0,  0, 0,  0,  0,  0
+    };
+float Gscale = 0.9810f;
+float filterCurrInput[6] = {0};
+float filterLastInput[6] = {0};
+float filterLLastInput[6] = {0};
+
 // Buffer mode variables
 uint32_t bufferSizeSet = 5000;
 uint32_t bufferSize = bufferSizeSet;
@@ -189,6 +204,9 @@
 // DSP Param Packet Handler
 void dspParamPacket(void);
 
+// DSP Filter Packet Handler
+void dspFilterPacket(void);
+
 // initialize DSP
 void initDSP(void);
 
@@ -415,6 +433,8 @@
         dspPacket();
     } else if (targetName == "dspParam") {
         dspParamPacket();
+    } else if (targetName == "dspFilter") {
+        dspFilterPacket();
     } else {
 #ifdef DEBUG_MOD2
         // unrecognised target
@@ -458,7 +478,8 @@
         FilterFunction = offMode;
         operationMode = 0 ;
     }
-
+    // succesfull parse
+    switch_dsp.printf("{\"Ack\":\"dsp\",\"mode\":\"%s\"}\r\n",modeType.c_str());
 }// end dspPacket
 // DSP Param Packet Handler
 void dspParamPacket(void)
@@ -472,7 +493,33 @@
     trigDelay = trigDelaySet;
 #ifdef DEBUG_MOD10
     // send parsed values
-    pc.printf("SignalGain: %f , trigTresh: %f , trigDelaySet %d , trigPause: %d\r\n", signalGain , trigTresh , trigDelaySet , trigPause);
+    pc.printf("SignalGain: %.3f , trigTresh: %.3f , trigDelaySet %d , trigPause: %d\r\n", signalGain , trigTresh , trigDelaySet , trigPause);
 #endif
+    // succesfull parse
+    switch_dsp.printf("{\"Ack\":\"dspParam\",\"SignalGain\":%.3f,\"trigTresh\":%.3f,\"trigDelaySet\":%d,\"trigPause\":%d}\r\n", signalGain , trigTresh , trigDelaySet , trigPause);
+} // end dspParamPacket
 
-} // end dspParamPacket
\ No newline at end of file
+// DSP Filter Packet Handler
+void dspFilterPacket(void)
+{ 
+    // get values.
+    FilterSections  = (guiCmd["Sections"].get<int>());
+    Gscale          = ((float)(guiCmd["Gscale"].get<int>()))/10000.0f; // issue in parsing doubles
+    
+    // get SOSMat
+    for (int jj=0 ; jj < FilterSections ; jj++){
+        for (int ii=0 ; ii < 5 ; ii++) {
+        SOSMat[jj][ii] = ((float)guiCmd["SOSMat"][jj][ii].get<int>())/10000.0f;
+        }
+    }
+#ifdef DEBUG_MOD10
+    // send parsed values
+    pc.printf("FilterSections: %d , Gscale: %.3f\r\n", FilterSections , Gscale);
+    pc.printf("SOSMat \r\n");
+    for (int jj=0 ; jj < FilterSections ; jj++){
+        pc.printf("%.3f , %.3f , %.3f , %.3f , %.3f , %.3f \r\n",SOSMat[jj][0] ,SOSMat[jj][1],SOSMat[jj][2],SOSMat[jj][3] ,SOSMat[jj][4] ,SOSMat[jj][5]);
+    }
+#endif
+    // succesfull parse
+    switch_dsp.printf("{\"Ack\":\"dspFilter\",\"FilterSections\":%d,\"Gscale\":%.3f}\r\n", FilterSections , Gscale);
+} // end dspFilterPacket
\ No newline at end of file