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

Stream support for A2DP using https://github.com/pschatzmann/ESP32-A2DP: begin(TX_MODE) opens a a2dp_source and begin(RX_MODE) a a2dp_sink. The data is in int16_t with 2 channels at 44100 hertz. We support only one instance of the class! Please note that this is a conveniance class that supports the stream api, however this is rather inefficient, beause quite a big buffer needs to be allocated. It is recommended to use the API with the callbacks. Examples can be found in the a2dp examples directory starting with basic. More...

#include <A2DPStream.h>

Inheritance diagram for A2DPStream:
AudioStream VolumeSupport BaseStream AudioInfoSupport AudioInfoSource BaseStream AudioInfoSupport AudioInfoSource Stream Stream Stream Stream Print Print Print Print Print Print Print Print

Public Member Functions

 A2DPStream ()
 ~A2DPStream ()
 Release the allocate a2dp_source or a2dp_sink.
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 () override
 Provides the number of bytes available to read.
int availableForWrite () override
 Provides the number of bytes available to write.
bool begin (A2DPConfig cfg)
 Starts the processing.
bool begin (RxTxMode mode, const char *name, bool wait_for_connection=true)
 Starts the processing.
virtual bool begin ()
BaseBuffer< uint8_t > & buffer ()
 Provides access to the buffer.
void clear ()
 Clears the buffer.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
A2DPConfig defaultConfig (RxTxMode mode=RX_MODE)
void end () override
virtual void flush () override
virtual void flush () override
bool isConnected ()
 checks if we are connected
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isReady ()
 is ready to process data
 operator bool ()
 convert to bool
size_t readBytes (uint8_t *data, size_t len) override
 Reads the data from the temporary buffer.
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.
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
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 setSilenceOnNoData (bool silence)
 Manage config.silence_on_nodata dynamically.
bool setVolume (float volume) override
 Define the volume (values between 0.0 and 1.0).
void setWriteBufferSize (int size)
void setWriteBufferSize (int size)
BluetoothA2DPSink & sink ()
 provides access to the BluetoothA2DPSink
BluetoothA2DPSource & source ()
 provides access to the BluetoothA2DPSource
virtual float volume ()
 provides the actual volume in the range of 0.0f to 1.0f
virtual float volume ()
 provides the actual volume in the range of 0.0f to 1.0f
size_t write (const uint8_t *data, size_t len) override
 Writes the data into a temporary send buffer - where it can be picked up by the callback.
virtual size_t write (uint8_t ch) 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

virtual int not_supported (int out, const char *msg="")
virtual int not_supported (int out, const char *msg="")
void notify_base_Info (int rate)
 notify subscriber with AudioInfo
void notifyAudioChange (AudioInfo info)
void notifyAudioChange (AudioInfo info)
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().

Static Protected Member Functions

static void a2dp_state_callback (esp_a2d_connection_state_t state, void *caller)
static void a2dp_stream_sink_sound_data (const uint8_t *data, uint32_t len)
 callback used by A2DP to write the sound data
static int32_t a2dp_stream_source_sound_data (uint8_t *data, int32_t len)
static bool detected_device (const char *ssid, esp_bd_addr_t address, int rssi)
static void sample_rate_callback (uint16_t rate)
 callback to update audio info with used a2dp sample rate

Protected Attributes

int _timeout = 10
BluetoothA2DPCommon * a2dp =nullptr
const int A2DP_MAX_VOL = 128
BluetoothA2DPSink * a2dp_sink = nullptr
BluetoothA2DPSource * a2dp_source = nullptr
A2DPConfig config
AudioInfo info
bool is_notify_active = true
Vector< AudioInfoSupport * > notify_vector
RingBuffer< uint8_t > tmp_in {0}
RingBuffer< uint8_t > tmp_out {0}
float volume_value = 1.0f
int write_buffer_size = 8

Detailed Description

