A class to control MEMS microphone. More...
#include <Microphone.h>
Public Member Functions | |
| int | begin () |
| Initialize the PDM MEMS microphone. | |
| int | getSamples (int16_t *buffer, size_t samples) |
| Read PCM samples from the microphone buffer. | |
| Microphone (uint8_t dataPin, uint8_t clkPin) | |
| Construct a new Microphone object. | |
| void | setCallback (pdm_samples_ready_handler_t handler) |
| Set a callback function to be called when new samples are ready. | |
| int | start () |
| Start capturing audio samples. | |
| void | stop () |
| Stop capturing audio samples. | |
A class to control MEMS microphone.
This class provides control for the PDM MEMS microphone connected via PIO.
**Microphone (PDM_CLK — GPIO 15, PDM_DATA — GPIO 16)**
Default microphone parameters:
| Setting | Value |
|---|---|
| Data pin | PDM_DATA (GPIO 16) |
| Clock pin | PDM_CLK (GPIO 15) |
| Sample rate | 16 kHz |
| Buffer size | 256 samples |
| Microphone::Microphone | ( | uint8_t | dataPin, |
| uint8_t | clkPin ) |
Construct a new Microphone object.
| dataPin | GPIO pin connected to the PDM data signal (default: GPIO 16) |
| clkPin | GPIO pin connected to the PDM clock signal (default: GPIO 15) |
| int Microphone::begin | ( | ) |
Initialize the PDM MEMS microphone.
Configures the microphone using PIO to capture PDM data and the OpenPDM2PCM library to transform it into PCM samples.
Implementation is based on the official [Arm Developer Ecosystem microphone library for Pico] (https://github.com/ArmDeveloperEcosystem/microphone-library-for-pico/tree/main).
Default parameters:
| int Microphone::getSamples | ( | int16_t * | buffer, |
| size_t | samples ) |
Read PCM samples from the microphone buffer.
| buffer | Pointer to an array where the samples will be stored. |
| samples | Number of samples to read. |
| void Microphone::setCallback | ( | pdm_samples_ready_handler_t | handler | ) |
Set a callback function to be called when new samples are ready.
| handler | Callback function of type ::pdm_samples_ready_handler_t. |
| int Microphone::start | ( | ) |
Start capturing audio samples.
| void Microphone::stop | ( | ) |
Stop capturing audio samples.