#include <audio_decoder.h>
Definition at line 55 of file audio_decoder.h.
◆ AudioDecoder()
| esphome::audio::AudioDecoder::AudioDecoder |
( |
size_t | input_buffer_size, |
|
|
size_t | output_buffer_size ) |
Allocates the output transfer buffer and stores the input buffer size for later use by add_source()
- Parameters
-
| input_buffer_size | Soft cap on the bytes a ring buffer source exposes per fill, in bytes. |
| output_buffer_size | Size of the output transfer buffer in bytes. |
Definition at line 20 of file audio_decoder.cpp.
◆ ~AudioDecoder()
| esphome::audio::AudioDecoder::~AudioDecoder |
( |
| ) |
|
|
default |
◆ add_sink() [1/3]
Adds a callback as the sink for decoded audio.
- Parameters
-
- Returns
- ESP_OK if successful, ESP_ERR_NO_MEM if the transfer buffer wasn't allocated
Definition at line 62 of file audio_decoder.cpp.
◆ add_sink() [2/3]
Adds a sink speaker for decoded audio.
- Parameters
-
| speaker | pointer to speaker component |
- Returns
- ESP_OK if successsful, ESP_ERR_NO_MEM if the transfer buffer wasn't allocated
Definition at line 53 of file audio_decoder.cpp.
◆ add_sink() [3/3]
Adds a sink ring buffer for decoded audio.
Takes ownership of the ring buffer in a shared_ptr.
- Parameters
-
| output_ring_buffer | weak_ptr of a shared_ptr of the sink ring buffer to transfer ownership |
- Returns
- ESP_OK if successsful, ESP_ERR_NO_MEM if the transfer buffer wasn't allocated
Definition at line 44 of file audio_decoder.cpp.
◆ add_source() [1/2]
| esp_err_t esphome::audio::AudioDecoder::add_source |
( |
const uint8_t * | data_pointer, |
|
|
size_t | length ) |
Adds a const data pointer as the source for raw file data.
Does not allocate a transfer buffer.
- Parameters
-
| data_pointer | Pointer to the const audio data (e.g., stored in flash memory) |
| length | Size of the data in bytes |
- Returns
- ESP_OK
Definition at line 37 of file audio_decoder.cpp.
◆ add_source() [2/2]
Adds a source ring buffer for raw file data.
Shares ownership of the ring buffer via a shared_ptr. The decoder reads directly from the ring buffer's internal storage with a zero-copy RingBufferAudioSource.
- Parameters
-
| input_ring_buffer | weak_ptr of the source ring buffer to read from |
- Returns
- ESP_OK if successful, ESP_ERR_INVALID_ARG if the ring buffer is expired or the buffer size is zero
Definition at line 25 of file audio_decoder.cpp.
◆ decode()
Decodes audio from the ring buffer source and writes to the sink.
- Parameters
-
| stop_gracefully | If true, it indicates the file source is finished. The decoder will decode all the reamining data and then finish. |
- Returns
- AudioDecoderState
Definition at line 121 of file audio_decoder.cpp.
◆ decode_flac_()
◆ decode_mp3_()
◆ decode_opus_()
◆ decode_wav_()
◆ get_audio_stream_info()
Gets the audio stream information, if it has been decoded from the files header.
- Returns
- optional<AudioStreamInfo> with the audio information. If not available yet, returns no value.
Definition at line 113 of file audio_decoder.h.
◆ get_playback_ms()
| uint32_t esphome::audio::AudioDecoder::get_playback_ms |
( |
| ) |
const |
|
inline |
Returns the duration of audio (in milliseconds) decoded and sent to the sink.
- Returns
- Duration of decoded audio in milliseconds
Definition at line 117 of file audio_decoder.h.
◆ set_pause_output_state()
| void esphome::audio::AudioDecoder::set_pause_output_state |
( |
bool | pause_state | ) |
|
|
inline |
Pauses sending resampled audio to the sink.
If paused, it will continue to process internal buffers.
- Parameters
-
| pause_state | If true, audio data is not sent to the sink. |
Definition at line 121 of file audio_decoder.h.
◆ start()
| esp_err_t esphome::audio::AudioDecoder::start |
( |
AudioFileType | audio_file_type | ) |
|
Sets up decoding the file.
- Parameters
-
| audio_file_type | AudioFileType of the file |
- Returns
- ESP_OK if successful, ESP_ERR_NO_MEM if the transfer buffers fail to allocate, or ESP_ERR_NOT_SUPPORTED if the format isn't supported.
Definition at line 70 of file audio_decoder.cpp.
◆ accumulated_frames_written_
| uint32_t esphome::audio::AudioDecoder::accumulated_frames_written_ {0} |
|
protected |
◆ audio_file_type_
◆ audio_stream_info_
| optional<AudioStreamInfo> esphome::audio::AudioDecoder::audio_stream_info_ {} |
|
protected |
◆ end_of_file_
| bool esphome::audio::AudioDecoder::end_of_file_ {false} |
|
protected |
◆ flac_decoder_
| std::unique_ptr<micro_flac::FLACDecoder> esphome::audio::AudioDecoder::flac_decoder_ |
|
protected |
◆ free_buffer_required_
| size_t esphome::audio::AudioDecoder::free_buffer_required_ {0} |
|
protected |
◆ input_buffer_
◆ input_buffer_size_
| size_t esphome::audio::AudioDecoder::input_buffer_size_ {0} |
|
protected |
◆ mp3_decoder_
| std::unique_ptr<micro_mp3::Mp3Decoder> esphome::audio::AudioDecoder::mp3_decoder_ |
|
protected |
◆ opus_decoder_
| std::unique_ptr<micro_opus::OggOpusDecoder> esphome::audio::AudioDecoder::opus_decoder_ |
|
protected |
◆ output_transfer_buffer_
◆ pause_output_
| bool esphome::audio::AudioDecoder::pause_output_ {false} |
|
protected |
◆ playback_ms_
| uint32_t esphome::audio::AudioDecoder::playback_ms_ {0} |
|
protected |
◆ potentially_failed_count_
| uint32_t esphome::audio::AudioDecoder::potentially_failed_count_ {0} |
|
protected |
◆ wav_decoder_
| std::unique_ptr<micro_wav::WAVDecoder> esphome::audio::AudioDecoder::wav_decoder_ |
|
protected |
The documentation for this class was generated from the following files: