Il y avait des problèmes dans la libraire...

Dependencies:   ST_FREQUENCY_DIVIDER ST_I2S USBDEVICE

Fork of X_NUCLEO_CCA02M1 by ST

Revision:
15:17bdadc6aa9c
Parent:
13:90465220b75f
Child:
16:4ab2eac7be21
--- a/Middlewares/OpenPDM2PCM/OpenPDMFilter.c	Tue May 02 12:53:15 2017 +0000
+++ b/Middlewares/OpenPDM2PCM/OpenPDMFilter.c	Tue May 02 18:06:58 2017 +0200
@@ -35,35 +35,55 @@
 
 /* Definitions ---------------------------------------------------------------*/
 
-#define maxDecFactor 128
 #define maxVol 64
 #define FilterGain 16;
 #define RoundDiv(a, b) (((a)>0)?(((a)+(b)/2)/(b)):(((a)-(b)/2)/(b)))
 #define SaturaLH(N, L, H) (((N)<(L))?(L):(((N)>(H))?(H):(N)))
 
+#define SINCN_MAX 3
+#define DECIMATION_MAX 64
+
 
 /* Variables -----------------------------------------------------------------*/
 
-uint32_t coef[5][maxDecFactor]; // Max sinc 5 with decimation 128
 uint32_t DivideConst = 0;
 int64_t SubConst = 0;
-uint32_t sinc1[maxDecFactor];
-uint32_t sinc2[maxDecFactor*2];
-uint32_t sinc3[maxDecFactor*3];
-uint32_t sinc4[maxDecFactor*4];
-uint32_t sinc[maxDecFactor*5];              
+uint32_t sinc1[DECIMATION_MAX];
+uint32_t sinc2[DECIMATION_MAX*2];
+uint32_t sinc3[DECIMATION_MAX*3];
+uint32_t sinc4[DECIMATION_MAX*4];
+uint32_t sinc[DECIMATION_MAX*5];              
 int64_t Z = 0;
-uint16_t app;
+uint32_t coef[5][DECIMATION_MAX]; // Max sinc 5 with Param->Decimation = 128.
+#ifdef USE_LUT
+int32_t lut[256][DECIMATION_MAX / 8][SINCN_MAX];
+#endif
 
 
 /* Functions -----------------------------------------------------------------*/
 
-int64_t filterTable(uint8_t *data, uint8_t table, uint8_t decimation, uint8_t channels);
+int64_t filterTable(uint8_t *data, uint8_t SincN, uint8_t decimation, uint8_t channels);
 
 void convolve(uint32_t Signal[/* SignalLen */], unsigned short SignalLen,
               uint32_t Kernel[/* KernelLen */], unsigned short KernelLen,
               uint32_t Result[/* SignalLen + KernelLen - 1 */]);
 
+#ifdef USE_LUT
+inline int64_t filterTable(uint8_t *data, uint8_t SincN, uint8_t decimation, uint8_t channels)
+{
+  uint8_t c, d;
+  uint16_t data_index = 0;
+  int64_t F = 0;
+
+  for (d = 0; d < (decimation >> 3); d++)
+  {
+    c = data[data_index];
+    F += lut[c][d][SincN];
+    data_index += channels;
+  }
+  return F;
+}
+#else
 inline int64_t filterTable(uint8_t *data, uint8_t table, uint8_t decimation, uint8_t channels)
 {
   uint8_t c, i;
@@ -72,7 +92,7 @@
   int64_t F = 0;
 
   for (i = 0; i < decimation; i += 8)
-  {  
+  {
     c = data[data_index];
     F += ((c >> 7)       ) * coef_p[i    ] +
          ((c >> 6) & 0x01) * coef_p[i + 1] +
@@ -86,6 +106,7 @@
   }
   return F;
 }
+#endif
 
 void Open_PDM_Filter_Init(TPDMFilter_InitStruct *Param)
 {
@@ -203,7 +224,27 @@
   }
   SubConst = sum  / 2;
   DivideConst = SubConst*maxVol/32768/FilterGain;
-  if(DivideConst == 0 ) DivideConst = 1;
+  if (DivideConst == 0)
+    DivideConst = 1;
+
+#ifdef USE_LUT
+  /* Look-Up Table. */
+  uint16_t c, d, s;
+  for (s = 0; s < SINCN_MAX; s++)
+  {
+    uint32_t *coef_p = &coef[s][0];
+    for (c = 0; c < 256; c++)
+      for (d = 0; d < DECIMATION_MAX / 8; d++)
+        lut[c][d][s] = ((c >> 7)       ) * coef_p[d * 8    ] +
+                       ((c >> 6) & 0x01) * coef_p[d * 8 + 1] +
+                       ((c >> 5) & 0x01) * coef_p[d * 8 + 2] +
+                       ((c >> 4) & 0x01) * coef_p[d * 8 + 3] +
+                       ((c >> 3) & 0x01) * coef_p[d * 8 + 4] +
+                       ((c >> 2) & 0x01) * coef_p[d * 8 + 5] +
+                       ((c >> 1) & 0x01) * coef_p[d * 8 + 6] +
+                       ((c     ) & 0x01) * coef_p[d * 8 + 7];
+  }
+#endif
 }
 
 void convolve(uint32_t Signal[/* SignalLen */], unsigned short SignalLen,