|
ESPHome 2026.11.0-dev
|
#include <usb_audio_speaker.h>
Public Member Functions | |
| USBAudioSpeaker (const audio::AudioStreamInfo &stream_info, uint32_t buffer_size, uint32_t write_timeout_ms) | |
| void | setup () override |
| void | dump_config () override |
| void | loop () override |
| void | start () override |
| void | stop () override |
| void | finish () 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 |
| bool | has_buffered_data () const override |
| void | set_volume (float volume) override |
| void | set_mute_state (bool mute_state) override |
| audio::AudioStreamInfo | get_usb_stream_info () override |
| void | on_stream_state (StreamEvent event) override |
| bool | stream_idle () const override |
| void | on_transfer_taken () override |
Public Member Functions inherited from esphome::speaker::Speaker | |
| size_t | play (const std::vector< uint8_t > &data) |
| virtual void | set_pause_state (bool pause_state) |
| virtual bool | get_pause_state () const |
| bool | is_running () const |
| bool | is_stopped () const |
| virtual float | get_volume () |
| virtual 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::AudioStreamInfo & | get_audio_stream_info () |
| template<typename F > | |
| void | add_audio_output_callback (F &&callback) |
| Callback function for sending the duration of the audio written to the speaker since the last callback. | |
Public Member Functions inherited from esphome::Component | |
| virtual float | get_setup_priority () const |
| priority of setup(). | |
| float | get_actual_setup_priority () const |
| void | set_setup_priority (float priority) |
| void | call () |
| virtual void | on_shutdown () |
| virtual void | on_safe_shutdown () |
| virtual bool | teardown () |
| Called during teardown to allow component to gracefully finish operations. | |
| virtual void | on_powerdown () |
| Called after teardown is complete to power down hardware. | |
| uint8_t | get_component_state () const |
| void | reset_to_construction_state () |
| Reset this component back to the construction state to allow setup to run again. | |
| bool | is_in_loop_state () const |
| Check if this component has completed setup and is in the loop state. | |
| bool | is_idle () const |
| Check if this component is idle. | |
| void | mark_failed () |
| Mark this component as failed. | |
| void | mark_failed (const LogString *message) |
| void | disable_loop () |
| Disable this component's loop. | |
| void | enable_loop () |
| Enable this component's loop. | |
| void | enable_loop_soon_any_context () |
| Thread and ISR-safe version of enable_loop() that can be called from any context. | |
| 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 () |
| void | status_set_warning (const char *message) |
| void | status_set_warning (const LogString *message) |
| bool | status_comm_result (bool ok) |
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok. | |
| bool | status_comm_result (bool ok, const LogString *message) |
| void | status_set_error () |
| void | status_set_error (const LogString *message) |
| void | status_clear_warning () |
| void | status_clear_error () |
| ESPDEPRECATED ("Use status_momentary_warning() without a name. Removed in 2027.5.0", "2026.11.0") void status_momentary_warning(const char *name | |
| void | status_momentary_warning (uint32_t length=5000) |
Set warning status flag and clear it after length ms. | |
| void | status_momentary_warning (const LogString *message, uint32_t length=5000) |
| ESPDEPRECATED ("Use status_momentary_error() without a name. Removed in 2027.5.0", "2026.11.0") void status_momentary_error(const char *name | |
| void | status_momentary_error (uint32_t length=5000) |
Set error status flag and clear it after length ms. | |
| void | status_momentary_error (const LogString *message, uint32_t length=5000) |
| bool | has_overridden_loop () const |
| const LogString * | get_component_log_str () const ESPHOME_ALWAYS_INLINE |
| Get the integration where this component was declared as a LogString for logging. | |
| bool | should_warn_of_blocking (uint32_t blocking_time, uint32_t &threshold_ms_out) |
Public Member Functions inherited from esphome::Parented< USBAudioComponent > | |
| Parented () | |
| Parented (USBAudioComponent *parent) | |
| USBAudioComponent * | get_parent () const |
| Get the parent of this object. | |
| void | set_parent (USBAudioComponent *parent) |
| Set the parent of this object. | |
Public Member Functions inherited from esphome::usb_audio::USBAudioStream | |
| USBAudioStream (uint32_t buffer_size) | |
| uint32_t | get_buffer_size () const |
Protected Member Functions | |
| void | request_ (uint8_t set, uint8_t clear) |
| void | deliver_reports_ () |
| void | begin_finishing_ () |
| void | stop_ () |
| size_t | play_internal_ (const uint8_t *data, size_t length, uint32_t budget_ms) |
| void | pad_with_silence_ () |
| Write silence until a whole USB transfer is padded, so the driver sends a final partial transfer. | |
| esp_err_t | write_ (const uint8_t *data, size_t length, uint32_t timeout_ms, bool padding) |
| Write to the driver, counting the bytes in ring_bytes_ (and in ring_padding_ for silence padding). | |
| size_t | ring_room_ () const |
| Bytes that can be written without filling the driver's ring buffer past buffer_size_. | |
| bool | has_buffered_data_ (int64_t now_us) const |
Protected Member Functions inherited from esphome::speaker::Speaker | |
| bool | is_silent_ () const |
| Whether the output should be silent: muted, or the volume is effectively zero. | |
| void | apply_audio_dac_mute_ () |
| Uses the audio dac's mute as the silence mechanism, since a dac's minimum volume is often audible. | |
Protected Member Functions inherited from esphome::Component | |
| friend | void::setup () |
| friend | void::original_setup () |
| void | set_component_source_ (uint8_t index) |
| Set where this component was loaded from for some debug messages. | |
| virtual void | call_setup () |
| void | call_dump_config_ () |
| void | enable_loop_slow_path_ () |
| void | set_component_state_ (uint8_t state) |
| Helper to set component state (clears state bits and sets new state) | |
| bool | set_status_flag_ (uint8_t flag) |
| Helper to set a status LED flag on both this component and the app. | |
| bool | set_error_flag_ (const LogString *message) |
| Set the error flag and log it; true when it was not set before. | |
| void | set_interval (const char *name, uint32_t interval, std::function< void()> &&f) |
| Set an interval function with a const char* name. | |
| void | set_interval (uint32_t id, uint32_t interval, std::function< void()> &&f) |
| Set an interval function with a numeric ID (zero heap allocation). | |
| void | set_interval (InternalSchedulerID id, uint32_t interval, std::function< void()> &&f) |
| void | set_interval (uint32_t interval, std::function< void()> &&f) |
| bool | cancel_interval (const char *name) |
| Cancel an interval function. | |
| bool | cancel_interval (uint32_t id) |
| bool | cancel_interval (InternalSchedulerID id) |
| void | set_timeout (const char *name, uint32_t timeout, std::function< void()> &&f) |
| Set a timeout function with a const char* name. | |
| void | set_timeout (uint32_t id, uint32_t timeout, std::function< void()> &&f) |
| Set a timeout function with a numeric ID (zero heap allocation). | |
| void | set_timeout (InternalSchedulerID id, uint32_t timeout, std::function< void()> &&f) |
| void | set_timeout (uint32_t timeout, std::function< void()> &&f) |
| bool | cancel_timeout (const char *name) |
| Cancel a timeout function. | |
| bool | cancel_timeout (uint32_t id) |
| bool | cancel_timeout (InternalSchedulerID id) |
| void | defer (const char *name, std::function< void()> &&f) |
| Defer a callback to the next loop() call with a const char* name. | |
| void | defer (std::function< void()> &&f) |
| Defer a callback to the next loop() call. | |
| void | defer (uint32_t id, std::function< void()> &&f) |
| Defer a callback with a numeric ID (zero heap allocation) | |
| bool | cancel_defer (const char *name) |
| Cancel a defer callback using the specified name, name must not be empty. | |
| bool | cancel_defer (uint32_t id) |
| void | status_clear_warning_slow_path_ () |
| void | status_clear_error_slow_path_ () |
Protected Attributes | |
| const audio::AudioStreamInfo | usb_stream_info_ |
| uint32_t | write_timeout_ms_ |
| uint32_t | write_chunk_ {0} |
| uint32_t | frame_bytes_ {0} |
| uint32_t | packet_bytes_ {0} |
| uint32_t | packet_frac_ {0} |
| uint32_t | transfer_bytes_ {0} |
| uint32_t | transfer_us_ {0} |
| uint32_t | in_flight_us_ {0} |
| uint32_t | report_frames_ {0} |
| uint32_t | pad_remaining_ {0} |
| std::atomic< uint32_t > | ring_bytes_ {0} |
| std::atomic< uint32_t > | ring_padding_ {0} |
| std::atomic< uint32_t > | last_taken_us_ {0} |
| portMUX_TYPE | taken_lock_ = portMUX_INITIALIZER_UNLOCKED |
| uint32_t | packet_frac_accum_ {0} |
| uint32_t | unreported_frames_ {0} |
| uint32_t | report_frames_pending_ {0} |
| int64_t | report_finish_us_ {0} |
| int64_t | last_finish_us_ {0} |
| std::atomic< uint8_t > | commands_ {0} |
| std::atomic< uint8_t > | writes_in_flight_ {0} |
| std::atomic< bool > | format_mismatch_ {false} |
| bool | finishing_ {false} |
| bool | finish_after_start_ {false} |
Protected Attributes inherited from esphome::speaker::Speaker | |
| State | state_ {STATE_STOPPED} |
| bool | mute_state_ {false} |
| audio::AudioStreamInfo | audio_stream_info_ |
| float | volume_ {1.0f} |
| audio_dac::AudioDac * | audio_dac_ {nullptr} |
| CallbackManager< void(uint32_t, int64_t)> | audio_output_callback_ {} |
Protected Attributes inherited from esphome::Component | |
| uint8_t | component_source_index_ {0} |
| Index into component source PROGMEM lookup table (0 = not set) | |
| uint8_t | warn_if_blocking_over_ {WARN_IF_BLOCKING_OVER_CS} |
| Warn threshold in centiseconds (max 2550ms) | |
| uint8_t | component_state_ {0x00} |
| State of this component - each bit has a purpose: Bits 0-2: Component state (0x00=CONSTRUCTION, 0x01=SETUP, 0x02=LOOP, 0x03=FAILED, 0x04=LOOP_DONE) Bit 3: STATUS_LED_WARNING Bit 4: STATUS_LED_ERROR Bit 5: Has overridden loop() (set at registration time) Bits 6-7: Unused - reserved for future expansion. | |
| volatile bool | pending_enable_loop_ {false} |
| ISR-safe flag for enable_loop_soon_any_context. | |
| ComponentRuntimeStats | runtime_stats_ |
Protected Attributes inherited from esphome::Parented< USBAudioComponent > | |
| USBAudioComponent * | parent_ |
Protected Attributes inherited from esphome::usb_audio::USBAudioStream | |
| uint32_t | buffer_size_ |
Static Protected Attributes | |
| static constexpr uint8_t | COMMAND_START = 1 << 0 |
| static constexpr uint8_t | COMMAND_STOP = 1 << 1 |
| static constexpr uint8_t | COMMAND_FINISH = 1 << 2 |
Additional Inherited Members | |
Data Fields inherited from esphome::Component | |
| uint32_t | length = 5000) |
Definition at line 18 of file usb_audio_speaker.h.
|
inline |
Definition at line 23 of file usb_audio_speaker.h.
|
protected |
Definition at line 109 of file usb_audio_speaker.cpp.
|
protected |
Definition at line 322 of file usb_audio_speaker.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 38 of file usb_audio_speaker.cpp.
|
overridevirtual |
Reimplemented from esphome::speaker::Speaker.
Definition at line 107 of file usb_audio_speaker.cpp.
|
inlineoverridevirtual |
Implements esphome::usb_audio::USBAudioStream.
Definition at line 44 of file usb_audio_speaker.h.
|
overridevirtual |
Implements esphome::speaker::Speaker.
Definition at line 344 of file usb_audio_speaker.cpp.
|
protected |
Definition at line 333 of file usb_audio_speaker.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 50 of file usb_audio_speaker.cpp.
|
overridevirtual |
Implements esphome::usb_audio::USBAudioStream.
Definition at line 130 of file usb_audio_speaker.cpp.
|
overridevirtual |
Reimplemented from esphome::usb_audio::USBAudioStream.
Definition at line 270 of file usb_audio_speaker.cpp.
|
protected |
Write silence until a whole USB transfer is padded, so the driver sends a final partial transfer.
Definition at line 251 of file usb_audio_speaker.cpp.
|
overridevirtual |
Implements esphome::speaker::Speaker.
Definition at line 155 of file usb_audio_speaker.cpp.
|
override |
Definition at line 148 of file usb_audio_speaker.cpp.
|
protected |
Definition at line 157 of file usb_audio_speaker.cpp.
|
protected |
Definition at line 92 of file usb_audio_speaker.cpp.
|
protected |
Bytes that can be written without filling the driver's ring buffer past buffer_size_.
Definition at line 227 of file usb_audio_speaker.cpp.
|
overridevirtual |
Reimplemented from esphome::speaker::Speaker.
Definition at line 352 of file usb_audio_speaker.cpp.
|
overridevirtual |
Reimplemented from esphome::speaker::Speaker.
Definition at line 347 of file usb_audio_speaker.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 22 of file usb_audio_speaker.cpp.
|
overridevirtual |
Implements esphome::speaker::Speaker.
Definition at line 98 of file usb_audio_speaker.cpp.
|
overridevirtual |
Implements esphome::speaker::Speaker.
Definition at line 105 of file usb_audio_speaker.cpp.
|
protected |
Definition at line 119 of file usb_audio_speaker.cpp.
|
inlineoverridevirtual |
Implements esphome::usb_audio::USBAudioStream.
Definition at line 46 of file usb_audio_speaker.h.
|
protected |
Write to the driver, counting the bytes in ring_bytes_ (and in ring_padding_ for silence padding).
Definition at line 234 of file usb_audio_speaker.cpp.
|
staticconstexprprotected |
Definition at line 52 of file usb_audio_speaker.h.
|
staticconstexprprotected |
Definition at line 50 of file usb_audio_speaker.h.
|
staticconstexprprotected |
Definition at line 51 of file usb_audio_speaker.h.
|
protected |
Definition at line 100 of file usb_audio_speaker.h.
|
protected |
Definition at line 107 of file usb_audio_speaker.h.
|
protected |
Definition at line 105 of file usb_audio_speaker.h.
|
protected |
Definition at line 104 of file usb_audio_speaker.h.
|
protected |
Definition at line 74 of file usb_audio_speaker.h.
|
protected |
Definition at line 81 of file usb_audio_speaker.h.
|
protected |
Definition at line 99 of file usb_audio_speaker.h.
|
protected |
Definition at line 90 of file usb_audio_speaker.h.
|
protected |
Definition at line 75 of file usb_audio_speaker.h.
|
protected |
Definition at line 76 of file usb_audio_speaker.h.
|
protected |
Definition at line 94 of file usb_audio_speaker.h.
|
protected |
Definition at line 84 of file usb_audio_speaker.h.
|
protected |
Definition at line 97 of file usb_audio_speaker.h.
|
protected |
Definition at line 82 of file usb_audio_speaker.h.
|
protected |
Definition at line 96 of file usb_audio_speaker.h.
|
protected |
Definition at line 87 of file usb_audio_speaker.h.
|
protected |
Definition at line 88 of file usb_audio_speaker.h.
|
protected |
Definition at line 93 of file usb_audio_speaker.h.
|
protected |
Definition at line 79 of file usb_audio_speaker.h.
|
protected |
Definition at line 80 of file usb_audio_speaker.h.
|
protected |
Definition at line 95 of file usb_audio_speaker.h.
|
protected |
Definition at line 68 of file usb_audio_speaker.h.
|
protected |
Definition at line 71 of file usb_audio_speaker.h.
|
protected |
Definition at line 69 of file usb_audio_speaker.h.
|
protected |
Definition at line 102 of file usb_audio_speaker.h.