Stream support for A2DP using https://github.com/pschatzmann/ESP32-A2DP: begin(TX_MODE) opens a a2dp_source and begin(RX_MODE) a a2dp_sink. The data is in int16_t with 2 channels at 44100 hertz. We support only one instance of the class! Please note that this is a conveniance class that supports the stream api, however this is rather inefficient, beause quite a big buffer needs to be allocated. It is recommended to use the API with the callbacks. Examples can be found in the a2dp examples directory starting with basic.

Note
Supported only on EP32 (via Arduino and IDF)
Requires: https://github.com/pschatzmann/ESP32-A2DP
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ A2DPStream()

A2DPStream ( )
inline

◆ ~A2DPStream()

~A2DPStream ( )
inline

Release the allocate a2dp_source or a2dp_sink.

Member Function Documentation

◆ a2dp_state_callback()

void a2dp_state_callback ( esp_a2d_connection_state_t state,
void * caller )
inlinestaticprotected

◆ a2dp_stream_sink_sound_data()

void a2dp_stream_sink_sound_data ( const uint8_t * data,
uint32_t len )
inlinestaticprotected

callback used by A2DP to write the sound data

◆ a2dp_stream_source_sound_data()

int32_t a2dp_stream_source_sound_data ( uint8_t * data,
int32_t len )
inlinestaticprotected

◆ 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 ( )
inlineoverridevirtual

Provides the number of bytes available to read.

Reimplemented from BaseStream.

◆ availableForWrite()

int availableForWrite ( )
inlineoverridevirtual

Provides the number of bytes available to write.

Reimplemented from BaseStream.

◆ begin() [1/3]

bool begin ( A2DPConfig cfg)
inline

Starts the processing.

◆ begin() [2/3]

bool begin ( RxTxMode mode,
const char * name,
bool wait_for_connection = true )
inline

Starts the processing.

◆ begin() [3/3]

virtual bool begin ( )
inlinevirtualinherited

Reimplemented in AdapterAudioOutputToAudioStream, AdaptiveResamplingStream, AnalogAudioStream, AdapterAudioOutputToAudioStream, AudioInputMonitor, AudioInputMonitor, AudioStreamWrapper, AudioStreamWrapper, AudioTimeSourceStream, CallbackStream, CallbackStream, CatStream, CatStream, DynamicMemoryStream, DynamicMemoryStream, EncodedAudioStream, FilteredStream< T, TF >, FilteredStream< T, TF >, GeneratedSoundStream< T >, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, InputMerge< T >, InputMerge< T >, MemoryStream, MemoryStream, ProgressStream, ProgressStream, QueueStream< T >, QueueStream< T >, QueueStream< uint8_t >, Throttle, Throttle, TimedStream, TimerCallbackAudioStream, TimerCallbackAudioStream, VolumeMeter, VolumeMeter, AudioBoardStream, AudioEffectStream, AudioEffectStreamT< T >, AudioFFTBase, AudioInputMonitor, AudioKitStream, AudioLoRa, AudioMP34DT05, AudioOutputWithCallback, AudioStreamWrapper, AudioTimeSourceStream, AutomaticGainControlStream, CallbackStream, CatStream, ChannelFormatConverterStream, ChannelFormatConverterStreamT< T >, DynamicMemoryStream, EncodedAudioStream, Equalizer3BandsPerChannelT< T >, Equalizer3BandsPerChannelT< float >, Equalizer3BandsT< T >, Equalizer3BandsT< float >, EqualizerNBands< SampleT, AccT, NUM_TAPS, NUM_BANDS >, ESPNowStream, FileLoopT< FileType >, FileLoopT< File >, FilteredStream< T, TF >, FormatConverterStream, FrequencyDetectorAutoCorrelation, GeneratedSoundStream< T >, GoertzelStream, HLSStreamT< URLStream >, HLSStreamT< URLStreamESP32 >, I2SCodecStream, I2SStream, InputMerge< T >, MeasuringStream, MemoryStream, MiniAudioStream, MozziStream, NRF24Stream, NumberFormatConverterStream, NumberFormatConverterStreamT< TFrom, TTo >, Pipeline, Pipeline::ModifyingStreamAdapter, PortAudioStream, ProgressStream, PureDataStream, QualityAnalysisStream, QueueStream< T >, ResampleStream, ResampleStreamT< TInterpolator >, SPDIFOutput, StdioStream, SupportedRatesStream, Throttle, TimedStream, TimerCallbackAudioStream, USBAudioDeviceBase, USBAudioHostBase, VBANStream, VolumeMeter, VolumeStream, VS1053Stream, and WM8960Stream.

