arduino-audio-tools
Loading...
Searching...
No Matches
VBANStream Class Reference

VBAN Audio Source and Sink for the ESP32. For further details please see https://vb-audio.com/Voicemeeter/vban.htm . Inspired by https://github.com/rkinnett/ESP32-VBAN-Audio-Source/tree/master and https://github.com/rkinnett/ESP32-VBAN-Network-Audio-Player. More...

#include <VBANStream.h>

Inheritance diagram for VBANStream:
AudioStream BaseStream AudioInfoSupport AudioInfoSource BaseStream AudioInfoSupport AudioInfoSource Stream Stream Stream Stream Print Print Print Print Print Print Print Print

Public Member Functions

virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfoOut ()
virtual AudioInfo audioInfoOut ()
int available ()
int availableForWrite ()
bool begin ()
bool begin (VBANConfig cfg)
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
VBANConfig defaultConfig (RxTxMode mode=TX_MODE)
virtual void end ()
virtual void end ()
virtual void flush () override
virtual void flush () override
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
virtual operator bool ()
virtual operator bool ()
size_t readBytes (uint8_t *data, size_t len) override
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
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.
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
void setAudioInfo (AudioInfo info) override
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active).
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active).
void setOutput (Print &out)
void setWriteBufferSize (int size)
void setWriteBufferSize (int size)
virtual size_t write (uint8_t ch) override
size_t write (const uint8_t *data, size_t len) override
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).

Protected Member Functions

bool begin_rx ()
bool begin_tx ()
bool configure_tx ()
void configure_vban (VBanSampleRates rate)
virtual int not_supported (int out, const char *msg="")
virtual int not_supported (int out, const char *msg="")
void notifyAudioChange (AudioInfo info)
void notifyAudioChange (AudioInfo info)
void receive_udp (AsyncUDPPacket &packet)
 VBAN adjusts the number of samples per packet according to sample rate. Assuming 16-bit PCM mono, sample rates 11025, 22050, 44100, and 88200 yield packets containing 64, 128, 256, and 256 samples per packet, respectively. The even-thousands sample rates below 48000 yield non-power-of-2 lengths. For example, sample rate 24000 yields 139 samples per packet. This VBAN->DMA->DAC method seems to require the dma buffer length be set equal to the number of samples in each VBAN packet. ESP32 I2S/DMA does not seem to handle non-power-of-2 buffer lengths well. Sample rate 24000 doesn't work reliably at all. Sample rate 32000 is stable but stutters. Recommend selecting from sample rates 11025, 22050, 44100, and above And set samplesPerPacket to 64 for 11025, 128 for 22050, or 256 for all else.
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().
void safe_strncpy (char *dest, const char *src, size_t dest_size)
void sendVbanPing0Reply (AsyncUDPPacket &sourcePacket)
void start_wifi ()
const char * toString (IPAddress adr)
int vban_sample_rate ()

Protected Attributes

int _timeout = 10
bool available_active = false
const IPAddress broadcast_address {0, 0, 0, 0}
size_t bytes_received = 0
VBANConfig cfg
AudioInfo info
bool is_notify_active = true
Vector< AudioInfoSupport * > notify_vector
Print * p_out = nullptr
uint32_t packet_counter = 0
BufferRTOS< uint8_t > rx_buffer { 0}
Throttle throttle
RingBuffer< uint8_t > tmp_in {0}
RingBuffer< uint8_t > tmp_out {0}
SingleBuffer< int16_t > tx_buffer {0}
AsyncUDP udp
bool udp_connected = false
VBan vban
int write_buffer_size = 8

Detailed Description

VBAN Audio Source and Sink for the ESP32. For further details please see https://vb-audio.com/Voicemeeter/vban.htm . Inspired by https://github.com/rkinnett/ESP32-VBAN-Audio-Source/tree/master and https://github.com/rkinnett/ESP32-VBAN-Network-Audio-Player.

