ESPHome  2025.2.0
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
esphome::resampler::ResamplerSpeaker Class Reference

#include <resampler_speaker.h>

Inheritance diagram for esphome::resampler::ResamplerSpeaker:
esphome::Component esphome::speaker::Speaker

Public Member Functions

float get_setup_priority () const override
 
void setup () override
 
void loop () override
 
size_t play (const uint8_t *data, size_t length, TickType_t ticks_to_wait) override
 
size_t play (const uint8_t *data, size_t length) override
 
void start () override
 
void stop () override
 
void finish () override
 
void set_pause_state (bool pause_state) override
 
bool get_pause_state () const override
 
bool has_buffered_data () const override
 
void set_mute_state (bool mute_state) override
 Mute state changes are passed to the parent's output speaker. More...
 
void set_volume (float volume) override
 Volume state changes are passed to the parent's output speaker. More...
 
void set_output_speaker (speaker::Speaker *speaker)
 
void set_task_stack_in_psram (bool task_stack_in_psram)
 
void set_target_bits_per_sample (uint8_t target_bits_per_sample)
 
void set_target_sample_rate (uint32_t target_sample_rate)
 
void set_filters (uint16_t filters)
 
void set_taps (uint16_t taps)
 
void set_buffer_duration (uint32_t buffer_duration_ms)
 
- Public Member Functions inherited from esphome::Component
virtual void dump_config ()
 
float get_actual_setup_priority () const
 
void set_setup_priority (float priority)
 
virtual float get_loop_priority () const
 priority of loop(). More...
 
void call ()
 
virtual void on_shutdown ()
 
virtual void on_safe_shutdown ()
 
uint32_t get_component_state () const
 
virtual void mark_failed ()
 Mark this component as failed. More...
 
bool is_failed () const
 
bool is_ready () const
 
virtual bool can_proceed ()
 
bool status_has_warning () const
 
bool status_has_error () const
 
void status_set_warning (const char *message="unspecified")
 
void status_set_error (const char *message="unspecified")
 
void status_clear_warning ()
 
void status_clear_error ()
 
void status_momentary_warning (const std::string &name, uint32_t length=5000)
 
void status_momentary_error (const std::string &name, uint32_t length=5000)
 
bool has_overridden_loop () const
 
void set_component_source (const char *source)
 Set where this component was loaded from for some debug messages. More...
 
const char * get_component_source () const
 Get the integration where this component was declared as a string. More...
 
- Public Member Functions inherited from esphome::speaker::Speaker
size_t play (const std::vector< uint8_t > &data)
 
bool is_running () const
 
bool is_stopped () const
 
float get_volume ()
 
bool get_mute_state ()
 
void set_audio_dac (audio_dac::AudioDac *audio_dac)
 
void set_audio_stream_info (const audio::AudioStreamInfo &audio_stream_info)
 
audio::AudioStreamInfoget_audio_stream_info ()
 
void add_audio_output_callback (std::function< void(uint32_t, uint32_t, uint32_t, uint32_t)> &&callback)
 Callback function for sending the duration of the audio written to the speaker since the last callback. More...
 

Protected Member Functions

esp_err_t start_ ()
 Starts the output speaker after setting the resampled stream info. More...
 
esp_err_t start_task_ ()
 Starts the resampler task after allocating the task stack. More...
 
void stop_ ()
 Stops the output speaker. If the resampling task is running, it sends the stop command. More...
 
esp_err_t delete_task_ ()
 Deallocates the task stack and resets the pointers. More...
 
bool requires_resampling_ () const
 
- Protected Member Functions inherited from esphome::Component
virtual void call_loop ()
 
virtual void call_setup ()
 
virtual void call_dump_config ()
 
