arduino-audio-tools
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 bit buffer needs to be allocated. It is recommended to use the API with the callbacks. Examples can be found in the examples-basic-api directory. More...

#include <A2DPStream.h>

Inheritance diagram for A2DPStream:
AudioStream VolumeSupport Stream AudioInfoSupport AudioInfoSource Print

Public Member Functions

 ~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 ()
 provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
 
int available () override
 
int availableForWrite () override
 
virtual bool begin ()
 
bool begin (A2DPConfig cfg)
 Starts the processing.
 
bool begin (RxTxMode mode, const char *name)
 Starts the processing.
 
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)
 
bool setVolume (float volume) override
 define the actual volume in the range of 0.0f to 1.0f
 
BluetoothA2DPSink & sink ()
 provides access to the BluetoothA2DPSink
 
BluetoothA2DPSource & source ()
 provides access to the
 
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 ()
 

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
 

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 bit buffer needs to be allocated. It is recommended to use the API with the callbacks. Examples can be found in the examples-basic-api directory.

Requires: https://github.com/pschatzmann/ESP32-A2DP

Author
Phil Schatzmann

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