ESPHome  2025.2.0
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
esphome::mixer_speaker::MixerSpeaker Class Reference

#include <mixer_speaker.h>

Inheritance diagram for esphome::mixer_speaker::MixerSpeaker:
esphome::Component

Public Member Functions

void dump_config () override
 
void setup () override
 
void loop () override
 
void add_source_speaker (SourceSpeaker *source_speaker)
 
esp_err_t start (audio::AudioStreamInfo &stream_info)
 Starts the mixer task. More...
 
void stop ()
 
void set_output_channels (uint8_t output_channels)
 
void set_output_speaker (speaker::Speaker *speaker)
 
void set_queue_mode (bool queue_mode)
 
void set_task_stack_in_psram (bool task_stack_in_psram)
 
speaker::Speakerget_output_speaker () const
 
- Public Member Functions inherited from esphome::Component
virtual float get_setup_priority () const
 priority of setup(). More...
 
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...
 

Protected Member Functions

esp_err_t start_task_ ()
 Starts the mixer task after allocating memory for the task stack. More...
 
esp_err_t delete_task_ ()
 If the task is stopped, it sets the task handle to the nullptr and deallocates its stack. More...
 
- 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 copy_frames (const int16_t *input_buffer, audio::AudioStreamInfo input_stream_info, int16_t *output_buffer, audio::AudioStreamInfo output_stream_info, uint32_t frames_to_transfer)
 Copies audio frames from the input buffer to the output buffer taking into account the number of channels in each stream. More...
 
static void mix_audio_samples (const int16_t *primary_buffer, audio::AudioStreamInfo primary_stream_info, const int16_t *secondary_buffer, audio::AudioStreamInfo secondary_stream_info, int16_t *output_buffer, audio::AudioStreamInfo output_stream_info, uint32_t frames_to_mix)
 Mixes the primary and secondary streams taking into account the number of channels in each stream. More...
 
static void audio_mixer_task (void *params)
 

Protected Attributes

EventGroupHandle_t event_group_ {nullptr}
 
std::vector< SourceSpeaker * > source_speakers_
 
speaker::Speakeroutput_speaker_ {nullptr}
 
uint8_t output_channels_
 
bool queue_mode_
 
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}
 
optional< audio::AudioStreamInfoaudio_stream_info_
 
- 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}
 

Detailed Description

Definition at line 120 of file mixer_speaker.h.

Member Function Documentation

◆ add_source_speaker()

void esphome::mixer_speaker::MixerSpeaker::add_source_speaker ( SourceSpeaker source_speaker)
inline

Definition at line 126 of file mixer_speaker.h.

◆ audio_mixer_task()

void esphome::mixer_speaker::MixerSpeaker::audio_mixer_task ( void *  params)
staticprotected

Definition at line 463 of file mixer_speaker.cpp.

◆ copy_frames()

void esphome::mixer_speaker::MixerSpeaker::copy_frames ( const int16_t *  input_buffer,
audio::AudioStreamInfo  input_stream_info,
int16_t *  output_buffer,
audio::AudioStreamInfo  output_stream_info,
uint32_t  frames_to_transfer 
)
staticprotected

Copies audio frames from the input buffer to the output buffer taking into account the number of channels in each stream.

If the output stream has more channels, the input samples are duplicated. If the output stream has less channels, the extra channel input samples are dropped.

Parameters
input_buffer
input_stream_info
output_buffer
output_stream_info
frames_to_transfernumber of frames (consisting of a sample for each channel) to copy from the input buffer

Definition at line 412 of file mixer_speaker.cpp.

◆ delete_task_()

esp_err_t esphome::mixer_speaker::MixerSpeaker::delete_task_ ( )
protected

If the task is stopped, it sets the task handle to the nullptr and deallocates its stack.

Returns
ESP_OK if the task was stopped, ESP_ERR_INVALID_STATE otherwise.

Definition at line 388 of file mixer_speaker.cpp.

◆ dump_config()

void esphome::mixer_speaker::MixerSpeaker::dump_config ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 287 of file mixer_speaker.cpp.

◆ get_output_speaker()

speaker::Speaker* esphome::mixer_speaker::MixerSpeaker::get_output_speaker ( ) const
inline

Definition at line 144 of file mixer_speaker.h.

◆ loop()

void esphome::mixer_speaker::MixerSpeaker::loop ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 302 of file mixer_speaker.cpp.

◆ mix_audio_samples()

void esphome::mixer_speaker::MixerSpeaker::mix_audio_samples ( const int16_t *  primary_buffer,
audio::AudioStreamInfo  primary_stream_info,
const int16_t *  secondary_buffer,
audio::AudioStreamInfo  secondary_stream_info,
int16_t *  output_buffer,
audio::AudioStreamInfo  output_stream_info,
uint32_t  frames_to_mix 
)
staticprotected

Mixes the primary and secondary streams taking into account the number of channels in each stream.

