Il y avait des problèmes dans la libraire...
Dependencies: ST_FREQUENCY_DIVIDER ST_I2S USBDEVICE
Fork of X_NUCLEO_CCA02M1 by
Diff: BSP/PDM2PCMAudio.cpp
- Revision:
- 20:9952bef19da1
- Parent:
- 11:b2f7f79026e4
--- a/BSP/PDM2PCMAudio.cpp Thu May 04 10:39:39 2017 +0000 +++ b/BSP/PDM2PCMAudio.cpp Fri May 05 11:34:10 2017 +0000 @@ -68,55 +68,58 @@ /* Methods -------------------------------------------------------------------*/ /** -* @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 PDM2PCMAudio::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 PDM2PCMAudio::pcm2pdm_samples(uint32_t PCM_samples) +{ + return PCM_samples * (_decimation_factor >> 4); +} + +/** + * @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 PDM2PCMAudio::convert(int16_t *output_buffer, uint16_t *input_buffer, uint32_t volume) { if (!(volume <= PDM2PCM_MAX_VOLUME)) - error("Volume level not supported: it must be in the range [0..64].\r\n"); + error("Volume level not supported: it must be in the range [0..%d].\r\n", PDM2PCM_MAX_VOLUME); - switch (decimation_factor) +#ifdef PDM2PCM_AUDIO_DEBUG + _pdm2pcm_audio_signal = 1; +#endif + switch (_decimation_factor) { case 64: for (uint32_t index = 0; index < _channels; index++) { -#ifdef PDM2PCM_AUDIO_DEBUG - _pdm2pcm_audio_signal = 1; -#endif #ifdef USE_OPEN_PDM2PCM_LIBRARY - Open_PDM_Filter(&((uint8_t *) input_buffer)[index], (uint16_t *) &(output_buffer[index]), volume, (TPDMFilter_InitStruct *) &_PDM2PCM_filter[index]); + Open_PDM_Filter_64(&((uint8_t *) input_buffer)[index], (uint16_t *) &(output_buffer[index]), volume, (TPDMFilter_InitStruct *) &_PDM2PCM_filter[index]); #else PDM_Filter_64_LSB(&((uint8_t *) input_buffer)[index], (uint16_t *) &(output_buffer[index]), volume, (PDMFilter_InitStruct *) &_PDM2PCM_filter[index]); #endif -#ifdef PDM2PCM_AUDIO_DEBUG - _pdm2pcm_audio_signal = 0; -#endif } break; case 128: for (uint32_t index = 0; index < _channels; index++) { -#ifdef PDM2PCM_AUDIO_DEBUG - _pdm2pcm_audio_signal = 1; -#endif #ifdef USE_OPEN_PDM2PCM_LIBRARY - Open_PDM_Filter(&((uint8_t *) input_buffer)[index], (uint16_t *) &(output_buffer[index]), volume, (TPDMFilter_InitStruct *) &_PDM2PCM_filter[index]); + Open_PDM_Filter_128(&((uint8_t *) input_buffer)[index], (uint16_t *) &(output_buffer[index]), volume, (TPDMFilter_InitStruct *) &_PDM2PCM_filter[index]); #else PDM_Filter_128_LSB(&((uint8_t *) input_buffer)[index], (uint16_t *) &(output_buffer[index]), volume, (PDMFilter_InitStruct *) &_PDM2PCM_filter[index]); #endif -#ifdef PDM2PCM_AUDIO_DEBUG - _pdm2pcm_audio_signal = 0; -#endif } break; default: error("Decimation factor not supported: it must be either 64 or 128.\r\n"); } +#ifdef PDM2PCM_AUDIO_DEBUG + _pdm2pcm_audio_signal = 0; +#endif return COMPONENT_OK; }