Note
Supported only on Arduino ESP32 platforms with WiFi support!
Author
Phil Schatzmann

Member Function Documentation

◆ addNotifyAudioChange() [1/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ addNotifyAudioChange() [2/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ audioInfo() [1/2]

◆ audioInfo() [2/2]

◆ audioInfoOut() [1/2]

◆ audioInfoOut() [2/2]

◆ available()

int available ( )
inlinevirtual

Reimplemented from BaseStream.

◆ availableForWrite()

int availableForWrite ( )
inlinevirtual

Reimplemented from BaseStream.

◆ begin() [1/2]

bool begin ( )
inlinevirtual

Reimplemented from BaseStream.

◆ begin() [2/2]

bool begin ( VBANConfig cfg)
inline

◆ begin_rx()

bool begin_rx ( )
inlineprotected

◆ begin_tx()

bool begin_tx ( )
inlineprotected

◆ clearNotifyAudioChange() [1/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ clearNotifyAudioChange() [2/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ configure_tx()

bool configure_tx ( )
inlineprotected

◆ configure_vban()

void configure_vban ( VBanSampleRates rate)
inlineprotected

◆ defaultConfig()

VBANConfig defaultConfig ( RxTxMode mode = TX_MODE)
inline

◆ end() [1/2]

virtual void end ( )
inlinevirtualinherited

Reimplemented in A2DPStream, AbstractURLStream, AdapterAudioOutputToAudioStream, AdaptiveResamplingStream, AnalogAudioStream, AdapterAudioOutputToAudioStream, AudioStreamWrapper, AudioStreamWrapper, CallbackStream, CallbackStream, CatStream, CatStream, DynamicMemoryStream, DynamicMemoryStream, EncodedAudioStream, FilteredStream< T, TF >, FilteredStream< T, TF >, FilteredStream< int16_t, int16_t >, GeneratedSoundStream< T >, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, InputMerge< T >, InputMerge< T >, InputMixer< T, SumT >, InputMixer< T, SumT >, MemoryStream, MemoryStream, QueueStream< T >, QueueStream< T >, QueueStream< uint8_t >, ReformatBaseStream, TimerCallbackAudioStream, TimerCallbackAudioStream, AudioBLEClient, AudioBLEClient, AudioBLEServer, AudioBLEServer, AudioBLEStream, AudioEffectStream, AudioEffectStreamT< T >, AudioFFTBase, AudioKitStream, AudioLoRa, AudioMP34DT05, AudioStreamWrapper, AutomaticGainControlStream, BufferedTaskStream, CallbackStream, CatStream, ChannelFormatConverterStream, DynamicMemoryStream, EncodedAudioStream, Equalizer3BandsPerChannelT< T >, Equalizer3BandsPerChannelT< float >, Equalizer3BandsT< T >, Equalizer3BandsT< float >, EqualizerNBands< SampleT, AccT, NUM_TAPS, NUM_BANDS >, ESPNowStream, FaustStream< DSP >, FileLoopT< FileType >, FileLoopT< File >, FilteredStream< T, TF >, FormatConverterStream, GeneratedSoundStream< T >, GoertzelStream, HLSStreamT< URLStream >, HLSStreamT< URLStreamESP32 >, HttpRequest, I2SCodecStream, I2SStream, ICYStreamT< T >, ICYStreamT< URLStream >, ICYStreamT< URLStreamESP32 >, InputMerge< T >, InputMixer< T, SumT >, MemoryStream, MiniAudioStream, MozziStream, NRF24Stream, NumberFormatConverterStream, Pipeline, Pipeline::ModifyingStreamAdapter, PortAudioStream, PureDataStream, QueueStream< T >, ReformatBaseStream, SPDIFOutput, SPIAudioSlave, StdioStream, SupportedRatesStream, TimerCallbackAudioStream, URLStream, URLStreamBufferedT< T >, URLStreamBufferedT< ICYStream >, URLStreamBufferedT< ICYStreamESP32 >, URLStreamBufferedT< URLStream >, URLStreamBufferedT< URLStreamESP32 >, URLStreamESP32, USBAudioDeviceBase, USBAudioHostBase, VolumeStream, VS1053Stream, and WM8960Stream.

◆ end() [2/2]

virtual void end ( )
inlinevirtualinherited

Reimplemented in A2DPStream, AbstractURLStream, AdapterAudioOutputToAudioStream, AdaptiveResamplingStream, AnalogAudioStream, AdapterAudioOutputToAudioStream, AudioStreamWrapper, AudioStreamWrapper, CallbackStream, CallbackStream, CatStream, CatStream, DynamicMemoryStream, DynamicMemoryStream, EncodedAudioStream, FilteredStream< T, TF >, FilteredStream< T, TF >, FilteredStream< int16_t, int16_t >, GeneratedSoundStream< T >, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, InputMerge< T >, InputMerge< T >, InputMixer< T, SumT >, InputMixer< T, SumT >, MemoryStream, MemoryStream, QueueStream< T >, QueueStream< T >, QueueStream< uint8_t >, ReformatBaseStream, TimerCallbackAudioStream, TimerCallbackAudioStream, AudioBLEClient, AudioBLEClient, AudioBLEServer, AudioBLEServer, AudioBLEStream, AudioEffectStream, AudioEffectStreamT< T >, AudioFFTBase, AudioKitStream, AudioLoRa, AudioMP34DT05, AudioStreamWrapper, AutomaticGainControlStream, BufferedTaskStream, CallbackStream, CatStream, ChannelFormatConverterStream, DynamicMemoryStream, EncodedAudioStream, Equalizer3BandsPerChannelT< T >, Equalizer3BandsPerChannelT< float >, Equalizer3BandsT< T >, Equalizer3BandsT< float >, EqualizerNBands< SampleT, AccT, NUM_TAPS, NUM_BANDS >, ESPNowStream, FaustStream< DSP >, FileLoopT< FileType >, FileLoopT< File >, FilteredStream< T, TF >, FormatConverterStream, GeneratedSoundStream< T >, GoertzelStream, HLSStreamT< URLStream >, HLSStreamT< URLStreamESP32 >, HttpRequest, I2SCodecStream, I2SStream, ICYStreamT< T >, ICYStreamT< URLStream >, ICYStreamT< URLStreamESP32 >, InputMerge< T >, InputMixer< T, SumT >, MemoryStream, MiniAudioStream, MozziStream, NRF24Stream, NumberFormatConverterStream, Pipeline, Pipeline::ModifyingStreamAdapter, PortAudioStream, PureDataStream, QueueStream< T >, ReformatBaseStream, SPDIFOutput, SPIAudioSlave, StdioStream, SupportedRatesStream, TimerCallbackAudioStream, URLStream, URLStreamBufferedT< T >, URLStreamBufferedT< ICYStream >, URLStreamBufferedT< ICYStreamESP32 >, URLStreamBufferedT< URLStream >, URLStreamBufferedT< URLStreamESP32 >, URLStreamESP32, USBAudioDeviceBase, USBAudioHostBase, VolumeStream, VS1053Stream, and WM8960Stream.

◆ flush() [1/2]

◆ flush() [2/2]

◆ isNotifyActive() [1/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isNotifyActive() [2/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ not_supported() [1/2]

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

◆ not_supported() [2/2]

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

◆ notifyAudioChange() [1/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ notifyAudioChange() [2/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ operator bool() [1/2]

◆ operator bool() [2/2]

◆ readBytes()

size_t readBytes ( uint8_t * data,
size_t len )
inlineoverridevirtual

Reimplemented from AudioStream.

◆ readSilence() [1/2]

virtual size_t readSilence ( uint8_t * buffer,
size_t length )
inlinevirtualinherited

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

◆ readSilence() [2/2]

virtual size_t readSilence ( uint8_t * buffer,
size_t length )
inlinevirtualinherited

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

◆ receive_udp()

void receive_udp ( AsyncUDPPacket & packet)
inlineprotected

VBAN adjusts the number of samples per packet according to sample rate. Assuming 16-bit PCM mono, sample rates 11025, 22050, 44100, and 88200 yield packets containing 64, 128, 256, and 256 samples per packet, respectively. The even-thousands sample rates below 48000 yield non-power-of-2 lengths. For example, sample rate 24000 yields 139 samples per packet. This VBAN->DMA->DAC method seems to require the dma buffer length be set equal to the number of samples in each VBAN packet. ESP32 I2S/DMA does not seem to handle non-power-of-2 buffer lengths well. Sample rate 24000 doesn't work reliably at all. Sample rate 32000 is stable but stutters. Recommend selecting from sample rates 11025, 22050, 44100, and above And set samplesPerPacket to 64 for 11025, 128 for 22050, or 256 for all else.

◆ refillReadBuffer() [1/2]

void refillReadBuffer ( )
inlineprotectedinherited

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

◆ refillReadBuffer() [2/2]

void refillReadBuffer ( )
inlineprotectedinherited

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

◆ removeNotifyAudioChange() [1/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

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

◆ removeNotifyAudioChange() [2/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

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

◆ safe_strncpy()

void safe_strncpy ( char * dest,
const char * src,
size_t dest_size )
inlineprotected

◆ sendVbanPing0Reply()

void sendVbanPing0Reply ( AsyncUDPPacket & sourcePacket)
inlineprotected

◆ setAudioInfo() [1/2]

◆ setAudioInfo() [2/2]

void setAudioInfo ( AudioInfo info)
inlineoverride

◆ setNotifyActive() [1/2]

void setNotifyActive ( bool flag)
inlineinherited

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

◆ setNotifyActive() [2/2]

void setNotifyActive ( bool flag)
inlineinherited

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

◆ setOutput()

void setOutput ( Print & out)
inline

◆ setWriteBufferSize() [1/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ setWriteBufferSize() [2/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ start_wifi()

void start_wifi ( )
inlineprotected

◆ toString()

const char * toString ( IPAddress adr)
inlineprotected

◆ vban_sample_rate()

int vban_sample_rate ( )
inlineprotected

◆ write() [1/2]

◆ write() [2/2]

size_t write ( const uint8_t * data,
size_t len )
inlineoverridevirtual

Reimplemented from AudioStream.

◆ writeSilence() [1/2]

virtual void writeSilence ( size_t len)
inlinevirtualinherited

Writes len bytes of silence (=0).

◆ writeSilence() [2/2]

virtual void writeSilence ( size_t len)
inlinevirtualinherited

Writes len bytes of silence (=0).

Member Data Documentation

◆ _timeout

int _timeout = 10
protectedinherited

◆ available_active

bool available_active = false
protected

◆ broadcast_address

const IPAddress broadcast_address {0, 0, 0, 0}
protected

◆ bytes_received

size_t bytes_received = 0
protected

◆ cfg

VBANConfig cfg
protected

◆ info

AudioInfo info
protectedinherited

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector< AudioInfoSupport * > notify_vector
protectedinherited

◆ p_out

Print* p_out = nullptr
protected

◆ packet_counter

uint32_t packet_counter = 0
protected

◆ rx_buffer

BufferRTOS<uint8_t> rx_buffer { 0}
protected

◆ throttle

Throttle throttle
protected

◆ tmp_in

RingBuffer< uint8_t > tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer< uint8_t > tmp_out {0}
protectedinherited

◆ tx_buffer

SingleBuffer<int16_t> tx_buffer {0}
protected

◆ udp

AsyncUDP udp
protected

◆ udp_connected

bool udp_connected = false
protected

◆ vban

VBan vban
protected

◆ write_buffer_size

int write_buffer_size = 8
protectedinherited

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