Il y avait des problèmes dans la libraire...
Dependencies: ST_FREQUENCY_DIVIDER ST_I2S USBDEVICE
Fork of X_NUCLEO_CCA02M1 by
BSP/PDM2PCMAudio.h
- Committer:
- Davidroid
- Date:
- 2017-05-05
- Revision:
- 20:9952bef19da1
- Parent:
- 17:a758b376b018
File content as of revision 20:9952bef19da1:
/** ****************************************************************************** * @file PDM2PCMAudio.h * @author AST / Software Platforms and Cloud * @version V1.0 * @date November 10th, 2016 * @brief Class header file for the PDM2PCMAudio conversion library. ****************************************************************************** * @attention * * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __PDM2PCM_AUDIO_CLASS_H #define __PDM2PCM_AUDIO_CLASS_H /* Configuration -------------------------------------------------------------*/ /** * Enable to use the OpenPDM2PCM library. */ #define USE_OPEN_PDM2PCM_LIBRARY /** * Enable to debug the duration of the PDM2PCM library functions through an * oscilloscope. */ //#define PDM2PCM_AUDIO_DEBUG /* Includes ------------------------------------------------------------------*/ #include "mbed.h" #include "component_def.h" #ifdef USE_OPEN_PDM2PCM_LIBRARY #include "OpenPDMFilter.h" #else #include "pdm_filter.h" #endif /* 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 /* Classes -------------------------------------------------------------------*/ /** PDM2PCMAudio Conversion Library Class. */ class PDM2PCMAudio { public: /** * @brief Constructor. * @param frequency Audio sampling frequency. * @param channels Number of audio channels to be recorded. */ PDM2PCMAudio(uint32_t frequency, uint32_t channels) : _frequency(frequency), _channels(channels) #ifdef PDM2PCM_AUDIO_DEBUG , _pdm2pcm_audio_signal(D9) #endif { /* 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++) { /* Filter LP and HP Init */ _PDM2PCM_filter[i].LP_HZ = _frequency / 2; _PDM2PCM_filter[i].HP_HZ = 10; _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 PDM_Filter_Init((PDMFilter_InitStruct *) &_PDM2PCM_filter[i]); #endif } }; /** * @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. * @param output_buffer Pointer to output PDM buffer data. * @param input_buffer Pointer to input PDM buffer data. * @param size Size of the buffers (thay has to be equally sized). * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. */ status_t scramble(uint16_t *output_buffer, uint16_t *input_buffer, uint32_t size); /** * @brief Demuxing audio data. * @param output_buffer Pointer to output PDM buffer data. * @param input_buffer Pointer to input PDM buffer data. * @param size Size of the buffers (thay has to be equally sized). * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. */ status_t demux(uint16_t *output_buffer, uint16_t *input_buffer, uint32_t size); protected: uint32_t _frequency; uint32_t _channels; uint32_t _decimation_factor; #ifdef USE_OPEN_PDM2PCM_LIBRARY TPDMFilter_InitStruct _PDM2PCM_filter[PDM2PCM_FILTER_SIZE]; #else PDMFilter_InitStruct _PDM2PCM_filter[PDM2PCM_FILTER_SIZE]; #endif static const uint8_t _demux_filter[DEMUX_FILTER_SIZE]; #ifdef PDM2PCM_AUDIO_DEBUG DigitalOut _pdm2pcm_audio_signal; #endif }; #endif /* __PDM2PCM_AUDIO_CLASS_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/