◆ buffer()

BaseBuffer< uint8_t > & buffer ( )
inline

Provides access to the buffer.

◆ clear()

void clear ( )
inline

Clears the buffer.

◆ clearNotifyAudioChange() [1/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ clearNotifyAudioChange() [2/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ defaultConfig()

A2DPConfig defaultConfig ( RxTxMode mode = RX_MODE)
inline

◆ detected_device()

bool detected_device ( const char * ssid,
esp_bd_addr_t address,
int rssi )
inlinestaticprotected

◆ end()

void end ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ flush() [1/2]

◆ flush() [2/2]

◆ isConnected()

bool isConnected ( )
inline

checks if we are connected

◆ 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.

◆ isReady()

bool isReady ( )
inline

is ready to process data

◆ 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

◆ notify_base_Info()

void notify_base_Info ( int rate)
inlineprotected

notify subscriber with AudioInfo

◆ notifyAudioChange() [1/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ notifyAudioChange() [2/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ operator bool()

operator bool ( )
inlinevirtual

convert to bool

Reimplemented from AudioStream.

◆ readBytes()

size_t readBytes ( uint8_t * data,
size_t len )
inlineoverridevirtual

Reads the data from the temporary buffer.

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.

◆ 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.

◆ sample_rate_callback()

void sample_rate_callback ( uint16_t rate)
inlinestaticprotected

callback to update audio info with used a2dp sample rate

◆ setAudioInfo() [1/2]

◆ setAudioInfo() [2/2]

◆ 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).

◆ setSilenceOnNoData()

void setSilenceOnNoData ( bool silence)
inline

Manage config.silence_on_nodata dynamically.

◆ setVolume()

bool setVolume ( float volume)
inlineoverridevirtual

Define the volume (values between 0.0 and 1.0).

Reimplemented from VolumeSupport.

◆ setWriteBufferSize() [1/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ setWriteBufferSize() [2/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ sink()

BluetoothA2DPSink & sink ( )
inline

provides access to the BluetoothA2DPSink

◆ source()

BluetoothA2DPSource & source ( )
inline

provides access to the BluetoothA2DPSource

◆ volume() [1/2]

virtual float volume ( )
inlinevirtualinherited

provides the actual volume in the range of 0.0f to 1.0f

Reimplemented in AudioPlayer, I2SCodecStream, USBAudioStreamBase, VolumeStream, and VS1053Stream.

◆ volume() [2/2]

virtual float volume ( )
inlinevirtualinherited

provides the actual volume in the range of 0.0f to 1.0f

Reimplemented in AudioPlayer, I2SCodecStream, USBAudioStreamBase, VolumeStream, and VS1053Stream.

◆ write() [1/2]

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

Writes the data into a temporary send buffer - where it can be picked up by the callback.

Reimplemented from AudioStream.

◆ write() [2/2]

◆ 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

◆ a2dp

BluetoothA2DPCommon* a2dp =nullptr
protected

◆ A2DP_MAX_VOL

const int A2DP_MAX_VOL = 128
protected

◆ a2dp_sink

BluetoothA2DPSink* a2dp_sink = nullptr
protected

◆ a2dp_source

BluetoothA2DPSource* a2dp_source = nullptr
protected

◆ config

A2DPConfig config
protected

◆ info

AudioInfo info
protectedinherited

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector< AudioInfoSupport * > notify_vector
protectedinherited

◆ tmp_in

RingBuffer< uint8_t > tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer< uint8_t > tmp_out {0}
protectedinherited

◆ volume_value

float volume_value = 1.0f
protectedinherited

◆ write_buffer_size

int write_buffer_size = 8
protectedinherited

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