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: BSP/PDM2PCMAudio.h
- Revision:
- 20:9952bef19da1
- Parent:
- 17:a758b376b018
--- a/BSP/PDM2PCMAudio.h Thu May 04 10:39:39 2017 +0000 +++ b/BSP/PDM2PCMAudio.h Fri May 05 11:34:10 2017 +0000 @@ -69,12 +69,11 @@ /* Definitions ---------------------------------------------------------------*/ -#define DEMUX_FILTER_SIZE 128 -#define DEMUX_FILTER_MASK 0x55 -#define PDM2PCM_FILTER_SIZE 4 -#define PDM2PCM_NOGAIN_VOLUME 4 -#define PDM2PCM_MAX_VOLUME 64 -#define PDM2PCM_DECIMATION_FACTOR 64 +#define DEMUX_FILTER_SIZE 128 +#define DEMUX_FILTER_MASK 0x55 +#define PDM2PCM_FILTER_SIZE 4 +#define PDM2PCM_NOGAIN_VOLUME 4 +#define PDM2PCM_MAX_VOLUME 64 /* Classes -------------------------------------------------------------------*/ @@ -100,6 +99,22 @@ /* Enable CRC peripheral to unlock the PDM2PCMAudio library. */ __CRC_CLK_ENABLE(); + /* Setting configuration. */ + switch (_frequency) + { + case I2S_AUDIOFREQ_8K: + _decimation_factor = 128; + break; + + case I2S_AUDIOFREQ_16K: + case I2S_AUDIOFREQ_32K: + case I2S_AUDIOFREQ_44K: + case I2S_AUDIOFREQ_48K: + default: + _decimation_factor = 64; + break; + } + /* Initializing PDM2PCMAudio Filter. */ for (uint32_t i = 0; i < _channels; i++) { @@ -109,6 +124,8 @@ _PDM2PCM_filter[i].Fs = _frequency; _PDM2PCM_filter[i].Out_MicChannels = _channels; _PDM2PCM_filter[i].In_MicChannels = _channels; + _PDM2PCM_filter[i].Decimation = _decimation_factor; + _PDM2PCM_filter[i].MaxVolume = PDM2PCM_MAX_VOLUME; #ifdef USE_OPEN_PDM2PCM_LIBRARY Open_PDM_Filter_Init((TPDMFilter_InitStruct *) &_PDM2PCM_filter[i]); #else @@ -118,14 +135,20 @@ }; /** - * @brief Converting audio data from PDM to PCM. - * @param output_buffer Pointer to output PCM buffer data. - * @param input_buffer Pointer to input PDM buffer data. - * @param volume Volume level (it must be in the range [0..64]). - * @param decimation_factor Decimation factor (it must be either 64 or 128). - * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. - */ - status_t convert(int16_t *output_buffer, uint16_t *input_buffer, uint32_t volume, uint32_t decimation_factor); + * @brief Getting number of PCM samples from nummber of PDM samples. + * @param PCM_samples Number of PCM samples. + * @retval Number of equivalent PDM samples. + */ + uint32_t pcm2pdm_samples(uint32_t PCM_samples); + + /** + * @brief Converting audio data from PDM to PCM. + * @param output_buffer Pointer to output PCM buffer data. + * @param input_buffer Pointer to input PDM buffer data. + * @param volume Volume level (it must be in the range [0..PDM2PCM_MAX_VOLUME]). + * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. + */ + status_t convert(int16_t *output_buffer, uint16_t *input_buffer, uint32_t volume); /** * @brief Scrambling audio data. @@ -150,6 +173,7 @@ uint32_t _frequency; uint32_t _channels; + uint32_t _decimation_factor; #ifdef USE_OPEN_PDM2PCM_LIBRARY TPDMFilter_InitStruct _PDM2PCM_filter[PDM2PCM_FILTER_SIZE]; #else