arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
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 Stream 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 AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
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.
 
virtual bool begin ()
 
bool begin (A2DPConfig cfg)
 Starts the processing.
 
bool begin (RxTxMode mode, const char *name, bool wait_for_connection=true)
 Starts the processing.
 
BaseBuffer< uint8_t > & buffer ()
 Provides access to the buffer.
 
void clear ()
 Clears the buffer.
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
A2DPConfig defaultConfig (RxTxMode mode=RX_MODE)
 
void end () override
 
virtual void flush () override
 
bool isConnected ()
 checks if we are connected
 
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 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 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)
 
BluetoothA2DPSinksink ()
 provides access to the BluetoothA2DPSink
 
BluetoothA2DPSourcesource ()
 provides access to the BluetoothA2DPSource
 
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).
 

Protected Member Functions

virtual int not_supported (int out, const char *msg="")
 
void notify_base_Info (int rate)
 notify subscriber with AudioInfo
 
void notifyAudioChange (AudioInfo info)
 
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
 
BluetoothA2DPCommona2dp =nullptr
 
const int A2DP_MAX_VOL = 128
 
BluetoothA2DPSinka2dp_sink = nullptr
 
BluetoothA2DPSourcea2dp_source = nullptr
 
A2DPConfig config
 
AudioInfo info
 
bool is_notify_active = true
 
Vector< AudioInfoSupport * > notify_vector
 
RingBuffer< uint8_ttmp_in {0}
 
RingBuffer< uint8_ttmp_out {0}
 
float volume_value = 1.0f
 
int write_buffer_size = MAX_SINGLE_CHARS
 

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.

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

static void a2dp_state_callback ( esp_a2d_connection_state_t  state,
void caller 
)
inlinestaticprotected

◆ a2dp_stream_sink_sound_data()

static 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()

static int32_t a2dp_stream_source_sound_data ( uint8_t data,
int32_t  len 
)
inlinestaticprotected

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

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

virtual bool begin ( )
inlinevirtualinherited

◆ begin() [2/3]

bool begin ( A2DPConfig  cfg)
inline

Starts the processing.

◆ begin() [3/3]

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

Starts the processing.

◆ buffer()

BaseBuffer< uint8_t > & buffer ( )
inline

Provides access to the buffer.

◆ clear()

void clear ( )
inline

Clears the buffer.

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ defaultConfig()

A2DPConfig defaultConfig ( RxTxMode  mode = RX_MODE)
inline

◆ detected_device()

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

◆ end()

void end ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

◆ isConnected()

bool isConnected ( )
inline

checks if we are connected

◆ isNotifyActive()

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isReady()

bool isReady ( )
inline

is ready to process data

◆ not_supported()

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

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

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

◆ sample_rate_callback()

static void sample_rate_callback ( uint16_t  rate)
inlinestaticprotected

callback to update audio info with used a2dp sample rate

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlineoverridevirtualinherited

◆ setNotifyActive()

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

void setWriteBufferSize ( int  size)
inlineinherited

◆ sink()

BluetoothA2DPSink & sink ( )
inline

provides access to the BluetoothA2DPSink

◆ source()

BluetoothA2DPSource & source ( )
inline

provides access to the BluetoothA2DPSource

◆ volume()

virtual float volume ( )
inlinevirtualinherited

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

Reimplemented in I2SCodecStream, VS1053Stream, AudioPlayer, and VolumeStream.

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

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

◆ 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 = MAX_SINGLE_CHARS
protectedinherited

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