Primary and secondary samples are duplicated or dropped as necessary to ensure the output stream has the configured number of channels. Output samples are clamped to the corresponding int16 min or max values if the mixed sample overflows.

Parameters
primary_buffer(int16_t *) samples buffer for the primary stream
primary_stream_infostream info for the primary stream
secondary_buffer(int16_t *) samples buffer for secondary stream
secondary_stream_infostream info for the secondary stream
output_buffer(int16_t *) buffer for the mixed samples
output_stream_infostream info for the output buffer
frames_to_mixnumber of frames in the primary and secondary buffers to mix together

Definition at line 435 of file mixer_speaker.cpp.

◆ set_output_channels()

void esphome::mixer_speaker::MixerSpeaker::set_output_channels ( uint8_t  output_channels)
inline

Definition at line 139 of file mixer_speaker.h.

◆ set_output_speaker()

void esphome::mixer_speaker::MixerSpeaker::set_output_speaker ( speaker::Speaker speaker)
inline

Definition at line 140 of file mixer_speaker.h.

◆ set_queue_mode()

void esphome::mixer_speaker::MixerSpeaker::set_queue_mode ( bool  queue_mode)
inline

Definition at line 141 of file mixer_speaker.h.

◆ set_task_stack_in_psram()

void esphome::mixer_speaker::MixerSpeaker::set_task_stack_in_psram ( bool  task_stack_in_psram)
inline

Definition at line 142 of file mixer_speaker.h.

◆ setup()

void esphome::mixer_speaker::MixerSpeaker::setup ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 292 of file mixer_speaker.cpp.

◆ start()

esp_err_t esphome::mixer_speaker::MixerSpeaker::start ( audio::AudioStreamInfo stream_info)

Starts the mixer task.

Called by a source speaker giving the current audio stream information

Parameters
stream_infoThe calling source speakers audio stream information
Returns
ESP_ERR_NOT_SUPPORTED if the incoming stream is incompatible due to unsupported bits per sample ESP_ERR_INVALID_ARG if the incoming stream is incompatible to be mixed with the other input audio stream ESP_ERR_NO_MEM if there isn't enough memory for the task's stack ESP_ERR_INVALID_STATE if the task fails to start ESP_OK if the incoming stream is compatible and the mixer task starts

Definition at line 341 of file mixer_speaker.cpp.

◆ start_task_()

esp_err_t esphome::mixer_speaker::MixerSpeaker::start_task_ ( )
protected

Starts the mixer task after allocating memory for the task stack.

Returns
ESP_ERR_NO_MEM if there isn't enough memory for the task's stack ESP_ERR_INVALID_STATE if the task didn't start ESP_OK if successful

Definition at line 361 of file mixer_speaker.cpp.

◆ stop()

void esphome::mixer_speaker::MixerSpeaker::stop ( )

Definition at line 410 of file mixer_speaker.cpp.

Field Documentation

◆ audio_stream_info_

optional<audio::AudioStreamInfo> esphome::mixer_speaker::MixerSpeaker::audio_stream_info_
protected

Definition at line 201 of file mixer_speaker.h.

◆ event_group_

EventGroupHandle_t esphome::mixer_speaker::MixerSpeaker::event_group_ {nullptr}
protected

Definition at line 186 of file mixer_speaker.h.

◆ output_channels_

uint8_t esphome::mixer_speaker::MixerSpeaker::output_channels_
protected

Definition at line 191 of file mixer_speaker.h.

◆ output_speaker_

speaker::Speaker* esphome::mixer_speaker::MixerSpeaker::output_speaker_ {nullptr}
protected

Definition at line 189 of file mixer_speaker.h.

◆ queue_mode_

bool esphome::mixer_speaker::MixerSpeaker::queue_mode_
protected

Definition at line 192 of file mixer_speaker.h.

◆ source_speakers_

std::vector<SourceSpeaker *> esphome::mixer_speaker::MixerSpeaker::source_speakers_
protected

Definition at line 188 of file mixer_speaker.h.

◆ task_created_

bool esphome::mixer_speaker::MixerSpeaker::task_created_ {false}
protected

Definition at line 195 of file mixer_speaker.h.

◆ task_handle_

TaskHandle_t esphome::mixer_speaker::MixerSpeaker::task_handle_ {nullptr}
protected

Definition at line 197 of file mixer_speaker.h.

◆ task_stack_

StaticTask_t esphome::mixer_speaker::MixerSpeaker::task_stack_
protected

Definition at line 198 of file mixer_speaker.h.

◆ task_stack_buffer_

StackType_t* esphome::mixer_speaker::MixerSpeaker::task_stack_buffer_ {nullptr}
protected

Definition at line 199 of file mixer_speaker.h.

◆ task_stack_in_psram_

bool esphome::mixer_speaker::MixerSpeaker::task_stack_in_psram_ {false}
protected

Definition at line 193 of file mixer_speaker.h.


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