Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ST_FREQUENCY_DIVIDER ST_I2S USBDEVICE
Fork of X_NUCLEO_CCA02M1 by
Revision 15:17bdadc6aa9c, committed 2017-05-02
- Comitter:
- davide.aliprandi@st.com
- Date:
- Tue May 02 18:06:58 2017 +0200
- Parent:
- 14:377677cca2e9
- Child:
- 16:4ab2eac7be21
- Commit message:
- Improve performance with a LUT (now supports stereo@32KHz).
Changed in this revision
--- a/BSP/XNucleoCCA02M1.cpp Tue May 02 12:53:15 2017 +0000
+++ b/BSP/XNucleoCCA02M1.cpp Tue May 02 18:06:58 2017 +0200
@@ -82,8 +82,9 @@
/* Checking input parameters. */
if (!(((_frequency == 16000) && (_channels == 1)) ||
((_frequency == 16000) && (_channels == 2)) ||
- ((_frequency == 32000) && (_channels == 1))))
- error("\r\nConfiguration error: Currently only mono@16KHz, stero@16KHz or mono@32KHz are supported.\n\r");
+ ((_frequency == 32000) && (_channels == 1)) ||
+ ((_frequency == 32000) && (_channels == 2))))
+ error("\r\nConfiguration error: Currently only mono@16KHz, stero@16KHz, mono@32KHz and stereo@32KHz are supported.\n\r");
#endif
/* Setting configuration. */
--- 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,
--- a/Middlewares/OpenPDM2PCM/OpenPDMFilter.h Tue May 02 12:53:15 2017 +0000
+++ b/Middlewares/OpenPDM2PCM/OpenPDMFilter.h Tue May 02 18:06:58 2017 +0200
@@ -48,6 +48,10 @@
(((uint16_t)(A) & 0x00ff) << 8))
+/* Look-Up Table to improve performance while using more FLASH and RAM memory. */
+#define USE_LUT
+
+
/* Types ---------------------------------------------------------------------*/
typedef struct {
