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@17:a758b376b018, 2017-05-03 (annotated)
- Committer:
- Davidroid
- Date:
- Wed May 03 16:27:21 2017 +0000
- Revision:
- 17:a758b376b018
- Parent:
- 16:4ab2eac7be21
- Child:
- 20:9952bef19da1
Removing XNucleoCCA02M1_config file.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
davide.aliprandi@st.com | 2:9f389fd8fb2e | 1 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 2 | ****************************************************************************** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 3 | * @file PDM2PCMAudio.h |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 4 | * @author AST / Software Platforms and Cloud |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 5 | * @version V1.0 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 6 | * @date November 10th, 2016 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 7 | * @brief Class header file for the PDM2PCMAudio conversion library. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 8 | ****************************************************************************** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 9 | * @attention |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 10 | * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 12 | * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 13 | * Redistribution and use in source and binary forms, with or without modification, |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 14 | * are permitted provided that the following conditions are met: |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 16 | * this list of conditions and the following disclaimer. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 18 | * this list of conditions and the following disclaimer in the documentation |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 19 | * and/or other materials provided with the distribution. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 21 | * may be used to endorse or promote products derived from this software |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 22 | * without specific prior written permission. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 23 | * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 34 | * |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 35 | ****************************************************************************** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 36 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 37 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 38 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 39 | /* Define to prevent recursive inclusion -------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 40 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 41 | #ifndef __PDM2PCM_AUDIO_CLASS_H |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 42 | #define __PDM2PCM_AUDIO_CLASS_H |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 43 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 44 | |
Davidroid | 17:a758b376b018 | 45 | /* Configuration -------------------------------------------------------------*/ |
Davidroid | 17:a758b376b018 | 46 | |
Davidroid | 17:a758b376b018 | 47 | /** |
Davidroid | 17:a758b376b018 | 48 | * Enable to use the OpenPDM2PCM library. |
Davidroid | 17:a758b376b018 | 49 | */ |
Davidroid | 17:a758b376b018 | 50 | #define USE_OPEN_PDM2PCM_LIBRARY |
Davidroid | 17:a758b376b018 | 51 | |
Davidroid | 17:a758b376b018 | 52 | /** |
Davidroid | 17:a758b376b018 | 53 | * Enable to debug the duration of the PDM2PCM library functions through an |
Davidroid | 17:a758b376b018 | 54 | * oscilloscope. |
Davidroid | 17:a758b376b018 | 55 | */ |
Davidroid | 17:a758b376b018 | 56 | //#define PDM2PCM_AUDIO_DEBUG |
Davidroid | 17:a758b376b018 | 57 | |
Davidroid | 17:a758b376b018 | 58 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 59 | /* Includes ------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 60 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 61 | #include "mbed.h" |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 62 | #include "component_def.h" |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 63 | #ifdef USE_OPEN_PDM2PCM_LIBRARY |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 64 | #include "OpenPDMFilter.h" |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 65 | #else |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 66 | #include "pdm_filter.h" |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 67 | #endif |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 68 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 69 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 70 | /* Definitions ---------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 71 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 72 | #define DEMUX_FILTER_SIZE 128 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 73 | #define DEMUX_FILTER_MASK 0x55 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 74 | #define PDM2PCM_FILTER_SIZE 4 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 75 | #define PDM2PCM_NOGAIN_VOLUME 4 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 76 | #define PDM2PCM_MAX_VOLUME 64 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 77 | #define PDM2PCM_DECIMATION_FACTOR 64 |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 78 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 79 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 80 | /* Classes -------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 81 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 82 | /** PDM2PCMAudio Conversion Library Class. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 83 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 84 | class PDM2PCMAudio |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 85 | { |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 86 | public: |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 87 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 88 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 89 | * @brief Constructor. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 90 | * @param frequency Audio sampling frequency. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 91 | * @param channels Number of audio channels to be recorded. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 92 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 93 | PDM2PCMAudio(uint32_t frequency, uint32_t channels) : |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 94 | _frequency(frequency), |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 95 | _channels(channels) |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 96 | #ifdef PDM2PCM_AUDIO_DEBUG |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 97 | , _pdm2pcm_audio_signal(D9) |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 98 | #endif |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 99 | { |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 100 | /* Enable CRC peripheral to unlock the PDM2PCMAudio library. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 101 | __CRC_CLK_ENABLE(); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 102 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 103 | /* Initializing PDM2PCMAudio Filter. */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 104 | for (uint32_t i = 0; i < _channels; i++) |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 105 | { |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 106 | /* Filter LP and HP Init */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 107 | _PDM2PCM_filter[i].LP_HZ = _frequency / 2; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 108 | _PDM2PCM_filter[i].HP_HZ = 10; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 109 | _PDM2PCM_filter[i].Fs = _frequency; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 110 | _PDM2PCM_filter[i].Out_MicChannels = _channels; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 111 | _PDM2PCM_filter[i].In_MicChannels = _channels; |
davide.aliprandi@st.com | 16:4ab2eac7be21 | 112 | #ifdef USE_OPEN_PDM2PCM_LIBRARY |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 113 | Open_PDM_Filter_Init((TPDMFilter_InitStruct *) &_PDM2PCM_filter[i]); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 114 | #else |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 115 | PDM_Filter_Init((PDMFilter_InitStruct *) &_PDM2PCM_filter[i]); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 116 | #endif |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 117 | } |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 118 | }; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 119 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 120 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 121 | * @brief Converting audio data from PDM to PCM. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 122 | * @param output_buffer Pointer to output PCM buffer data. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 123 | * @param input_buffer Pointer to input PDM buffer data. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 124 | * @param volume Volume level (it must be in the range [0..64]). |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 125 | * @param decimation_factor Decimation factor (it must be either 64 or 128). |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 126 | * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 127 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 128 | status_t convert(int16_t *output_buffer, uint16_t *input_buffer, uint32_t volume, uint32_t decimation_factor); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 129 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 130 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 131 | * @brief Scrambling audio data. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 132 | * @param output_buffer Pointer to output PDM buffer data. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 133 | * @param input_buffer Pointer to input PDM buffer data. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 134 | * @param size Size of the buffers (thay has to be equally sized). |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 135 | * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 136 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 137 | status_t scramble(uint16_t *output_buffer, uint16_t *input_buffer, uint32_t size); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 138 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 139 | /** |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 140 | * @brief Demuxing audio data. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 141 | * @param output_buffer Pointer to output PDM buffer data. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 142 | * @param input_buffer Pointer to input PDM buffer data. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 143 | * @param size Size of the buffers (thay has to be equally sized). |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 144 | * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 145 | */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 146 | status_t demux(uint16_t *output_buffer, uint16_t *input_buffer, uint32_t size); |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 147 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 148 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 149 | protected: |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 150 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 151 | uint32_t _frequency; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 152 | uint32_t _channels; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 153 | #ifdef USE_OPEN_PDM2PCM_LIBRARY |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 154 | TPDMFilter_InitStruct _PDM2PCM_filter[PDM2PCM_FILTER_SIZE]; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 155 | #else |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 156 | PDMFilter_InitStruct _PDM2PCM_filter[PDM2PCM_FILTER_SIZE]; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 157 | #endif |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 158 | static const uint8_t _demux_filter[DEMUX_FILTER_SIZE]; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 159 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 160 | #ifdef PDM2PCM_AUDIO_DEBUG |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 161 | DigitalOut _pdm2pcm_audio_signal; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 162 | #endif |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 163 | }; |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 164 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 165 | #endif /* __PDM2PCM_AUDIO_CLASS_H */ |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 166 | |
davide.aliprandi@st.com | 2:9f389fd8fb2e | 167 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |