#include <spdif_encoder.h>
|
| bool | setup () |
| | Initialize the SPDIF working buffer.
|
| |
| void | set_write_callback (SPDIFBlockCallback callback, void *user_ctx) |
| | Set callback for normal writes (used when channel is running)
|
| |
| void | set_preload_callback (SPDIFBlockCallback callback, void *user_ctx) |
| | Set callback for preload writes (used when preloading to DMA before enabling channel)
|
| |
| void | set_preload_mode (bool preload) |
| | Enable or disable preload mode When in preload mode, completed blocks use the preload callback instead of write callback.
|
| |
| bool | is_preload_mode () const |
| | Check if currently in preload mode.
|
| |
| void | set_bytes_per_sample (uint8_t bytes_per_sample) |
| | Set input PCM width: 2 = 16-bit, 3 = 24-bit, 4 = 32-bit (truncated to 24-bit on the wire).
|
| |
| uint8_t | get_bytes_per_sample () const |
| | Get the configured input PCM width in bytes per sample.
|
| |
| esp_err_t | write (const uint8_t *src, size_t size, TickType_t ticks_to_wait, uint32_t *blocks_sent=nullptr, size_t *bytes_consumed=nullptr) |
| | Convert PCM audio data to SPDIF BMC encoded data.
|
| |
| esp_err_t | flush_with_silence (TickType_t ticks_to_wait) |
| | Emit one complete SPDIF block: pad any pending partial block with silence and send, or send a full silence block if nothing is pending.
|
| |
| void | reset () |
| | Reset the SPDIF block buffer and position tracking, discarding any partial block.
|
| |
| void | set_sample_rate (uint32_t sample_rate) |
| | Set the sample rate for Channel Status Block encoding.
|
| |
| uint32_t | get_sample_rate () const |
| | Get the currently configured sample rate.
|
| |
|
| template<uint8_t Bps> |
| void | encode_silence_frame_ () |
| | Encode a single stereo silence frame at the current block position.
|
| |
| template<uint8_t Bps> |
| HOT esp_err_t | write_typed_ (const uint8_t *src, size_t size, TickType_t ticks_to_wait, uint32_t *blocks_sent, size_t *bytes_consumed) |
| | Templated write loop. Called from the public write() via runtime dispatch on bytes_per_sample_.
|
| |
| template<uint8_t Bps> |
| esp_err_t | flush_with_silence_typed_ (TickType_t ticks_to_wait) |
| | Templated flush-with-silence.
|
| |
| esp_err_t | send_block_ (TickType_t ticks_to_wait) |
| | Send the completed block via the appropriate callback.
|
| |
| void | build_channel_status_ () |
| | Build the channel status block from current configuration.
|
| |
Definition at line 36 of file spdif_encoder.h.
◆ build_channel_status_()
| void esphome::i2s_audio::SPDIFEncoder::build_channel_status_ |
( |
| ) |
|
|
protected |
Build the channel status block from current configuration.
Definition at line 123 of file spdif_encoder.cpp.
◆ encode_silence_frame_()
template<uint8_t Bps>
| void esphome::i2s_audio::SPDIFEncoder::encode_silence_frame_ |
( |
| ) |
|
|
protected |
Encode a single stereo silence frame at the current block position.
- Note
- Used only by flush_with_silence_typed_ to pad; the hot write path inlines the encoding body directly into write_typed_ to keep block_ptr / frame_in_block_ in registers.
Definition at line 293 of file spdif_encoder.cpp.
◆ flush_with_silence()
| esp_err_t esphome::i2s_audio::SPDIFEncoder::flush_with_silence |
( |
TickType_t | ticks_to_wait | ) |
|
Emit one complete SPDIF block: pad any pending partial block with silence and send, or send a full silence block if nothing is pending.
Always produces exactly one block on success.
- Parameters
-
| ticks_to_wait | Timeout for blocking writes |
- Returns
- esp_err_t as returned from the callback
Definition at line 477 of file spdif_encoder.cpp.
◆ flush_with_silence_typed_()
template<uint8_t Bps>
| esp_err_t esphome::i2s_audio::SPDIFEncoder::flush_with_silence_typed_ |
( |
TickType_t | ticks_to_wait | ) |
|
|
protected |
Templated flush-with-silence.
Pads the pending block with zeros at the configured width (or builds a full silence block when nothing is pending) and sends it. Always emits one block.
Definition at line 455 of file spdif_encoder.cpp.
◆ get_bytes_per_sample()
| uint8_t esphome::i2s_audio::SPDIFEncoder::get_bytes_per_sample |
( |
| ) |
const |
|
inline |
Get the configured input PCM width in bytes per sample.
Definition at line 71 of file spdif_encoder.h.
◆ get_sample_rate()
| uint32_t esphome::i2s_audio::SPDIFEncoder::get_sample_rate |
( |
| ) |
const |
|
inline |
Get the currently configured sample rate.
Definition at line 98 of file spdif_encoder.h.
◆ is_preload_mode()
| bool esphome::i2s_audio::SPDIFEncoder::is_preload_mode |
( |
| ) |
const |
|
inline |
◆ reset()
| void esphome::i2s_audio::SPDIFEncoder::reset |
( |
| ) |
|
Reset the SPDIF block buffer and position tracking, discarding any partial block.
Definition at line 95 of file spdif_encoder.cpp.
◆ send_block_()
| esp_err_t esphome::i2s_audio::SPDIFEncoder::send_block_ |
( |
TickType_t | ticks_to_wait | ) |
|
|
protected |
Send the completed block via the appropriate callback.
Definition at line 305 of file spdif_encoder.cpp.
◆ set_bytes_per_sample()
| void esphome::i2s_audio::SPDIFEncoder::set_bytes_per_sample |
( |
uint8_t | bytes_per_sample | ) |
|
Set input PCM width: 2 = 16-bit, 3 = 24-bit, 4 = 32-bit (truncated to 24-bit on the wire).
Must be called before write() if input width changes from the default (16-bit). Triggers a channel-status rebuild to reflect the new word length.
Definition at line 109 of file spdif_encoder.cpp.
◆ set_preload_callback()
| void esphome::i2s_audio::SPDIFEncoder::set_preload_callback |
( |
SPDIFBlockCallback | callback, |
|
|
void * | user_ctx ) |
|
inline |
Set callback for preload writes (used when preloading to DMA before enabling channel)
- Parameters
-
| callback | Function pointer to call when a block is ready for preload |
| user_ctx | Context pointer passed to callback (typically 'this' pointer of speaker) |
Definition at line 53 of file spdif_encoder.h.
◆ set_preload_mode()
| void esphome::i2s_audio::SPDIFEncoder::set_preload_mode |
( |
bool | preload | ) |
|
|
inline |
Enable or disable preload mode When in preload mode, completed blocks use the preload callback instead of write callback.
Definition at line 60 of file spdif_encoder.h.
◆ set_sample_rate()
| void esphome::i2s_audio::SPDIFEncoder::set_sample_rate |
( |
uint32_t | sample_rate | ) |
|
Set the sample rate for Channel Status Block encoding.
- Parameters
-
| sample_rate | Sample rate in Hz (e.g., 44100, 48000) Call this before writing audio data to ensure correct channel status. |
Definition at line 101 of file spdif_encoder.cpp.
◆ set_write_callback()
| void esphome::i2s_audio::SPDIFEncoder::set_write_callback |
( |
SPDIFBlockCallback | callback, |
|
|
void * | user_ctx ) |
|
inline |
Set callback for normal writes (used when channel is running)
- Parameters
-
| callback | Function pointer to call when a block is ready |
| user_ctx | Context pointer passed to callback (typically 'this' pointer of speaker) |
Definition at line 45 of file spdif_encoder.h.
◆ setup()
| bool esphome::i2s_audio::SPDIFEncoder::setup |
( |
| ) |
|
Initialize the SPDIF working buffer.
- Returns
- true if setup was successful, false if allocation failed
Definition at line 80 of file spdif_encoder.cpp.
◆ write()
| HOT esp_err_t esphome::i2s_audio::SPDIFEncoder::write |
( |
const uint8_t * | src, |
|
|
size_t | size, |
|
|
TickType_t | ticks_to_wait, |
|
|
uint32_t * | blocks_sent = nullptr, |
|
|
size_t * | bytes_consumed = nullptr ) |
Convert PCM audio data to SPDIF BMC encoded data.
- Parameters
-
| src | Source PCM audio data (stereo, width matches set_bytes_per_sample) |
| size | Size of source data in bytes |
| ticks_to_wait | Timeout for blocking writes |
| blocks_sent | Optional pointer to receive the number of complete SPDIF blocks sent |
| bytes_consumed | Optional pointer to receive the number of PCM bytes consumed from src |
- Returns
- esp_err_t as returned from the callback
Definition at line 437 of file spdif_encoder.cpp.
◆ write_typed_()
template<uint8_t Bps>
| HOT esp_err_t esphome::i2s_audio::SPDIFEncoder::write_typed_ |
( |
const uint8_t * | src, |
|
|
size_t | size, |
|
|
TickType_t | ticks_to_wait, |
|
|
uint32_t * | blocks_sent, |
|
|
size_t * | bytes_consumed ) |
|
protected |
Templated write loop. Called from the public write() via runtime dispatch on bytes_per_sample_.
Definition at line 333 of file spdif_encoder.cpp.
◆ block_buf_is_silence_block_
| bool esphome::i2s_audio::SPDIFEncoder::block_buf_is_silence_block_ {false} |
|
protected |
◆ bytes_per_sample_
| uint8_t esphome::i2s_audio::SPDIFEncoder::bytes_per_sample_ {2} |
|
protected |
◆ channel_status_
| std::array<uint8_t, 24> esphome::i2s_audio::SPDIFEncoder::channel_status_ {} |
|
protected |
◆ frame_in_block_
| uint8_t esphome::i2s_audio::SPDIFEncoder::frame_in_block_ {0} |
|
protected |
◆ preload_callback_
◆ preload_callback_ctx_
| void* esphome::i2s_audio::SPDIFEncoder::preload_callback_ctx_ {nullptr} |
|
protected |
◆ preload_mode_
| bool esphome::i2s_audio::SPDIFEncoder::preload_mode_ {false} |
|
protected |
◆ sample_rate_
| uint32_t esphome::i2s_audio::SPDIFEncoder::sample_rate_ {48000} |
|
protected |
◆ spdif_block_buf_
| std::unique_ptr<uint32_t[]> esphome::i2s_audio::SPDIFEncoder::spdif_block_buf_ |
|
protected |
◆ spdif_block_ptr_
| uint32_t* esphome::i2s_audio::SPDIFEncoder::spdif_block_ptr_ {nullptr} |
|
protected |
◆ write_callback_
◆ write_callback_ctx_
| void* esphome::i2s_audio::SPDIFEncoder::write_callback_ctx_ {nullptr} |
|
protected |
The documentation for this class was generated from the following files: