arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
NRF24Stream Class Reference

NRF24L01(+) Stream for sending and receiving audio via the nRF24L01 2.4GHz radio module. Optimized for low-latency, high-throughput audio with small 32-byte packets. More...

#include <NRF24Stream.h>

Inheritance diagram for NRF24Stream:
AudioStream BaseStream AudioInfoSupport AudioInfoSource Stream Print

Public Member Functions

 NRF24Stream ()=default
 Default constructor.
 
 NRF24Stream (BaseBuffer< uint8_t > &buffer)
 Constructor with an external receive buffer.
 
 NRF24Stream (RF24 &radio)
 Constructor with an externally created RF24 object.
 
 NRF24Stream (RF24 &radio, BaseBuffer< uint8_t > &buffer)
 Constructor with an externally created RF24 object and receive buffer.
 
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 () override
 Returns the number of bytes available to read.
 
int availableForWrite () override
 Returns the number of bytes available to write.
 
bool begin () override
 Initializes the radio hardware and configures TX or RX mode.
 
bool begin (NRF24Config config)
 Starts the stream with the given configuration.
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
NRF24Config defaultConfig (RxTxMode mode=TX_MODE)
 Returns the default configuration for the given mode.
 
void end () override
 Stops the radio and releases resources.
 
virtual void flush () override
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual operator bool ()
 
RF24radio ()
 Provides access to the RF24 radio object for advanced configuration.
 
size_t readBytes (uint8_t *data, size_t len) override
 Reads received audio data from the RX buffer.
 
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
void setAudioInfo (AudioInfo info) override
 Updates the audio info and propagates to the base class.
 
void setBuffer (BaseBuffer< uint8_t > &buffer)
 Sets an external receive buffer.
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setWriteBufferSize (int size)
 
size_t write (const uint8_t *data, size_t len) override
 Writes audio data, buffering into payload-sized packets for transmission.
 
virtual size_t write (uint8_t ch) override
 
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
 

Protected Member Functions

void fillBuffer ()
 Drains all available radio packets into the RX buffer.
 
virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read()
 

Protected Attributes

int _timeout = 10
 
NRF24Config cfg
 
RingBuffer< uint8_tdefault_rx_buffer {0}
 
AudioInfo info
 
bool is_notify_active = true
 
Vector< AudioInfoSupport * > notify_vector
 
RF24p_own_radio = nullptr
 
RF24p_radio = nullptr
 
BaseBuffer< uint8_t > * p_rx_buffer = nullptr
 
RingBuffer< uint8_ttmp_in {0}
 
RingBuffer< uint8_ttmp_out {0}
 
SingleBuffer< uint8_ttx_buffer
 
int write_buffer_size = MAX_SINGLE_CHARS
 

Detailed Description

NRF24L01(+) Stream for sending and receiving audio via the nRF24L01 2.4GHz radio module. Optimized for low-latency, high-throughput audio with small 32-byte packets.

Works across Teensy, ESP32, Arduino Nano (including variants with integrated nRF24), and other platforms supported by the RF24 library.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ NRF24Stream() [1/4]

NRF24Stream ( )
default

Default constructor.

◆ NRF24Stream() [2/4]

NRF24Stream ( RF24 radio)
inline

Constructor with an externally created RF24 object.

◆ NRF24Stream() [3/4]

NRF24Stream ( BaseBuffer< uint8_t > &  buffer)
inline

Constructor with an external receive buffer.

◆ NRF24Stream() [4/4]

NRF24Stream ( RF24 radio,
BaseBuffer< uint8_t > &  buffer 
)
inline

Constructor with an externally created RF24 object and receive buffer.

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ available()

int available ( )
inlineoverridevirtual

Returns the number of bytes available to read.

Reimplemented from BaseStream.

◆ availableForWrite()

int availableForWrite ( )
inlineoverridevirtual

Returns the number of bytes available to write.

Reimplemented from BaseStream.

◆ begin() [1/2]

bool begin ( )
inlineoverridevirtual

Initializes the radio hardware and configures TX or RX mode.

Reimplemented from BaseStream.

◆ begin() [2/2]

bool begin ( NRF24Config  config)
inline

Starts the stream with the given configuration.

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ defaultConfig()

NRF24Config defaultConfig ( RxTxMode  mode = TX_MODE)
inline

Returns the default configuration for the given mode.

◆ end()

void end ( )
inlineoverridevirtual

Stops the radio and releases resources.

Reimplemented from BaseStream.

◆ fillBuffer()

void fillBuffer ( )
inlineprotected

Drains all available radio packets into the RX buffer.

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

◆ isNotifyActive()

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ not_supported()

virtual int not_supported ( int  out,
const char msg = "" 
)
inlineprotectedvirtualinherited

◆ notifyAudioChange()

void notifyAudioChange ( AudioInfo  info)
inlineprotectedinherited

◆ operator bool()

virtual operator bool ( )
inlinevirtualinherited

◆ radio()

RF24 * radio ( )
inline

Provides access to the RF24 radio object for advanced configuration.

◆ readBytes()

size_t readBytes ( uint8_t data,
size_t  len 
)
inlineoverridevirtual

Reads received audio data from the RX buffer.

Reimplemented from AudioStream.

◆ readSilence()

virtual size_t readSilence ( uint8_t buffer,
size_t  length 
)
inlinevirtualinherited

Source to generate silence: just sets the buffer to 0.

◆ refillReadBuffer()

void refillReadBuffer ( )
inlineprotectedinherited

Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read()

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  info)
inlineoverridevirtual

Updates the audio info and propagates to the base class.

Reimplemented from AudioStream.

◆ setBuffer()

void setBuffer ( BaseBuffer< uint8_t > &  buffer)
inline

Sets an external receive buffer.

◆ setNotifyActive()

void setNotifyActive ( bool  flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active)

◆ setWriteBufferSize()

void setWriteBufferSize ( int  size)
inlineinherited

◆ write() [1/2]

size_t write ( const uint8_t data,
size_t  len 
)
inlineoverridevirtual

Writes audio data, buffering into payload-sized packets for transmission.

Reimplemented from AudioStream.

◆ write() [2/2]

virtual size_t write ( uint8_t  ch)
inlineoverridevirtualinherited

◆ writeSilence()

virtual void writeSilence ( size_t  len)
inlinevirtualinherited

Writes len bytes of silence (=0).

Member Data Documentation

◆ _timeout

int _timeout = 10
protectedinherited

◆ cfg

NRF24Config cfg
protected

◆ default_rx_buffer

RingBuffer<uint8_t> default_rx_buffer {0}
protected

◆ info

AudioInfo info
protectedinherited

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector<AudioInfoSupport*> notify_vector
protectedinherited

◆ p_own_radio

RF24* p_own_radio = nullptr
protected

◆ p_radio

RF24* p_radio = nullptr
protected

◆ p_rx_buffer

BaseBuffer<uint8_t>* p_rx_buffer = nullptr
protected

◆ tmp_in

RingBuffer<uint8_t> tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer<uint8_t> tmp_out {0}
protectedinherited

◆ tx_buffer

SingleBuffer<uint8_t> tx_buffer
protected

◆ write_buffer_size

int write_buffer_size = MAX_SINGLE_CHARS
protectedinherited

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