1 /** 2 ******************************************************************************* 3 * @file OpenPDMFilter.h 4 * @author CL 5 * @version V1.0.0 6 * @date 9-September-2015 7 * @brief Header file for Open PDM audio software decoding Library. 8 * This Library is used to decode and reconstruct the audio signal 9 * produced by ST MEMS microphone (MP45Dxxx, MP34Dxxx). 10 ******************************************************************************* 11 * @attention 12 * 13 * <h2><center>© COPYRIGHT 2018 STMicroelectronics</center></h2> 14 * 15 * Licensed under the Apache License, Version 2.0 (the "License"); 16 * you may not use this file except in compliance with the License. 17 * You may obtain a copy of the License at 18 * 19 * http://www.apache.org/licenses/LICENSE-2.0 20 * 21 * Unless required by applicable law or agreed to in writing, software 22 * distributed under the License is distributed on an "AS IS" BASIS, 23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 * See the License for the specific language governing permissions and 25 * limitations under the License. 26 ******************************************************************************* 27 */ 28 29 30 /* Define to prevent recursive inclusion -------------------------------------*/ 31 32 #ifndef __OPENPDMFILTER_H 33 #define __OPENPDMFILTER_H 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 40 /* Includes ------------------------------------------------------------------*/ 41 42 #include <stdint.h> 43 44 45 /* Definitions ---------------------------------------------------------------*/ 46 47 /* 48 * Enable to use a Look-Up Table to improve performances while using more FLASH 49 * and RAM memory. 50 * Note: Without Look-Up Table up to stereo@16KHz configuration is supported. 51 */ 52 #define USE_LUT 53 54 #define SINCN 3 55 #define DECIMATION_MAX 128 56 #define FILTER_GAIN 16 57 58 #define HTONS(A) ((((uint16_t)(A) & 0xff00) >> 8) | \ 59 (((uint16_t)(A) & 0x00ff) << 8)) 60 #define RoundDiv(a, b) (((a)>0)?(((a)+(b)/2)/(b)):(((a)-(b)/2)/(b))) 61 #define SaturaLH(N, L, H) (((N)<(L))?(L):(((N)>(H))?(H):(N))) 62 63 64 /* Types ---------------------------------------------------------------------*/ 65 66 typedef struct { 67 /* Public */ 68 float LP_HZ; 69 float HP_HZ; 70 uint16_t Fs; 71 uint8_t In_MicChannels; 72 uint8_t Out_MicChannels; 73 uint8_t Decimation; 74 uint8_t MaxVolume; 75 /* Private */ 76 uint32_t Coef[SINCN]; 77 uint16_t FilterLen; 78 int64_t OldOut, OldIn, OldZ; 79 uint16_t LP_ALFA; 80 uint16_t HP_ALFA; 81 uint16_t bit[5]; 82 uint16_t byte; 83 } TPDMFilter_InitStruct; 84 85 86 /* Exported functions ------------------------------------------------------- */ 87 88 void Open_PDM_Filter_Init(TPDMFilter_InitStruct *init_struct); 89 void Open_PDM_Filter_64(uint8_t* data, uint16_t* data_out, uint16_t mic_gain, TPDMFilter_InitStruct *init_struct); 90 void Open_PDM_Filter_128(uint8_t* data, uint16_t* data_out, uint16_t mic_gain, TPDMFilter_InitStruct *init_struct); 91 92 #ifdef __cplusplus 93 } 94 #endif 95 96 #endif // __OPENPDMFILTER_H 97 98 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 99