BackgroundAudio 1.4.1
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ESP32PDMAudio Class Reference

PDM object with IRQ-based callbacks to a FreeRTOS task, for use with BackgroundAudio. More...

#include <ESP32PDMAudio.h>

Inheritance diagram for ESP32PDMAudio:
Inheritance graph
[legend]
Collaboration diagram for ESP32PDMAudio:
Collaboration graph
[legend]

Public Member Functions

 ESP32PDMAudio (int8_t dout=0)
 Construct ESP32-based PDM object with IRQ-based callbacks to a FreeRTOS task, for use with BackgroundAudio.
 
void setPin (int8_t dout)
 Set the PDM GPIO pin before calling begin
 
bool setFrequency (int freq) override
 Set the sample rate of the PDM interface. Can be called while running.
 
bool begin () override
 Start the PDM interface.
 
- Public Member Functions inherited from ESP32I2SAudio
 ESP32I2SAudio (int8_t bclk=0, int8_t ws=1, int8_t dout=2, int8_t mclk=-1)
 Construct ESP32-based I2S object with IRQ-based callbacks to a FreeRTOS task, for use with BackgroundAudio.
 
void setPins (int8_t bclk, int8_t ws, int8_t dout, int8_t mclk=-1)
 Set the I2S GPIO pins before calling begin
 
void setInverted (bool bclk, bool ws, bool mclk=false)
 Set the I2S GPIO inversions before calling begin
 
bool setBuffers (size_t buffers, size_t bufferWords, int32_t silenceSample=0) override
 Set the size and number of the I2S buffers before begin
 
bool setBitsPerSample (int bps) override
 Set the bits per sample for the I2S output. Only 16-bit supported.
 
bool setFrequency (int freq) override
 Set the sample rate (LRCLK/WS) of the I2S interface. Can be called while running.
 
bool setStereo (bool stereo=true) override
 Set mono or stereo mode. Only stereo supported.
 
bool begin () override
 Start the I2S interface.
 
void _backgroundTask ()
 Background I2S DMA buffer notification task. Tracks number of bytes available to be written.
 
void _saturating_add_available (uint32_t add)
 
void _saturating_sub_available (uint32_t sub)
 
uint32_t frames ()
 Get number of DMA frames(buffers) processed.
 
uint32_t irqs ()
 Get the number of input data shifts processed by decoder since begin
 
uint32_t underflows ()
 Get the number of times the MP3 decoder has underflowed waiting on raw data since begin
 
IRAM_ATTR bool _onSentCB (i2s_chan_handle_t handle, i2s_event_data_t *event)
 Object-based callback for I2S Sent notification.
 
bool end () override
 Stop the I2S device.
 
bool getUnderflow () override
 Determine if there was an underflow since the last time this was called. Cleared on read.
 
void onTransmit (void(*cb)(void *), void *cbData) override
 Set the callback function to be called every DMA buffer completion.
 
size_t write (const uint8_t *buffer, size_t size) override
 Write data to the I2S interface. Not legal from IRQ context. Will not block and may write less than requested.
 
size_t write (uint8_t d) override
 Write single byte to I2S buffers. Not supported.
 
int availableForWrite () override
 Determine the number of frames we can write to the DMA buffers at this instant.
 

Additional Inherited Members

- Static Public Member Functions inherited from ESP32I2SAudio
static IRAM_ATTR bool _onSent (i2s_chan_handle_t handle, i2s_event_data_t *event, void *user_ctx)
 C-language wrapper for I2S Sent event.
 
static void _taskShim (void *pvParameters)
 C-language shim to start the real object's task.
 
- Protected Attributes inherited from ESP32I2SAudio
bool _running
 
int8_t _bclk = 0
 
int8_t _ws = 1
 
int8_t _dout = 2
 
int8_t _mclk = -1
 
bool _bclkInv = false
 
bool _wsInv = false
 
bool _mclkInv = false
 
std::atomic< bool > _underflowed {false}
 
size_t _sampleRate
 
size_t _buffers
 
size_t _bufferWords
 
uint32_t _silenceSample
 
TaskHandle_t _taskHandle = 0
 
void(* _cb )(void *)
 
void * _cbData
 
i2s_chan_handle_t _tx_handle
 
size_t _totalAvailable = 0
 
std::atomic< uint32_t > _available {0}
 
uint32_t _irqs = 0
 
uint32_t _frames = 0
 
std::atomic< uint32_t > _underflows {0}
 

Detailed Description

PDM object with IRQ-based callbacks to a FreeRTOS task, for use with BackgroundAudio.

Constructor & Destructor Documentation

◆ ESP32PDMAudio()

ESP32PDMAudio::ESP32PDMAudio ( int8_t  dout = 0)
inline

Construct ESP32-based PDM object with IRQ-based callbacks to a FreeRTOS task, for use with BackgroundAudio.

Parameters
[in]doutGPIO pin to use as the DOUT from the PDM device

Member Function Documentation

◆ begin()

bool ESP32PDMAudio::begin ( )
inlineoverride

Start the PDM interface.

Allocates an I2S hardware device with the requested number and size of DMA buffers and pinout. A FreeRTOS task is started, awoken from the I2S DMA buffer complete interrupt, to process the reading and writing and keep track of the available sample space for upper layers.

Returns
True on success

◆ setFrequency()

bool ESP32PDMAudio::setFrequency ( int  freq)
inlineoverride

Set the sample rate of the PDM interface. Can be called while running.

Parameters
[in]freqNew sampling frequency in hertz
Returns
True if succeeded

◆ setPin()

void ESP32PDMAudio::setPin ( int8_t  dout)
inline

Set the PDM GPIO pin before calling begin

Parameters
[in]doutGPIO pin to use as the PDM output (connected to the LPF and speaker/amp)

The documentation for this class was generated from the following file: