#include <Microphone_PDM_RTL872x.h>
Static Public Attributes | |
static const size_t | BUFFER_SIZE_SAMPLES = SP_DMA_PAGE_SIZE / 2 |
static const size_t | NUM_BUFFERS = SP_DMA_PAGE_NUM |
Protected Member Functions | |
Microphone_PDM_RTL872x () | |
virtual | ~Microphone_PDM_RTL872x () |
virtual int | init () |
virtual int | uninit () |
virtual int | start () |
virtual int | stop () |
virtual bool | samplesAvailable () const |
virtual bool | copySamples (void *pSamples) |
virtual bool | noCopySamples (std::function< void(void *pSamples, size_t numSamples)>callback) |
size_t | getNumberOfSamples () const |
![]() | |
Microphone_PDM_Base (size_t numSamples) | |
virtual | ~Microphone_PDM_Base () |
void | copySamplesInternal (const int16_t *src, uint8_t *dst) const |
virtual size_t | copySrcIncrement () const |
Protected Attributes | |
bool | running = false |
![]() | |
pin_t | clkPin = A0 |
pin_t | datPin = A1 |
bool | stereoMode = false |
int | sampleRate |
OutputSize | outputSize = OutputSize::SIGNED_16 |
Range | range = Range::RANGE_2048 |
size_t | numSamples |
Additional Inherited Members | |
![]() | |
enum class | OutputSize { UNSIGNED_8 , SIGNED_16 , RAW_SIGNED_16 } |
enum class | Range { RANGE_128 = 0 , RANGE_256 , RANGE_512 , RANGE_1024 , RANGE_2048 , RANGE_4096 , RANGE_8192 , RANGE_16384 , RANGE_32768 } |
![]() | |
int | getSampleRate () const |
MCU-specific implementation of PDM for the RTL872x.
This class is used on the P2 and Photon 2.
You do not instantiate this class directly; it's automatically created when you use the Microphone_PDM singleton.
|
protectedvirtual |
Copy samples from the DMA buffer to your buffer.
pSamples | Pointer to buffer to copy samples to. It must be at least getNumberOfSamples() samples in length. |
The size of the buffer in bytes will depend on the outputSize. If UNSIGNED_8, then it's getNumberOfSamples() bytes. If SIGNED_16 or RAW_SIGNED_16, then it's 2 * getNumberOfSamples().
You can skip calling samplesAvailable() and just call copySamples which will return false in the same cases where samplesAvailable() would have returned false.
Reimplemented in Microphone_PDM.
|
inlineprotected |
Return the number of int16_t samples that copySamples will copy.
You will never get a partial buffer of data. The number of samples is a constant that is determined by the MCU type at compile time and does not change.
On the RTL872x, it's 256 samples (512 bytes). It's smaller because the are 4 buffers instead of the 2 buffers used on the nRF52, and the optimal DMA size on the RTL872x is 512 bytes.
|
protectedvirtual |
Initialize the PDM module.
This is often done from setup(). You can defer it until you're ready to sample if desired, calling right before start().
Reimplemented in Microphone_PDM.
|
protectedvirtual |
Alternative API to get samples.
callback | Callback function or lambda |
Alternative API that does not require a buffer to be passed in. You should only use this if you can consume the buffer immediately without blocking.
The callback function or lamba has this prototype:
void callback(void *pSamples, size_t numSamples)
It will be called with a pointer to the samples (in the DMA buffer) and the number of samples (not bytes!) of data. The number of bytes will vary depending on the outputSize.
You can skip calling samplesAvailable() and just call noCopySamples which will return false in the same cases where samplesAvailable() would have returned false.
Reimplemented in Microphone_PDM.
|
protectedvirtual |
Return true if there is data available to be copied using copySamples.
Reimplemented in Microphone_PDM.
|
protectedvirtual |
Start sampling.
Reimplemented in Microphone_PDM.
|
protectedvirtual |
Stop sampling.
Reimplemented in Microphone_PDM.
|
inlineprotectedvirtual |
Uninitialize the PDM module.
You normally will just initialize it once and only start and stop it as necessary, however you can completely uninitialize it if desired. The clkPin will be reset to INPUT mode.
Reimplemented in Microphone_PDM.