Decimation of the 1-bit stream of a PDM microphone to 16-bit PCM.
More...
Decimation of the 1-bit stream of a PDM microphone to 16-bit PCM.
Bytes of eight PDM samples go through a fifth-order sinc filter decimating by 8, then an equiripple low-pass FIR decimating by 8 or 16, flat to 0.4 times the output rate and at least 70 dB down from 0.6 times it. A high-pass filter at 1/800 of the output rate, 20 Hz at 16 kHz, then removes the offset of the microphone and its drift as it starts, and a gain of 0 to PBL_PDM_GAIN_MAX_MDB brings speech up from the low levels microphones give it. Without gain, a stream of only ones gives full scale.
One filter runs one microphone. The oldest of the eight samples of a byte is its most significant bit. The first samples are silence: until the FIR has seen as many as it has taps, and for the time the microphone takes to settle once clocked.
Filter of one microphone.
Definition pdm.h:45
int pbl_pdm_filter_init(struct pbl_pdm_filter *filter, uint32_t decimation, uint32_t settle)
Initialize a filter, without gain.
void pbl_pdm_filter_set_gain(struct pbl_pdm_filter *filter, int32_t gain_mdb)
Set the gain.
size_t pbl_pdm_filter_run(struct pbl_pdm_filter *filter, const uint8_t *in, size_t len, size_t in_stride, int16_t *out, size_t out_stride)
Filter PDM bytes.
◆ pbl_pdm_filter
Filter of one microphone.
◆ PBL_PDM_GAIN_MAX_MDB
| #define PBL_PDM_GAIN_MAX_MDB 42000 |
◆ pbl_pdm_filter_init()
| int pbl_pdm_filter_init |
( |
struct pbl_pdm_filter * |
filter, |
|
|
uint32_t |
decimation, |
|
|
uint32_t |
settle |
|
) |
| |
Initialize a filter, without gain.
- Parameters
-
| filter | Filter. |
| decimation | PDM samples per output sample: 64 or 128. |
| settle | Output samples to silence while the microphone settles. |
- Returns
- 0, or
-EINVAL for another decimation.
◆ pbl_pdm_filter_run()
| size_t pbl_pdm_filter_run |
( |
struct pbl_pdm_filter * |
filter, |
|
|
const uint8_t * |
in, |
|
|
size_t |
len, |
|
|
size_t |
in_stride, |
|
|
int16_t * |
out, |
|
|
size_t |
out_stride |
|
) |
| |
Filter PDM bytes.
- Parameters
-
| filter | Filter. |
| in | First byte of PDM samples. |
| len | Number of bytes. |
| in_stride | Distance between bytes, in bytes, as for the bytes of one microphone of several interleaved. |
| out | Where to write the samples. |
| out_stride | Distance between samples, in samples, as for one channel of several. |
- Returns
- Number of samples written:
len times 8 divided by the decimation, give or take one for the bytes the previous call left over.
◆ pbl_pdm_filter_set_gain()
| void pbl_pdm_filter_set_gain |
( |
struct pbl_pdm_filter * |
filter, |
|
|
int32_t |
gain_mdb |
|
) |
| |