void set_interval (const std::string &name, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a unique name. More...
 
void set_interval (uint32_t interval, std::function< void()> &&f)
 
bool cancel_interval (const std::string &name)
 Cancel an interval function. More...
 
void set_retry (const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
 Set an retry function with a unique name. More...
 
void set_retry (uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
 
bool cancel_retry (const std::string &name)
 Cancel a retry function. More...
 
void set_timeout (const std::string &name, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a unique name. More...
 
void set_timeout (uint32_t timeout, std::function< void()> &&f)
 
bool cancel_timeout (const std::string &name)
 Cancel a timeout function. More...
 
void defer (const std::string &name, std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
void defer (std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
bool cancel_defer (const std::string &name)
 Cancel a defer callback using the specified name, name must not be empty. More...
 

Static Protected Member Functions

static void resample_task (void *params)
 

Protected Attributes

EventGroupHandle_t event_group_ {nullptr}
 
std::weak_ptr< RingBufferring_buffer_
 
speaker::Speakeroutput_speaker_ {nullptr}
 
bool task_stack_in_psram_ {false}
 
bool task_created_ {false}
 
TaskHandle_t task_handle_ {nullptr}
 
StaticTask_t task_stack_
 
StackType_t * task_stack_buffer_ {nullptr}
 
audio::AudioStreamInfo target_stream_info_
 
uint16_t taps_
 
uint16_t filters_
 
uint8_t target_bits_per_sample_
 
uint32_t target_sample_rate_
 
uint32_t buffer_duration_ms_
 
int32_t playback_differential_ms_ {0}
 
- Protected Attributes inherited from esphome::Component
uint32_t component_state_ {0x0000}
 State of this component. More...
 
float setup_priority_override_ {NAN}
 
const char * component_source_ {nullptr}
 
- Protected Attributes inherited from esphome::speaker::Speaker
State state_ {STATE_STOPPED}
 
audio::AudioStreamInfo audio_stream_info_
 
float volume_ {1.0f}
 
bool mute_state_ {false}
 
audio_dac::AudioDacaudio_dac_ {nullptr}
 
CallbackManager< void(uint32_t, uint32_t, uint32_t, uint32_t)> audio_output_callback_ {}
 

Detailed Description

Definition at line 17 of file resampler_speaker.h.

Member Function Documentation

◆ delete_task_()

esp_err_t esphome::resampler::ResamplerSpeaker::delete_task_ ( )
protected

Deallocates the task stack and resets the pointers.

Returns
ESP_OK if successful ESP_ERR_INVALID_STATE if the task hasn't stopped itself

Definition at line 203 of file resampler_speaker.cpp.

◆ finish()

void esphome::resampler::ResamplerSpeaker::finish ( )
overridevirtual

Reimplemented from esphome::speaker::Speaker.

Definition at line 225 of file resampler_speaker.cpp.

◆ get_pause_state()

bool esphome::resampler::ResamplerSpeaker::get_pause_state ( ) const
inlineoverridevirtual

Reimplemented from esphome::speaker::Speaker.

Definition at line 31 of file resampler_speaker.h.

◆ get_setup_priority()

float esphome::resampler::ResamplerSpeaker::get_setup_priority ( ) const
inlineoverridevirtual

Reimplemented from esphome::Component.

Definition at line 19 of file resampler_speaker.h.

◆ has_buffered_data()

bool esphome::resampler::ResamplerSpeaker::has_buffered_data ( ) const
overridevirtual

Implements esphome::speaker::Speaker.

Definition at line 227 of file resampler_speaker.cpp.

◆ loop()

void esphome::resampler::ResamplerSpeaker::loop ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 55 of file resampler_speaker.cpp.

◆ play() [1/2]

size_t esphome::resampler::ResamplerSpeaker::play ( const uint8_t *  data,
size_t  length,
TickType_t  ticks_to_wait 
)
overridevirtual

Reimplemented from esphome::speaker::Speaker.

Definition at line 132 of file resampler_speaker.cpp.

◆ play() [2/2]

size_t esphome::resampler::ResamplerSpeaker::play ( const uint8_t *  data,
size_t  length 
)
inlineoverridevirtual

Implements esphome::speaker::Speaker.

Definition at line 24 of file resampler_speaker.h.

◆ requires_resampling_()

bool esphome::resampler::ResamplerSpeaker::requires_resampling_ ( ) const
inlineprotected

Definition at line 245 of file resampler_speaker.cpp.

◆ resample_task()

void esphome::resampler::ResamplerSpeaker::resample_task ( void *  params)
staticprotected

Definition at line 250 of file resampler_speaker.cpp.

◆ set_buffer_duration()

void esphome::resampler::ResamplerSpeaker::set_buffer_duration ( uint32_t  buffer_duration_ms)
inline

Definition at line 52 of file resampler_speaker.h.

◆ set_filters()

void esphome::resampler::ResamplerSpeaker::set_filters ( uint16_t  filters)
inline

Definition at line 49 of file resampler_speaker.h.

◆ set_mute_state()

void esphome::resampler::ResamplerSpeaker::set_mute_state ( bool  mute_state)
overridevirtual

Mute state changes are passed to the parent's output speaker.

Reimplemented from esphome::speaker::Speaker.

Definition at line 235 of file resampler_speaker.cpp.

◆ set_output_speaker()

void esphome::resampler::ResamplerSpeaker::set_output_speaker ( speaker::Speaker speaker)
inline

Definition at line 41 of file resampler_speaker.h.

◆ set_pause_state()

void esphome::resampler::ResamplerSpeaker::set_pause_state ( bool  pause_state)
inlineoverridevirtual

Reimplemented from esphome::speaker::Speaker.

Definition at line 30 of file resampler_speaker.h.

◆ set_taps()

void esphome::resampler::ResamplerSpeaker::set_taps ( uint16_t  taps)
inline

Definition at line 50 of file resampler_speaker.h.

◆ set_target_bits_per_sample()

void esphome::resampler::ResamplerSpeaker::set_target_bits_per_sample ( uint8_t  target_bits_per_sample)
inline

Definition at line 44 of file resampler_speaker.h.

◆ set_target_sample_rate()

void esphome::resampler::ResamplerSpeaker::set_target_sample_rate ( uint32_t  target_sample_rate)
inline

Definition at line 47 of file resampler_speaker.h.

◆ set_task_stack_in_psram()

void esphome::resampler::ResamplerSpeaker::set_task_stack_in_psram ( bool  task_stack_in_psram)
inline

Definition at line 42 of file resampler_speaker.h.

◆ set_volume()

void esphome::resampler::ResamplerSpeaker::set_volume ( float  volume)
overridevirtual

Volume state changes are passed to the parent's output speaker.

Reimplemented from esphome::speaker::Speaker.

Definition at line 240 of file resampler_speaker.cpp.

◆ setup()

void esphome::resampler::ResamplerSpeaker::setup ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 37 of file resampler_speaker.cpp.

◆ start()

void esphome::resampler::ResamplerSpeaker::start ( )
overridevirtual

Implements esphome::speaker::Speaker.

Definition at line 150 of file resampler_speaker.cpp.

◆ start_()

esp_err_t esphome::resampler::ResamplerSpeaker::start_ ( )
protected

Starts the output speaker after setting the resampled stream info.

If resampling is required, it starts the task.

Returns
ESP_OK if resampling is required return value of start_task_() if resampling is required

Definition at line 152 of file resampler_speaker.cpp.

◆ start_task_()

esp_err_t esphome::resampler::ResamplerSpeaker::start_task_ ( )
protected

Starts the resampler task after allocating the task stack.

Returns
ESP_OK if successful, ESP_ERR_NO_MEM if the task stack couldn't be allocated ESP_ERR_INVALID_STATE if the task wasn't created

Definition at line 167 of file resampler_speaker.cpp.

◆ stop()

void esphome::resampler::ResamplerSpeaker::stop ( )
overridevirtual

Implements esphome::speaker::Speaker.

Definition at line 194 of file resampler_speaker.cpp.

◆ stop_()

void esphome::resampler::ResamplerSpeaker::stop_ ( )
protected

Stops the output speaker. If the resampling task is running, it sends the stop command.

Definition at line 196 of file resampler_speaker.cpp.

Field Documentation

◆ buffer_duration_ms_

uint32_t esphome::resampler::ResamplerSpeaker::buffer_duration_ms_
protected

Definition at line 99 of file resampler_speaker.h.

◆ event_group_

EventGroupHandle_t esphome::resampler::ResamplerSpeaker::event_group_ {nullptr}
protected

Definition at line 78 of file resampler_speaker.h.

◆ filters_

uint16_t esphome::resampler::ResamplerSpeaker::filters_
protected

Definition at line 94 of file resampler_speaker.h.

◆ output_speaker_

speaker::Speaker* esphome::resampler::ResamplerSpeaker::output_speaker_ {nullptr}
protected

Definition at line 82 of file resampler_speaker.h.

◆ playback_differential_ms_

int32_t esphome::resampler::ResamplerSpeaker::playback_differential_ms_ {0}
protected

Definition at line 101 of file resampler_speaker.h.

◆ ring_buffer_

std::weak_ptr<RingBuffer> esphome::resampler::ResamplerSpeaker::ring_buffer_
protected

Definition at line 80 of file resampler_speaker.h.

◆ taps_

uint16_t esphome::resampler::ResamplerSpeaker::taps_
protected

Definition at line 93 of file resampler_speaker.h.

◆ target_bits_per_sample_

uint8_t esphome::resampler::ResamplerSpeaker::target_bits_per_sample_
protected

Definition at line 96 of file resampler_speaker.h.

◆ target_sample_rate_

uint32_t esphome::resampler::ResamplerSpeaker::target_sample_rate_
protected

Definition at line 97 of file resampler_speaker.h.

◆ target_stream_info_

audio::AudioStreamInfo esphome::resampler::ResamplerSpeaker::target_stream_info_
protected

Definition at line 91 of file resampler_speaker.h.

◆ task_created_

bool esphome::resampler::ResamplerSpeaker::task_created_ {false}
protected

Definition at line 85 of file resampler_speaker.h.

◆ task_handle_

TaskHandle_t esphome::resampler::ResamplerSpeaker::task_handle_ {nullptr}
protected

Definition at line 87 of file resampler_speaker.h.

◆ task_stack_

StaticTask_t esphome::resampler::ResamplerSpeaker::task_stack_
protected

Definition at line 88 of file resampler_speaker.h.

◆ task_stack_buffer_

StackType_t* esphome::resampler::ResamplerSpeaker::task_stack_buffer_ {nullptr}
protected

Definition at line 89 of file resampler_speaker.h.

◆ task_stack_in_psram_

bool esphome::resampler::ResamplerSpeaker::task_stack_in_psram_ {false}
protected

Definition at line 84 of file resampler_speaker.h.


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