Arduino TKJHAT
Arduino library for Pico HAT extension board
Loading...
Searching...
No Matches
OpenPDMFilter.h
Go to the documentation of this file.
1
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#ifdef PICO_BUILD
57#define FILTER_GAIN Param->Gain
58#else
59#define FILTER_GAIN 16
60#endif
61
62#define HTONS(A) ((((uint16_t)(A) & 0xff00) >> 8) | \
63 (((uint16_t)(A) & 0x00ff) << 8))
64#define RoundDiv(a, b) (((a)>0)?(((a)+(b)/2)/(b)):(((a)-(b)/2)/(b)))
65#define SaturaLH(N, L, H) (((N)<(L))?(L):(((N)>(H))?(H):(N)))
66
67
68/* Types ---------------------------------------------------------------------*/
69
70typedef struct {
71 /* Public */
72 float LP_HZ;
73 float HP_HZ;
74 uint16_t Fs;
75 uint8_t In_MicChannels;
76 uint8_t Out_MicChannels;
77 uint8_t Decimation;
78 uint8_t MaxVolume;
79#ifdef PICO_BUILD
80 uint8_t Gain;
81#endif
82 /* Private */
83 uint32_t Coef[SINCN];
84 uint16_t FilterLen;
85 int64_t OldOut, OldIn, OldZ;
86 uint16_t LP_ALFA;
87 uint16_t HP_ALFA;
88 uint16_t bit[5];
89 uint16_t byte;
90} TPDMFilter_InitStruct;
91
92
93/* Exported functions ------------------------------------------------------- */
94
95void Open_PDM_Filter_Init(TPDMFilter_InitStruct *init_struct);
96void Open_PDM_Filter_64(uint8_t* data, uint16_t* data_out, uint16_t mic_gain, TPDMFilter_InitStruct *init_struct);
97void Open_PDM_Filter_128(uint8_t* data, uint16_t* data_out, uint16_t mic_gain, TPDMFilter_InitStruct *init_struct);
98
99#ifdef __cplusplus
100}
101#endif
102
103#endif // __OPENPDMFILTER_H
104
105/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
106