Library to handle the X-NUCLEO-CCA02M1 MEMS Microphones Expansion Board.
Dependencies: ST_I2S ST_FREQUENCY_DIVIDER USBDEVICE
Dependents: HelloWorld_CCA02M1 HelloWorld_CCA02M1_mbedOS HelloWorld_CCA02M1 Karaoke_CCA01M1_CCA02M1_mbedOS
Fork of X_NUCLEO_CCA02M1 by
MEMS Microphones Library
Library to handle the X-NUCLEO-CCA02M1 MEMS Microphones Expansion Board. A single board allows to record a standard 2-channel stereo signal as an array of PCM samples (16 bit/sample); in principle, it could make use of six additional MEMS microphones to realize a 8-channel audio system.
Microphones configuration
Currently the configurations supported are the following:
- Stereo@48KHz
- Stereo@44.1KHz (CD audio quality)
- Stereo@32KHz
- Stereo@16KHz
- Stereo@8KHz
- Mono@48KHz
- Mono@44.1KHz
- Mono@32KHz
- Mono@16KHz
- Mono@8KHz
Mono configurations need a Jumper connecting PB_5 and PB_13 on the Morpho connector to properly work.
Platform compatibility
- This board can be currently used with the Nucleo F4 Family only, please see the ST_I2S library compatibility for further information.
- The library is compatible both with mbed OS 5.x and mbed classic 2.x (to work with mbed classic, the main application has to import the "events" library, which is not included into the "mbed" library).
I2S Peripheral Usage
By default this board makes use of the I2S peripheral available on Nucleo boards.
Acquiring through the USB
In order to acquire the recorded PCM audio channel with an audio SW on a PC, please connect the expansion board to a USB port of the PC, and the Nucleo board to a USB power supply.
Diff: Middlewares/OpenPDM2PCM/OpenPDMFilter.c
- 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,

X-NUCLEO-CCA02M1 Digital MEMS Microphones Expansion Board.