|
arduino-audio-tools
|
SPI master endpoint for remote audio sink configuration and PCM data transfer. More...
#include <SPIAudioMaster.h>
Public Member Functions | |
| SPIAudioMaster ()=default | |
| Default constructor. | |
| SPIAudioMaster (SPIClass &spi) | |
| Constructor with explicit SPI bus instance. | |
| virtual void | addNotifyAudioChange (AudioInfoSupport &bi) |
| Adds target to be notified about audio changes. | |
| virtual AudioInfo | audioInfo () override |
| provides the actual input AudioInfo | |
| virtual AudioInfo | audioInfoOut () |
| int | available () |
| Queries how many bytes are currently filled/readable in the remote buffer. | |
| int | availableForWrite () |
| Returns writable bytes on the remote side. | |
| virtual bool | begin () |
| virtual bool | begin (AudioInfo info) |
| bool | begin (SPIAudioMasterConfig cfg=SPIAudioMasterConfig()) |
| Initializes SPI and stores the master configuration. | |
| bool | clear () |
| Clears the remote audio buffer. | |
| virtual void | clearNotifyAudioChange () |
| Deletes all change notify subscriptions. | |
| void | end () |
| Stops the master and closes the SPI bus. | |
| virtual void | flush () |
| bool | isActive () const |
| Returns true when the master is active. | |
| virtual bool | isDeletable () |
| If true we need to release the related memory in the destructor. | |
| bool | isNotifyActive () |
| Checks if the automatic AudioInfo update is active. | |
| virtual | operator bool () |
| virtual bool | removeNotifyAudioChange (AudioInfoSupport &bi) |
| Removes a target in order not to be notified about audio changes. | |
| void | setAudioInfo (AudioInfo info) override |
| Sends audio format information to the remote slave. | |
| bool | setMime (const char *mime) |
| Set stream mime type (e.g. "audio/wav", "audio/mp3") | |
| void | setNotifyActive (bool flag) |
| Deactivate/Reactivate automatic AudioInfo updates: (default is active) | |
| size_t | write (const uint8_t *data, size_t len) |
| Writes audio bytes in chunks using WriteData command. | |
| virtual size_t | write (uint8_t ch) override |
| virtual void | writeSilence (size_t len) |
Protected Member Functions | |
| uint32_t | getAvailableBufferSize () |
| Queries available space in the remote buffer in bytes. | |
| uint32_t | getFilledBufferSize () |
| Queries how many bytes are filled/readable in the remote buffer. | |
| void | notifyAudioChange (AudioInfo info) |
| bool | sendCommand (SPIAudioCommand command, const uint8_t *payload, uint16_t payload_len, uint8_t *response, uint16_t *response_len) |
| Sends a protocol command and reads the optional response. | |
| uint16_t | transferU16LE (uint16_t value) |
| Transfers and/or receives a 16-bit little-endian value over SPI. | |
Static Protected Member Functions | |
| static uint32_t | readU32LE (const uint8_t *in) |
| Reads a 32-bit little-endian integer from the source buffer. | |
| static void | writeU32LE (uint8_t *out, uint32_t value) |
| Writes a 32-bit little-endian integer to the target buffer. | |
Protected Attributes | |
| int | _timeout = 10 |
| bool | active = false |
| int | buffer_size = 0 |
| AudioInfo | cfg |
| SPIAudioMasterConfig | config |
| bool | is_active = false |
| bool | is_notify_active = true |
| Vector< AudioInfoSupport * > | notify_vector |
| SPIClass * | p_spi = nullptr |
| SingleBuffer< uint8_t > | tmp {MAX_SINGLE_CHARS} |
| int | tmpPos = 0 |
SPI master endpoint for remote audio sink configuration and PCM data transfer.
This class implements the master side of a simple binary request/response protocol over SPI and is designed to work with SPIAudioSlave.
SPIAudioMaster provides a lightweight binary protocol for controlling a remote audio sink and streaming PCM data over SPI. The protocol is request/response based; the master initiates all transactions and waits for slave responses.
Request frame: cmd(1) + payload_len(2 LE) + payload(0..65535) Response frame: status(1) + response_len(2 LE) + response(0..65535)
All multi-byte integers are little-endian. Payload length is uint16_t, allowing up to 64KB payloads per command.
The master supports two write modes via is_blocking_write:
write() sends only the bytes that currently fit into the remote buffer and returns immediately.write() waits until enough remote space is available for one chunk and then sends that chunk in a single SPI command.Responses include status byte:
Configure SPI bus settings via SPIAudioMasterConfig:
cs_pin: Chip select GPIO (defaults to SS if defined, else 10). Set to -1 to disable manual CS handling (external or hardware-controlled CS).clock_hz: SPI clock frequency (default 8 MHz)bit_order: MSBFIRST or LSBFIRST (default MSBFIRST)data_mode: SPI_MODE0..SPI_MODE3 (default SPI_MODE0)max_payload: Max bytes per WriteData command (default 1024)is_blocking_write: Enable blocking write mode (default false)
|
default |
Default constructor.
|
inlineexplicit |
Constructor with explicit SPI bus instance.
|
inlinevirtualinherited |
Adds target to be notified about audio changes.
Reimplemented in CodecNOP, EncodedAudioOutput, EncodedAudioStream, AACDecoderFDK, DecoderBasic, CodecChain, MP3DecoderHelix, MP3DecoderMAD, OggContainerDecoder, RTSPClient< TcpClient, UdpSocket >, Pipeline, and Pipeline::ModifyingStreamAdapter.
provides the actual input AudioInfo
Implements AudioInfoSupport.
Reimplemented in AdapterPrintToAudioOutput, EncodedAudioOutput, and AdapterAudioStreamToAudioOutput.
provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
Reimplemented in PureDataStream, PWMAudioOutput, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, FormatConverterStream, Pipeline, ResampleStream, and ResampleStreamT< TInterpolator >.
|
inline |
Queries how many bytes are currently filled/readable in the remote buffer.
|
inlinevirtual |
Returns writable bytes on the remote side.
Reimplemented from AudioOutput.
Reimplemented in OSCContainerEncoder::OSCOutput, AudioOutputWithCallback, AudioServerEx, RTSPOutput< Platform >, PitchShiftOutput< T, BufferT >, PWMAudioOutput, RTTTLOutput< T >, EncodedAudioOutput, OggContainerOutput, FFTEffect, FFTPitchShift, R2ROutput, AdapterAudioStreamToAudioOutput, ChannelsSelectOutput, MetaDataFilter, CsvOutput< T >, HexDumpOutput, MemoryOutput, and RTTTLOutput< T >.
Reimplemented in AudioESP32ULP, RTSPOutput< Platform >, RTTTLOutput< T >, ChannelsSelectOutput, CsvOutput< T >, and EncodedAudioOutput.
|
inline |
Initializes SPI and stores the master configuration.
|
inline |
Clears the remote audio buffer.
Deletes all change notify subscriptions.
Reimplemented in RTSPClient< TcpClient, UdpSocket >.
|
inlinevirtual |
Stops the master and closes the SPI bus.
Reimplemented from AudioOutput.
Reimplemented from Print.
Reimplemented in MultiOutput, and HexDumpOutput.
|
inlineprotected |
Queries available space in the remote buffer in bytes.
|
inlineprotected |
Queries how many bytes are filled/readable in the remote buffer.
|
inline |
Returns true when the master is active.
If true we need to release the related memory in the destructor.
Reimplemented in AdapterPrintToAudioOutput, and AdapterAudioStreamToAudioOutput.
Reimplemented in RTSPOutput< Platform >, EncodedAudioOutput, and AdapterAudioStreamToAudioOutput.
Reads a 32-bit little-endian integer from the source buffer.
|
inlinevirtualinherited |
Removes a target in order not to be notified about audio changes.
Reimplemented in RTSPClient< TcpClient, UdpSocket >.
|
inlineprotected |
Sends a protocol command and reads the optional response.
Sends audio format information to the remote slave.
Reimplemented from AudioOutput.
Deactivate/Reactivate automatic AudioInfo updates: (default is active)
Transfers and/or receives a 16-bit little-endian value over SPI.
Writes audio bytes in chunks using WriteData command.
Implements AudioOutput.
Reimplemented in MetaDataOutput, and MultiOutput.
Writes n 0 values (= silence)
| len |
Writes a 32-bit little-endian integer to the target buffer.
|
protectedinherited |
|
protected |
|
protectedinherited |
|
protected |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |