From 478aca9cfa8be825350db53fefa9330dafc8a4fd Mon Sep 17 00:00:00 2001 From: Phil Schatzmann Date: Sat, 6 Apr 2024 23:09:38 +0200 Subject: [PATCH] Dev (#535) * Output to AudioTools * AudioKit example * Update example to use new API * doxygen * Examples add header * Warining if AudioTools is not installed * Do not use legacy I2S when p_print is defined. * BluetoothA2DPSinkQueued legacy only when p_print == nullptr * Setup actual_bluetooth_a2dp_sink = this; * doxygen * Doxygen remove legacy API * Remove is_i2s_output * BluetoothA2DPSinkQueued add missing constructors * add delay(1) on i2s_write_data * doxygen --- Doxyfile | 2 +- README.md | 92 +- docs/html/_bluetooth_a2_d_p_common_8h.html | 1 - .../_bluetooth_a2_d_p_common_8h_source.html | 2 +- .../_bluetooth_a2_d_p_sink_8h_source.html | 825 +- ...luetooth_a2_d_p_sink_queued_8h_source.html | 179 +- .../class_bluetooth_a2_d_p_sink-members.html | 237 +- docs/html/class_bluetooth_a2_d_p_sink.html | 57 +- ..._bluetooth_a2_d_p_sink_queued-members.html | 160 +- .../class_bluetooth_a2_d_p_sink_queued.html | 53 +- docs/html/config_8h_source.html | 17 +- docs/html/functions.html | 18 +- docs/html/functions_func.html | 18 +- docs/html/index.html | 132 +- docs/html/search/all_1.js | 4 +- docs/html/search/all_10.js | 2 +- docs/html/search/all_11.js | 4 +- docs/html/search/all_12.js | 6 +- docs/html/search/all_e.js | 85 +- docs/html/search/all_f.js | 6 +- docs/html/search/classes_0.js | 10 +- docs/html/search/classes_1.js | 10 +- docs/html/search/classes_2.js | 4 +- docs/html/search/classes_3.js | 2 +- docs/html/search/classes_4.js | 2 +- docs/html/search/files_0.js | 4 +- docs/html/search/functions_0.js | 4 +- docs/html/search/functions_1.js | 19 +- docs/html/search/functions_10.js | 2 +- docs/html/search/functions_11.js | 4 +- docs/html/search/functions_12.js | 6 +- docs/html/search/functions_2.js | 6 +- docs/html/search/functions_3.js | 8 +- docs/html/search/functions_4.js | 2 +- docs/html/search/functions_5.js | 2 +- docs/html/search/functions_6.js | 24 +- docs/html/search/functions_7.js | 2 +- docs/html/search/functions_8.js | 12 +- docs/html/search/functions_9.js | 2 +- docs/html/search/functions_a.js | 2 +- docs/html/search/functions_b.js | 4 +- docs/html/search/functions_c.js | 8 +- docs/html/search/functions_d.js | 6 +- docs/html/search/functions_e.js | 99 +- docs/html/search/functions_f.js | 6 +- docs/html/search/groups_0.js | 2 +- docs/html/search/pages_0.js | 2 +- docs/html/search/related_0.js | 20 +- docs/html/search/typedefs_0.js | 2 +- docs/html/search/variables_0.js | 2 +- docs/html/search/variables_1.js | 2 +- docs/html/search/variables_2.js | 2 +- docs/html/search/variables_3.js | 2 +- .../BluetoothA2DPSink32.h | 50 - .../bt_music_receiver_32bit_ext.ino | 31 - .../bt_music_receiver_and_BLE.ino | 20 +- .../bt_music_receiver_arduino_i2s.ino} | 21 +- .../bt_music_receiver_audiokit.ino | 26 +- .../bt_music_receiver_queued.ino | 5 +- .../bt_music_receiver_reconnect.ino | 13 +- .../bt_music_receiver_rssi.ino | 17 +- .../bt_music_receiver_simple.ino | 5 +- examples/bt_music_receiver_simple/debug.cfg | 14 - .../debug_custom.json | 19 - examples/bt_music_receiver_simple/esp32.svd | 46087 ---------------- .../bt_music_receiver_simple_with_pin.ino | 29 +- .../bt_music_receiver_status_callback.ino | 4 +- .../bt_music_receiver_to_internal_dac.ino | 18 +- .../bt_music_receiver_with_auto_shutdown.ino | 27 +- .../bt_music_receiver_with_metadata.ino | 18 +- src/BluetoothA2DPCommon.h | 2 +- src/BluetoothA2DPSink.cpp | 2295 +- src/BluetoothA2DPSink.h | 68 +- src/BluetoothA2DPSinkQueued.cpp | 11 +- src/BluetoothA2DPSinkQueued.h | 165 +- src/config.h | 11 +- 76 files changed, 2509 insertions(+), 48631 deletions(-) delete mode 100644 examples/bt_music_receiver_32bit_ext/BluetoothA2DPSink32.h delete mode 100644 examples/bt_music_receiver_32bit_ext/bt_music_receiver_32bit_ext.ino rename examples/{bt_music_receiver_32bit/bt_music_receiver_32bit.ino => bt_music_receiver_arduino_i2s/bt_music_receiver_arduino_i2s.ino} (65%) delete mode 100644 examples/bt_music_receiver_simple/debug.cfg delete mode 100644 examples/bt_music_receiver_simple/debug_custom.json delete mode 100644 examples/bt_music_receiver_simple/esp32.svd diff --git a/Doxyfile b/Doxyfile index 1fad4006..e77cfca6 100644 --- a/Doxyfile +++ b/Doxyfile @@ -2216,7 +2216,7 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = ESP_IDF_4 A2DP_I2S_SUPPORT +PREDEFINED = ESP_IDF_4 ARDUINO A2DP_I2S_AUDIOTOOLS # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The diff --git a/README.md b/README.md index bcbd7522..e89bd0ba 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,14 @@ It also supports Audio/Video Remote Control Profile (AVRCP) together with A2DP. The Hands-Free Profile (HFP), Headset Profile (HSP) and stand alone AVRCP without A2DP are __not__ supported! +## I2S API / Dependencies + +Espressif is retiring the legacy I2S API: So with Arduino 3.0.0 [my old I2S integration](https://github.com/pschatzmann/ESP32-A2DP/wiki/Legacy-I2S-API) will not be available any more. + +In order to support a unique output API which is version independent, it is recommended to install and use the [AudioTools](https://github.com/pschatzmann/arduino-audio-tools) library. + +However you can output to any other class which inherits from Arduino Print: e.g. the Arduino ESP32 I2SClass. + ## A2DP Sink (Music Receiver) @@ -27,9 +35,11 @@ This can be used e.g. to build your own Bluetooth Speaker. Here is the simplest example which just uses the proper default settings: ``` +#include "AudioTools.h #include "BluetoothA2DPSink.h" -BluetoothA2DPSink a2dp_sink; +I2SStream i2s; +BluetoothA2DPSink a2dp_sink(i2s); void setup() { a2dp_sink.start("MyMusic"); @@ -38,30 +48,32 @@ void setup() { void loop() { } ``` -This creates a new Bluetooth device with the name “MyMusic” and the output will be sent to the following default I2S pins which need to be conected to an external DAC: -- bck_io_num = 26 -- ws_io_num = 25 +This creates a new Bluetooth device with the name “MyMusic” and the output will be sent to the following default I2S pins which need to be connected to an external DAC: + +- bck_io_num = 14 +- ws_io_num = 15 - data_out_num = 22 +Please note that these default pins have changed compared to the legacy API! ### Defining Pins -You can define your own pins easily by calling the ```set_pin_config``` method in the setup before the ```start```. +You can define your own pins easily before the ```start```. ``` +#include "AudioTools.h #include "BluetoothA2DPSink.h" -BluetoothA2DPSink a2dp_sink; +I2SStream i2s; +BluetoothA2DPSink a2dp_sink(i2s); void setup() { - i2s_pin_config_t my_pin_config = { - .mck_io_num = I2S_PIN_NO_CHANGE, - .bck_io_num = 26, - .ws_io_num = 25, - .data_out_num = 22, - .data_in_num = I2S_PIN_NO_CHANGE - }; - a2dp_sink.set_pin_config(my_pin_config); + auto cfg = i2s.defaultConfig(); + cfg.pin_bck = 14; + cfg.pin_ws = 15; + cfg.pin_data = 22; + i2s.begin(cfg); + a2dp_sink.start("MyMusic"); } @@ -69,62 +81,46 @@ void loop() { } ``` -### Using your specific i2s_config +### Output Using the ESP32 I2S API -In some cases you might want to use your specific i2s_config settings. E.g. to request a different bits_per_sample (e.g. 32) or to use the use_apll or to optimize the dma buffer... +You can also use the Arduino ESP32 I2S API: You do not need to install any additional library for this. ``` +#include "I2S.h" #include "BluetoothA2DPSink.h" -BluetoothA2DPSink a2dp_sink; +BluetoothA2DPSink a2dp_sink(I2S); void setup() { + I2S.setSckPin(14); + I2S.setFsPin(15); + I2S.setDataPin(22); + if (!I2S.begin(I2S_PHILIPS_MODE, 44100, 16)) { + Serial.println("Failed to initialize I2S!"); + while (1); // do nothing + } - static i2s_config_t i2s_config = { - .mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_TX), - .sample_rate = 44100, // updated automatically by A2DP - .bits_per_sample = (i2s_bits_per_sample_t)32, - .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, - .communication_format = (i2s_comm_format_t) (I2S_COMM_FORMAT_STAND_I2S), - .intr_alloc_flags = 0, // default interrupt priority - .dma_buf_count = 8, - .dma_buf_len = 64, - .use_apll = true, - .tx_desc_auto_clear = true // avoiding noise in case of data unavailability - }; - a2dp_sink.set_i2s_config(i2s_config); - a2dp_sink.start("MyMusic"); + a2dp_sink.start("MyMusic"); } void loop() { } - ``` + ### Output to the Internal DAC -You can also send the output directly to the internal DAC of the ESP32 by providing the corresponding i2s_config: + +You can also send the output directly to the internal DAC of the ESP32 by using the AnalogAudioStream fro the AudioTools: ``` +#include "AudioTools.h #include "BluetoothA2DPSink.h" -BluetoothA2DPSink a2dp_sink; +AnalogAudioStream out; +BluetoothA2DPSink a2dp_sink(out); void setup() { - static const i2s_config_t i2s_config = { - .mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN), - .sample_rate = 44100, // corrected by info from bluetooth - .bits_per_sample = (i2s_bits_per_sample_t) 16, /* the DAC module will only take the 8bits from MSB */ - .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, - .communication_format = (i2s_comm_format_t)I2S_COMM_FORMAT_STAND_MSB, - .intr_alloc_flags = 0, // default interrupt priority - .dma_buf_count = 8, - .dma_buf_len = 64, - .use_apll = false - }; - - a2dp_sink.set_i2s_config(i2s_config); a2dp_sink.start("MyMusic"); - } void loop() { diff --git a/docs/html/_bluetooth_a2_d_p_common_8h.html b/docs/html/_bluetooth_a2_d_p_common_8h.html index 3c8f7daf..543095ce 100644 --- a/docs/html/_bluetooth_a2_d_p_common_8h.html +++ b/docs/html/_bluetooth_a2_d_p_common_8h.html @@ -102,7 +102,6 @@ #include "SoundData.h"
#include "A2DPVolumeControl.h"
#include "esp_task_wdt.h"
-#include "driver/i2s.h"
#include "esp_log.h"

Go to the source code of this file.

diff --git a/docs/html/_bluetooth_a2_d_p_common_8h_source.html b/docs/html/_bluetooth_a2_d_p_common_8h_source.html index 0af35d97..5946d6d9 100644 --- a/docs/html/_bluetooth_a2_d_p_common_8h_source.html +++ b/docs/html/_bluetooth_a2_d_p_common_8h_source.html @@ -122,7 +122,7 @@
59 #include "A2DPVolumeControl.h"
60 #include "esp_task_wdt.h"
61 
-
62 #if A2DP_I2S_SUPPORT
+
62 #if A2DP_LEGACY_I2S_SUPPORT
63 # include "driver/i2s.h"
64 #endif
65 
diff --git a/docs/html/_bluetooth_a2_d_p_sink_8h_source.html b/docs/html/_bluetooth_a2_d_p_sink_8h_source.html index a5c51b42..327283a7 100644 --- a/docs/html/_bluetooth_a2_d_p_sink_8h_source.html +++ b/docs/html/_bluetooth_a2_d_p_sink_8h_source.html @@ -89,359 +89,398 @@
18 #include "BluetoothA2DPCommon.h"
19 #include "freertos/ringbuf.h"
20 
-
21 #ifdef __cplusplus
-
22 extern "C" {
+
21 #ifdef ARDUINO
+
22 # include "Print.h"
23 #endif
24 
-
25 #define APP_SIG_WORK_DISPATCH (0x01)
-
26 
-
27 #ifndef BT_AV_TAG
-
28 #define BT_AV_TAG "BT_AV"
-
29 #endif
-
30 
-
31 /* @brief event for handler "bt_av_hdl_stack_up */
-
32 enum {
-
33  BT_APP_EVT_STACK_UP = 0,
-
34 };
-
35 
-
36 extern "C" void ccall_app_a2d_callback(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param);
-
37 extern "C" void ccall_app_rc_ct_callback(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
-
38 extern "C" void ccall_app_gap_callback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param);
-
39 extern "C" void ccall_app_task_handler(void *arg);
-
40 extern "C" void ccall_i2s_task_handler(void *arg);
-
41 extern "C" void ccall_audio_data_callback(const uint8_t *data, uint32_t len);
-
42 extern "C" void ccall_av_hdl_stack_evt(uint16_t event, void *p_param);
-
43 extern "C" void ccall_av_hdl_a2d_evt(uint16_t event, void *p_param);
-
44 extern "C" void ccall_av_hdl_avrc_evt(uint16_t event, void *p_param);
-
45 
-
46 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
-
47 extern "C" void ccall_app_rc_tg_callback(esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param);
-
48 extern "C" void ccall_av_hdl_avrc_tg_evt(uint16_t event, void *p_param);
-
49 #endif
-
50 
-
51 // defines the mechanism to confirm a pin request
-
52 enum PinCodeRequest {Undefined, Confirm, Reply};
+
25 #if A2DP_I2S_AUDIOTOOLS
+
26 # include "AudioTools.h"
+
27 #endif
+
28 
+
29 #ifdef __cplusplus
+
30 extern "C" {
+
31 #endif
+
32 
+
33 #define APP_SIG_WORK_DISPATCH (0x01)
+
34 
+
35 #ifndef BT_AV_TAG
+
36 #define BT_AV_TAG "BT_AV"
+
37 #endif
+
38 
+
39 /* @brief event for handler "bt_av_hdl_stack_up */
+
40 enum {
+
41  BT_APP_EVT_STACK_UP = 0,
+
42 };
+
43 
+
44 extern "C" void ccall_app_a2d_callback(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param);
+
45 extern "C" void ccall_app_rc_ct_callback(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
+
46 extern "C" void ccall_app_gap_callback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param);
+
47 extern "C" void ccall_app_task_handler(void *arg);
+
48 extern "C" void ccall_i2s_task_handler(void *arg);
+
49 extern "C" void ccall_audio_data_callback(const uint8_t *data, uint32_t len);
+
50 extern "C" void ccall_av_hdl_stack_evt(uint16_t event, void *p_param);
+
51 extern "C" void ccall_av_hdl_a2d_evt(uint16_t event, void *p_param);
+
52 extern "C" void ccall_av_hdl_avrc_evt(uint16_t event, void *p_param);
53 
-
63 class BluetoothA2DPSink : public BluetoothA2DPCommon {
-
64 
-
66  friend void ccall_app_a2d_callback(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param);
-
68  friend void ccall_app_rc_ct_callback(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
-
70  friend void ccall_app_gap_callback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param);
-
72  friend void ccall_app_task_handler(void *arg);
-
74  friend void ccall_i2s_task_handler(void *arg);
-
76  friend void ccall_audio_data_callback(const uint8_t *data, uint32_t len);
-
78  friend void ccall_av_hdl_stack_evt(uint16_t event, void *p_param);
-
80  friend void ccall_av_hdl_a2d_evt(uint16_t event, void *p_param);
-
82  friend void ccall_av_hdl_avrc_evt(uint16_t event, void *p_param);
-
83 
-
84 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
-
85 
-
87  friend void ccall_app_rc_tg_callback(esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param);
-
88  /* avrc TG event handler */
-
89  friend void ccall_av_hdl_avrc_tg_evt(uint16_t event, void *p_param);
-
90 
-
91 #endif
-
92 
-
93  public:
-
95  BluetoothA2DPSink();
-
97  virtual ~BluetoothA2DPSink();
-
98 
-
99 #if A2DP_I2S_SUPPORT
-
101  virtual void set_pin_config(i2s_pin_config_t pin_config);
-
102 
-
104  virtual void set_i2s_port(i2s_port_t i2s_num);
-
105 
-
107  virtual void set_i2s_config(i2s_config_t i2s_config);
+
54 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
+
55 extern "C" void ccall_app_rc_tg_callback(esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param);
+
56 extern "C" void ccall_av_hdl_avrc_tg_evt(uint16_t event, void *p_param);
+
57 #endif
+
58 
+
59 // defines the mechanism to confirm a pin request
+
60 enum PinCodeRequest {Undefined, Confirm, Reply};
+
61 
+
62 // provide global ref for callbacks
+
63 class BluetoothA2DPSink;
+
64 extern BluetoothA2DPSink *actual_bluetooth_a2dp_sink;
+
65 
+
75 class BluetoothA2DPSink : public BluetoothA2DPCommon {
+
76 
+
78  friend void ccall_app_a2d_callback(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param);
+
80  friend void ccall_app_rc_ct_callback(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
+
82  friend void ccall_app_gap_callback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param);
+
84  friend void ccall_app_task_handler(void *arg);
+
86  friend void ccall_i2s_task_handler(void *arg);
+
88  friend void ccall_audio_data_callback(const uint8_t *data, uint32_t len);
+
90  friend void ccall_av_hdl_stack_evt(uint16_t event, void *p_param);
+
92  friend void ccall_av_hdl_a2d_evt(uint16_t event, void *p_param);
+
94  friend void ccall_av_hdl_avrc_evt(uint16_t event, void *p_param);
+
95 
+
96 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
+
97 
+
99  friend void ccall_app_rc_tg_callback(esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param);
+
100  /* avrc TG event handler */
+
101  friend void ccall_av_hdl_avrc_tg_evt(uint16_t event, void *p_param);
+
102 
+
103 #endif
+
104 
+
105  public:
+
107  BluetoothA2DPSink();
108 
-
110  virtual void set_channels(i2s_channel_t channels) {
-
111  set_mono_downmix(channels==I2S_CHANNEL_MONO);
-
112  }
-
113 
-
115  virtual void set_bits_per_sample(int bps) { i2s_config.bits_per_sample = (i2s_bits_per_sample_t) bps; }
-
116 
-
117 #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 1)
-
118  virtual esp_err_t i2s_mclk_pin_select(const uint8_t pin);
-
119 #endif
-
120 
-
121 #endif
-
122 
-
124  virtual void start(const char* name, bool auto_reconect);
-
125 
-
127  virtual void start(const char* name);
-
128 
-
130  virtual void end(bool release_memory=false);
-
131 
-
133  virtual esp_a2d_mct_t get_audio_type();
-
134 
-
136  virtual void set_avrc_connection_state_callback(void (*callback)(bool)) {
-
137  this->avrc_connection_state_callback = callback;
-
138  }
-
139 
-
141  virtual void set_avrc_metadata_callback(void (*callback)(uint8_t, const uint8_t*)) {
-
142  this->avrc_metadata_callback = callback;
-
143  }
-
144 
-
145 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
-
147  virtual void set_avrc_rn_playstatus_callback(void (*callback)(esp_avrc_playback_stat_t playback)) {
-
148  this->avrc_rn_playstatus_callback = callback;
+
109 #if A2DP_I2S_AUDIOTOOLS
+
111  BluetoothA2DPSink(AudioOutput &output){
+
112  actual_bluetooth_a2dp_sink = this;
+
113  p_print = &output;
+
114  p_audio_print = &output;
+
115  }
+
117  BluetoothA2DPSink(AudioStream &output){
+
118  actual_bluetooth_a2dp_sink = this;
+
119  static AdapterAudioStreamToAudioOutput adapter(output);
+
120  p_print = &output;
+
121  p_audio_print = &adapter;
+
122  }
+
123 #endif
+
124 
+
125 #ifdef ARDUINO
+
127  BluetoothA2DPSink(Print &output){
+
128  actual_bluetooth_a2dp_sink = this;
+
129  p_print = &output;
+
130  }
+
131 #endif
+
132 
+
134  virtual ~BluetoothA2DPSink();
+
135 
+
136 #if A2DP_LEGACY_I2S_SUPPORT
+
138  virtual void set_pin_config(i2s_pin_config_t pin_config);
+
139 
+
141  virtual void set_i2s_port(i2s_port_t i2s_num);
+
142 
+
144  virtual void set_i2s_config(i2s_config_t i2s_config);
+
145 
+
147  virtual void set_channels(i2s_channel_t channels) {
+
148  set_mono_downmix(channels==I2S_CHANNEL_MONO);
149  }
-
150 #endif
-
151 
-
153  virtual void set_sample_rate_callback(void (*callback)(uint16_t rate)) {
-
154  this->sample_rate_callback = callback;
-
155  }
-
156 
-
158  virtual void set_stream_reader(void (*callBack)(const uint8_t*, uint32_t), bool i2s_output=true);
+
150 
+
152  virtual void set_bits_per_sample(int bps) { i2s_config.bits_per_sample = (i2s_bits_per_sample_t) bps; }
+
153 
+
154 #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 1)
+
155  virtual esp_err_t i2s_mclk_pin_select(const uint8_t pin);
+
156 #endif
+
157 
+
158 #endif
159 
-
161  virtual void set_raw_stream_reader(void (*callBack)(const uint8_t*, uint32_t));
+
161  virtual void start(const char* name, bool auto_reconect);
162 
-
164  virtual void set_on_data_received(void (*callBack)());
-
165 
-
167  virtual void set_address_validator(bool (*callBack)(esp_bd_addr_t remote_bda)){
-
168  address_validator = callBack;
-
169  }
-
170 
-
172  virtual bool is_avrc_connected();
-
173 
-
175  virtual void set_volume(uint8_t volume);
-
176 
-
178  virtual int get_volume();
-
179 
-
181  virtual void set_on_volumechange(void (*callBack)(int));
-
182 
-
184  virtual void set_avrc_rn_volumechange(void (*callBack)(int));
-
185 
-
187  virtual void set_avrc_rn_volumechange_completed(void (*callBack)(int));
+
164  virtual void start(const char* name);
+
165 
+
167  virtual void end(bool release_memory=false);
+
168 
+
170  virtual esp_a2d_mct_t get_audio_type();
+
171 
+
173  virtual void set_avrc_connection_state_callback(void (*callback)(bool)) {
+
174  this->avrc_connection_state_callback = callback;
+
175  }
+
176 
+
178  virtual void set_avrc_metadata_callback(void (*callback)(uint8_t, const uint8_t*)) {
+
179  this->avrc_metadata_callback = callback;
+
180  }
+
181 
+
182 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
+
184  virtual void set_avrc_rn_playstatus_callback(void (*callback)(esp_avrc_playback_stat_t playback)) {
+
185  this->avrc_rn_playstatus_callback = callback;
+
186  }
+
187 #endif
188 
-
190  virtual void play();
-
192  virtual void pause();
-
194  virtual void stop();
-
196  virtual void next();
-
198  virtual void previous();
-
200  virtual void fast_forward();
-
202  virtual void rewind();
-
203 
-
205  virtual void set_mono_downmix(bool enabled) {
-
206  volume_control()->set_mono_downmix(enabled);
-
207  }
-
208 
-
210  virtual uint16_t sample_rate() { return m_sample_rate;}
-
211 
-
213  virtual void activate_pin_code(bool active);
-
214 
-
216  virtual void confirm_pin_code();
-
217 
-
219  virtual void confirm_pin_code(int code);
-
220 
-
222  virtual int pin_code() {
-
223  return pin_code_int;
-
224  }
+
190  virtual void set_sample_rate_callback(void (*callback)(uint16_t rate)) {
+
191  this->sample_rate_callback = callback;
+
192  }
+
193 
+
195  virtual void set_stream_reader(void (*callBack)(const uint8_t*, uint32_t), bool i2s_output=true);
+
196 
+
198  virtual void set_raw_stream_reader(void (*callBack)(const uint8_t*, uint32_t));
+
199 
+
201  virtual void set_on_data_received(void (*callBack)());
+
202 
+
204  virtual void set_address_validator(bool (*callBack)(esp_bd_addr_t remote_bda)){
+
205  address_validator = callBack;
+
206  }
+
207 
+
209  virtual bool is_avrc_connected();
+
210 
+
212  virtual void set_volume(uint8_t volume);
+
213 
+
215  virtual int get_volume();
+
216 
+
218  virtual void set_on_volumechange(void (*callBack)(int));
+
219 
+
221  virtual void set_avrc_rn_volumechange(void (*callBack)(int));
+
222 
+
224  virtual void set_avrc_rn_volumechange_completed(void (*callBack)(int));
225 
-
227  virtual void set_avrc_metadata_attribute_mask(int flags){
-
228  avrc_metadata_flags = flags;
-
229  }
-
230 
-
232  virtual void set_swap_lr_channels(bool swap){
-
233  swap_left_right = swap;
-
234  }
-
235 
-
237  virtual void set_auto_reconnect(bool reconnect, int count=AUTOCONNECT_TRY_NUM ){
-
238  reconnect_status = reconnect ? AutoReconnect : NoReconnect;
-
239  try_reconnect_max_count = count;
-
240  }
-
241 
-
243  virtual esp_bd_addr_t* get_current_peer_address() {
-
244  return &peer_bd_addr;
-
245  }
-
246 
-
247 
-
249  void set_rssi_active(bool active){
-
250  rssi_active = active;
-
251  }
-
252 
-
254  esp_bt_gap_cb_param_t::read_rssi_delta_param get_last_rssi() {
-
255  return last_rssi_delta;
-
256  }
+
227  virtual void play();
+
229  virtual void pause();
+
231  virtual void stop();
+
233  virtual void next();
+
235  virtual void previous();
+
237  virtual void fast_forward();
+
239  virtual void rewind();
+
240 
+
242  virtual void set_mono_downmix(bool enabled) {
+
243  volume_control()->set_mono_downmix(enabled);
+
244  }
+
245 
+
247  virtual uint16_t sample_rate() { return m_sample_rate;}
+
248 
+
250  virtual void activate_pin_code(bool active);
+
251 
+
253  virtual void confirm_pin_code();
+
254 
+
256  virtual void confirm_pin_code(int code);
257 
-
259  void set_rssi_callback(void (*callback)(esp_bt_gap_cb_param_t::read_rssi_delta_param &rssi)){
-
260  rssi_callbak = callback;
+
259  virtual int pin_code() {
+
260  return pin_code_int;
261  }
262 
-
264  void set_reconnect_delay(int delay){
-
265  reconnect_delay = delay;
+
264  virtual void set_avrc_metadata_attribute_mask(int flags){
+
265  avrc_metadata_flags = flags;
266  }
267 
-
269  void set_spp_active(bool flag){
-
270  spp_active = flag;
+
269  virtual void set_swap_lr_channels(bool swap){
+
270  swap_left_right = swap;
271  }
272 
-
273  #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
-
275  virtual const char* get_connected_source_name();
-
277  bool is_avrc_peer_rn_cap(esp_avrc_rn_event_ids_t cmd) {
-
278  return esp_avrc_rn_evt_bit_mask_operation(ESP_AVRC_BIT_MASK_OP_TEST, &s_avrc_peer_rn_cap, cmd);
-
279  }
-
281  bool is_avrc_peer_rn_cap_available() {
-
282  return s_avrc_peer_rn_cap.bits != 0;
-
283  }
+
274  virtual void set_auto_reconnect(bool reconnect, int count=AUTOCONNECT_TRY_NUM ){
+
275  reconnect_status = reconnect ? AutoReconnect : NoReconnect;
+
276  try_reconnect_max_count = count;
+
277  }
+
278 
+
280  virtual esp_bd_addr_t* get_current_peer_address() {
+
281  return &peer_bd_addr;
+
282  }
+
283 
284 
-
286  virtual const char* get_peer_name() {
-
287  return get_connected_source_name();
+
286  void set_rssi_active(bool active){
+
287  rssi_active = active;
288  }
289 
-
290  #endif
-
291 
-
292  protected:
-
293  // protected data
-
294  xQueueHandle app_task_queue = nullptr;
-
295  xTaskHandle app_task_handle = nullptr;
-
296 
-
297  bool is_i2s_output = A2DP_I2S_SUPPORT;
-
298 #if A2DP_I2S_SUPPORT
-
299  i2s_config_t i2s_config;
-
300  i2s_pin_config_t pin_config;
-
301  i2s_channel_t i2s_channels = I2S_CHANNEL_STEREO;
-
302  i2s_port_t i2s_port = I2S_NUM_0;
-
303  volatile bool is_i2s_active = false;
-
304 #endif
-
305  uint16_t m_sample_rate = 0;
-
306  uint32_t m_pkt_cnt = 0;
-
307  //esp_a2d_audio_state_t m_audio_state = ESP_A2D_AUDIO_STATE_STOPPED;
-
308  esp_a2d_mct_t audio_type;
-
309  char pin_code_str[20] = {0};
-
310  bool player_init = false;
-
311  int connection_rety_count = 0;
-
312  bool spp_active = false;
-
313  esp_spp_mode_t esp_spp_mode = ESP_SPP_MODE_CB;
-
314  _lock_t s_volume_lock;
-
315  uint8_t s_volume = 0;
-
316  bool s_volume_notify;
-
317  int pin_code_int = 0;
-
318  PinCodeRequest pin_code_request = Undefined;
-
319  bool is_pin_code_active = false;
-
320  bool avrc_connection_state = false;
-
321  int avrc_metadata_flags = ESP_AVRC_MD_ATTR_TITLE | ESP_AVRC_MD_ATTR_ARTIST | ESP_AVRC_MD_ATTR_ALBUM | ESP_AVRC_MD_ATTR_TRACK_NUM | ESP_AVRC_MD_ATTR_NUM_TRACKS | ESP_AVRC_MD_ATTR_GENRE;
-
322  void (*bt_volumechange)(int) = nullptr;
-
323  void (*bt_dis_connected)() = nullptr;
-
324  void (*bt_connected)() = nullptr;
-
325  void (*data_received)() = nullptr;
-
326  void (*stream_reader)(const uint8_t*, uint32_t) = nullptr;
-
327  void (*raw_stream_reader)(const uint8_t*, uint32_t) = nullptr;
-
328  void (*avrc_connection_state_callback)(bool connected) = nullptr;
-
329  void (*avrc_metadata_callback)(uint8_t, const uint8_t*) = nullptr;
-
330 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
-
331  void (*avrc_rn_playstatus_callback)(esp_avrc_playback_stat_t) = nullptr;
-
332 #endif
-
333  void (*avrc_rn_volchg_complete_callback)(int) = nullptr;
-
334  bool (*address_validator)(esp_bd_addr_t remote_bda) = nullptr;
-
335  void (*sample_rate_callback)(uint16_t rate)=nullptr;
-
336  bool swap_left_right = false;
-
337  int try_reconnect_max_count = AUTOCONNECT_TRY_NUM;
-
338 
-
339  // RSSI support
-
340  esp_bt_gap_cb_param_t::read_rssi_delta_param last_rssi_delta;
-
341  bool rssi_active = false;
-
342  void (*rssi_callbak)(esp_bt_gap_cb_param_t::read_rssi_delta_param &rssi) = nullptr;
-
343  int reconnect_delay = 1000;
-
344 
-
345 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
-
346  esp_avrc_rn_evt_cap_mask_t s_avrc_peer_rn_cap = {0};
-
347  esp_avrc_rn_evt_cap_mask_t s_avrc_peer_rn_cap_set = {0};
-
348  char remote_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1];
-
349 #endif
-
350 
-
351  // protected methods
-
352  virtual int init_bluetooth();
-
353  virtual void app_task_start_up(void);
-
354  virtual void app_task_shut_down(void);
-
355  virtual bool app_send_msg(bt_app_msg_t *msg);
-
356  virtual bool app_work_dispatch(app_callback_t p_cback, uint16_t event, void *p_params, int param_len);
-
357  virtual void app_work_dispatched(bt_app_msg_t *msg);
-
358  virtual void app_alloc_meta_buffer(esp_avrc_ct_cb_param_t *param);
-
359  virtual void av_new_track();
-
360  virtual void av_playback_changed();
-
361  virtual void av_play_pos_changed();
-
362  virtual void init_nvs();
-
363  // execute AVRC command
-
364  virtual void execute_avrc_command(int cmd);
-
365 
-
366  virtual const char* last_bda_nvs_name() {
-
367  return "last_bda";
-
368  }
-
369 
-
370  virtual bool is_reconnect(esp_a2d_disc_rsn_t type) {
-
371  bool result = is_autoreconnect_allowed && (reconnect_status==AutoReconnect || reconnect_status==IsReconnecting) && has_last_connection();
-
372  ESP_LOGI(BT_AV_TAG,"is_reconnect: %s", result ? "true":"false");
-
373  return result;
-
374  }
-
375 
-
379  // task handler
-
380  virtual void app_task_handler(void *arg);
-
381  // a2d callback
-
382  virtual void app_a2d_callback(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param);
-
383  // GAP callback
-
384  virtual void app_gap_callback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param);
-
385  // avrc callback
-
386  virtual void app_rc_ct_callback(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
-
387  // Callback for music stream
-
388  virtual void audio_data_callback(const uint8_t *data, uint32_t len);
-
389  // av event handler
-
390  virtual void av_hdl_stack_evt(uint16_t event, void *p_param);
-
391  // a2dp event handler
-
392  virtual void av_hdl_a2d_evt(uint16_t event, void *p_param);
-
393  // avrc event handler
-
394  virtual void av_hdl_avrc_evt(uint16_t event, void *p_param);
+
291  esp_bt_gap_cb_param_t::read_rssi_delta_param get_last_rssi() {
+
292  return last_rssi_delta;
+
293  }
+
294 
+
296  void set_rssi_callback(void (*callback)(esp_bt_gap_cb_param_t::read_rssi_delta_param &rssi)){
+
297  rssi_callbak = callback;
+
298  }
+
299 
+
301  void set_reconnect_delay(int delay){
+
302  reconnect_delay = delay;
+
303  }
+
304 
+
306  void set_spp_active(bool flag){
+
307  spp_active = flag;
+
308  }
+
309 
+
310  #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
+
312  virtual const char* get_connected_source_name();
+
314  bool is_avrc_peer_rn_cap(esp_avrc_rn_event_ids_t cmd) {
+
315  return esp_avrc_rn_evt_bit_mask_operation(ESP_AVRC_BIT_MASK_OP_TEST, &s_avrc_peer_rn_cap, cmd);
+
316  }
+
318  bool is_avrc_peer_rn_cap_available() {
+
319  return s_avrc_peer_rn_cap.bits != 0;
+
320  }
+
321 
+
323  virtual const char* get_peer_name() {
+
324  return get_connected_source_name();
+
325  }
+
326 
+
327  #endif
+
328 
+
329  protected:
+
330 
+
331 #ifdef ARDUINO
+
332  Print* p_print = nullptr;
+
333 #endif
+
334 
+
335 #if A2DP_I2S_AUDIOTOOLS
+
336  AudioOutput* p_audio_print = nullptr;
+
337 #endif
+
338 
+
339  // protected data
+
340  xQueueHandle app_task_queue = nullptr;
+
341  xTaskHandle app_task_handle = nullptr;
+
342 
+
343 #if A2DP_LEGACY_I2S_SUPPORT
+
344  i2s_config_t i2s_config;
+
345  i2s_pin_config_t pin_config;
+
346  i2s_channel_t i2s_channels = I2S_CHANNEL_STEREO;
+
347  i2s_port_t i2s_port = I2S_NUM_0;
+
348 #endif
+
349  volatile bool is_i2s_active = false;
+
350  uint16_t m_sample_rate = 0;
+
351  uint32_t m_pkt_cnt = 0;
+
352  //esp_a2d_audio_state_t m_audio_state = ESP_A2D_AUDIO_STATE_STOPPED;
+
353  esp_a2d_mct_t audio_type;
+
354  char pin_code_str[20] = {0};
+
355  bool player_init = false;
+
356  int connection_rety_count = 0;
+
357  bool spp_active = false;
+
358  esp_spp_mode_t esp_spp_mode = ESP_SPP_MODE_CB;
+
359  _lock_t s_volume_lock;
+
360  uint8_t s_volume = 0;
+
361  bool s_volume_notify;
+
362  int pin_code_int = 0;
+
363  PinCodeRequest pin_code_request = Undefined;
+
364  bool is_pin_code_active = false;
+
365  bool avrc_connection_state = false;
+
366  int avrc_metadata_flags = ESP_AVRC_MD_ATTR_TITLE | ESP_AVRC_MD_ATTR_ARTIST | ESP_AVRC_MD_ATTR_ALBUM | ESP_AVRC_MD_ATTR_TRACK_NUM | ESP_AVRC_MD_ATTR_NUM_TRACKS | ESP_AVRC_MD_ATTR_GENRE;
+
367  void (*bt_volumechange)(int) = nullptr;
+
368  void (*bt_dis_connected)() = nullptr;
+
369  void (*bt_connected)() = nullptr;
+
370  void (*data_received)() = nullptr;
+
371  void (*stream_reader)(const uint8_t*, uint32_t) = nullptr;
+
372  void (*raw_stream_reader)(const uint8_t*, uint32_t) = nullptr;
+
373  void (*avrc_connection_state_callback)(bool connected) = nullptr;
+
374  void (*avrc_metadata_callback)(uint8_t, const uint8_t*) = nullptr;
+
375 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
+
376  void (*avrc_rn_playstatus_callback)(esp_avrc_playback_stat_t) = nullptr;
+
377 #endif
+
378  void (*avrc_rn_volchg_complete_callback)(int) = nullptr;
+
379  bool (*address_validator)(esp_bd_addr_t remote_bda) = nullptr;
+
380  void (*sample_rate_callback)(uint16_t rate)=nullptr;
+
381  bool swap_left_right = false;
+
382  int try_reconnect_max_count = AUTOCONNECT_TRY_NUM;
+
383 
+
384  // RSSI support
+
385  esp_bt_gap_cb_param_t::read_rssi_delta_param last_rssi_delta;
+
386  bool rssi_active = false;
+
387  void (*rssi_callbak)(esp_bt_gap_cb_param_t::read_rssi_delta_param &rssi) = nullptr;
+
388  int reconnect_delay = 1000;
+
389 
+
390 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
+
391  esp_avrc_rn_evt_cap_mask_t s_avrc_peer_rn_cap = {0};
+
392  esp_avrc_rn_evt_cap_mask_t s_avrc_peer_rn_cap_set = {0};
+
393  char remote_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1];
+
394 #endif
395 
-
396  // split up long handlers
-
397  virtual void handle_connection_state(uint16_t event, void *p_param);
-
398  virtual void handle_audio_state(uint16_t event, void *p_param);
-
399  virtual void handle_audio_cfg(uint16_t event, void *p_param);
-
400  virtual void handle_avrc_connection_state(bool connected);
-
401 
-
402 
-
403 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
-
404  virtual void volume_set_by_local_host(uint8_t volume);
-
405  virtual void volume_set_by_controller(uint8_t volume);
-
406  virtual void av_notify_evt_handler(uint8_t event_id, esp_avrc_rn_param_t* event_parameter);
-
407  virtual void app_rc_tg_callback(esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param);
-
408  virtual void av_hdl_avrc_tg_evt(uint16_t event, void *p_param);
-
409 #else
-
410  virtual void av_notify_evt_handler(uint8_t event_id, uint32_t event_parameter);
-
411 #endif
-
412 
-
413 #if A2DP_I2S_SUPPORT
-
414  virtual void init_i2s();
-
415 
-
417  virtual size_t write_audio(const uint8_t *data, size_t size){
-
418  return i2s_write_data(data, size);
+
396  // protected methods
+
397  virtual int init_bluetooth();
+
398  virtual void app_task_start_up(void);
+
399  virtual void app_task_shut_down(void);
+
400  virtual bool app_send_msg(bt_app_msg_t *msg);
+
401  virtual bool app_work_dispatch(app_callback_t p_cback, uint16_t event, void *p_params, int param_len);
+
402  virtual void app_work_dispatched(bt_app_msg_t *msg);
+
403  virtual void app_alloc_meta_buffer(esp_avrc_ct_cb_param_t *param);
+
404  virtual void av_new_track();
+
405  virtual void av_playback_changed();
+
406  virtual void av_play_pos_changed();
+
407  virtual void init_nvs();
+
408  // execute AVRC command
+
409  virtual void execute_avrc_command(int cmd);
+
410 
+
411  virtual const char* last_bda_nvs_name() {
+
412  return "last_bda";
+
413  }
+
414 
+
415  virtual bool is_reconnect(esp_a2d_disc_rsn_t type) {
+
416  bool result = is_autoreconnect_allowed && (reconnect_status==AutoReconnect || reconnect_status==IsReconnecting) && has_last_connection();
+
417  ESP_LOGI(BT_AV_TAG,"is_reconnect: %s", result ? "true":"false");
+
418  return result;
419  }
420 
-
422  size_t i2s_write_data(const uint8_t* data, size_t item_size);
-
423 
-
424 
-
426  virtual void i2s_task_handler(void *arg) {}
-
427  virtual void bt_i2s_task_start_up(void) {}
-
428  virtual void bt_i2s_task_shut_down(void) {}
-
429 
-
430 #endif
-
431 
-
432  virtual esp_err_t esp_a2d_connect(esp_bd_addr_t peer) {
-
433  return esp_a2d_sink_connect(peer);
-
434  }
-
435 
-
436  void set_scan_mode_connectable_default() override {
-
437  set_scan_mode_connectable(true);
-
438  }
-
439 
-
440  virtual void set_i2s_active(bool active);
-
441 
-
442 };
-
443 
-
444 
-
445 #ifdef __cplusplus
-
446 }
-
447 #endif
-
448 
-
449 
+
424  // task handler
+
425  virtual void app_task_handler(void *arg);
+
426  // a2d callback
+
427  virtual void app_a2d_callback(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param);
+
428  // GAP callback
+
429  virtual void app_gap_callback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param);
+
430  // avrc callback
+
431  virtual void app_rc_ct_callback(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
+
432  // Callback for music stream
+
433  virtual void audio_data_callback(const uint8_t *data, uint32_t len);
+
434  // av event handler
+
435  virtual void av_hdl_stack_evt(uint16_t event, void *p_param);
+
436  // a2dp event handler
+
437  virtual void av_hdl_a2d_evt(uint16_t event, void *p_param);
+
438  // avrc event handler
+
439  virtual void av_hdl_avrc_evt(uint16_t event, void *p_param);
+
440 
+
441  // split up long handlers
+
442  virtual void handle_connection_state(uint16_t event, void *p_param);
+
443  virtual void handle_audio_state(uint16_t event, void *p_param);
+
444  virtual void handle_audio_cfg(uint16_t event, void *p_param);
+
445  virtual void handle_avrc_connection_state(bool connected);
+
446 
+
447 
+
448 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
+
449  virtual void volume_set_by_local_host(uint8_t volume);
+
450  virtual void volume_set_by_controller(uint8_t volume);
+
451  virtual void av_notify_evt_handler(uint8_t event_id, esp_avrc_rn_param_t* event_parameter);
+
452  virtual void app_rc_tg_callback(esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param);
+
453  virtual void av_hdl_avrc_tg_evt(uint16_t event, void *p_param);
+
454 #else
+
455  virtual void av_notify_evt_handler(uint8_t event_id, uint32_t event_parameter);
+
456 #endif
+
457 
+
458  virtual void init_i2s();
+
459 
+
461  virtual size_t write_audio(const uint8_t *data, size_t size){
+
462  return i2s_write_data(data, size);
+
463  }
+
464 
+
466  size_t i2s_write_data(const uint8_t* data, size_t item_size);
+
467 
+
468 
+
470  virtual void i2s_task_handler(void *arg) {}
+
471  virtual void bt_i2s_task_start_up(void) {}
+
472  virtual void bt_i2s_task_shut_down(void) {}
+
473 
+
474  virtual esp_err_t esp_a2d_connect(esp_bd_addr_t peer) {
+
475  return esp_a2d_sink_connect(peer);
+
476  }
+
477 
+
478  void set_scan_mode_connectable_default() override {
+
479  set_scan_mode_connectable(true);
+
480  }
+
481 
+
482  virtual void set_i2s_active(bool active);
+
483 
+
484 };
+
485 
+
486 
+
487 #ifdef __cplusplus
+
488 }
+
489 #endif
+
490 
+
491 
void delay(long millis)
call vTaskDelay to deley for the indicated number of milliseconds
Definition: BluetoothA2DPCommon.cpp:356
void(* app_callback_t)(uint16_t event, void *param)
handler for the dispatched work
Definition: BluetoothA2DPCommon.h:102
@@ -449,70 +488,68 @@
virtual A2DPVolumeControl * volume_control()
provides access to the VolumeControl object
Definition: BluetoothA2DPCommon.h:311
virtual bool reconnect()
Reconnects to the last device.
Definition: BluetoothA2DPCommon.cpp:33
virtual void set_scan_mode_connectable(bool connectable)
Defines if the bluetooth is connectable.
Definition: BluetoothA2DPCommon.cpp:288
-
A2DP Bluethooth Sink - We initialize and start the Bluetooth A2DP Sink. The example https://github....
Definition: BluetoothA2DPSink.h:63
-
virtual void set_raw_stream_reader(void(*callBack)(const uint8_t *, uint32_t))
Define a callback that is called before the volume changes: this callback provides access to the data...
Definition: BluetoothA2DPSink.cpp:122
-
virtual ~BluetoothA2DPSink()
Destructor - stops the playback and releases all resources.
Definition: BluetoothA2DPSink.cpp:72
-
virtual void set_swap_lr_channels(bool swap)
swaps the left and right channel
Definition: BluetoothA2DPSink.h:232
-
virtual void activate_pin_code(bool active)
We need to confirm a new seesion by calling confirm_pin_code()
Definition: BluetoothA2DPSink.cpp:1271
-
virtual void next()
AVRC next.
Definition: BluetoothA2DPSink.cpp:1236
-
BluetoothA2DPSink()
Constructor.
Definition: BluetoothA2DPSink.cpp:24
-
virtual const char * get_connected_source_name()
Get the name of the connected source device (obsolete)
Definition: BluetoothA2DPSink.cpp:303
-
friend void ccall_av_hdl_avrc_evt(uint16_t event, void *p_param)
avrc event handler
Definition: BluetoothA2DPSink.cpp:1357
-
virtual void previous()
AVRC previous.
Definition: BluetoothA2DPSink.cpp:1239
-
virtual void app_task_handler(void *arg)
Definition: BluetoothA2DPSink.cpp:408
-
virtual int pin_code()
provides the requested pin code (0 = undefined)
Definition: BluetoothA2DPSink.h:222
-
virtual void stop()
AVRC stop.
Definition: BluetoothA2DPSink.cpp:1232
-
friend void ccall_av_hdl_stack_evt(uint16_t event, void *p_param)
av event handler
Definition: BluetoothA2DPSink.cpp:1350
-
virtual void set_i2s_config(i2s_config_t i2s_config)
Define the i2s configuration.
Definition: BluetoothA2DPSink.cpp:111
-
virtual void fast_forward()
AVRC fast_forward.
Definition: BluetoothA2DPSink.cpp:1242
-
friend void ccall_app_a2d_callback(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
handle esp_a2d_cb_event_t
Definition: BluetoothA2DPSink.cpp:1332
-
void set_rssi_active(bool active)
Activates the rssi reporting.
Definition: BluetoothA2DPSink.h:249
-
virtual bool is_avrc_connected()
returns true if the avrc service is connected
Definition: BluetoothA2DPSink.cpp:1204
-
virtual void set_stream_reader(void(*callBack)(const uint8_t *, uint32_t), bool i2s_output=true)
Define callback which is called when we receive data: This callback provides access to the data.
Definition: BluetoothA2DPSink.cpp:117
-
virtual void set_volume(uint8_t volume)
Changes the volume.
Definition: BluetoothA2DPSink.cpp:1249
-
esp_bt_gap_cb_param_t::read_rssi_delta_param get_last_rssi()
provides the last rssi parameters
Definition: BluetoothA2DPSink.h:254
-
virtual void end(bool release_memory=false)
ends the I2S bluetooth sink with the indicated name - if you release the memory a future start is not...
Definition: BluetoothA2DPSink.cpp:80
-
virtual void confirm_pin_code()
confirms the connection request by returning the receivedn pin code
Definition: BluetoothA2DPSink.cpp:1275
-
virtual void set_avrc_rn_playstatus_callback(void(*callback)(esp_avrc_playback_stat_t playback))
Define a callback method which provides the avrc notifications.
Definition: BluetoothA2DPSink.h:147
-
virtual void set_mono_downmix(bool enabled)
mix stereo into single mono signal
Definition: BluetoothA2DPSink.h:205
+
A2DP Bluethooth Sink - We initialize and start the Bluetooth A2DP Sink. The example https://github....
Definition: BluetoothA2DPSink.h:75
+
virtual void set_raw_stream_reader(void(*callBack)(const uint8_t *, uint32_t))
Define a callback that is called before the volume changes: this callback provides access to the data...
Definition: BluetoothA2DPSink.cpp:127
+
virtual ~BluetoothA2DPSink()
Destructor - stops the playback and releases all resources.
Definition: BluetoothA2DPSink.cpp:73
+
virtual void set_swap_lr_channels(bool swap)
swaps the left and right channel
Definition: BluetoothA2DPSink.h:269
+
virtual void activate_pin_code(bool active)
We need to confirm a new seesion by calling confirm_pin_code()
Definition: BluetoothA2DPSink.cpp:1298
+
virtual void next()
AVRC next.
Definition: BluetoothA2DPSink.cpp:1266
+
BluetoothA2DPSink()
Default Constructor: output via callback or Legacy I2S.
Definition: BluetoothA2DPSink.cpp:24
+
virtual const char * get_connected_source_name()
Get the name of the connected source device (obsolete)
Definition: BluetoothA2DPSink.cpp:301
+
friend void ccall_av_hdl_avrc_evt(uint16_t event, void *p_param)
avrc event handler
Definition: BluetoothA2DPSink.cpp:1382
+
virtual void previous()
AVRC previous.
Definition: BluetoothA2DPSink.cpp:1269
+
virtual void app_task_handler(void *arg)
Definition: BluetoothA2DPSink.cpp:402
+
virtual int pin_code()
provides the requested pin code (0 = undefined)
Definition: BluetoothA2DPSink.h:259
+
virtual void stop()
AVRC stop.
Definition: BluetoothA2DPSink.cpp:1264
+
friend void ccall_av_hdl_stack_evt(uint16_t event, void *p_param)
av event handler
Definition: BluetoothA2DPSink.cpp:1375
+
virtual void fast_forward()
AVRC fast_forward.
Definition: BluetoothA2DPSink.cpp:1272
+
friend void ccall_app_a2d_callback(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
handle esp_a2d_cb_event_t
Definition: BluetoothA2DPSink.cpp:1354
+
void set_rssi_active(bool active)
Activates the rssi reporting.
Definition: BluetoothA2DPSink.h:286
+
virtual bool is_avrc_connected()
returns true if the avrc service is connected
Definition: BluetoothA2DPSink.cpp:1236
+
virtual void set_stream_reader(void(*callBack)(const uint8_t *, uint32_t), bool i2s_output=true)
Define callback which is called when we receive data: This callback provides access to the data.
Definition: BluetoothA2DPSink.cpp:121
+
virtual void set_volume(uint8_t volume)
Changes the volume.
Definition: BluetoothA2DPSink.cpp:1279
+
esp_bt_gap_cb_param_t::read_rssi_delta_param get_last_rssi()
provides the last rssi parameters
Definition: BluetoothA2DPSink.h:291
+
virtual void end(bool release_memory=false)
ends the I2S bluetooth sink with the indicated name - if you release the memory a future start is not...
Definition: BluetoothA2DPSink.cpp:79
+
virtual void confirm_pin_code()
confirms the connection request by returning the receivedn pin code
Definition: BluetoothA2DPSink.cpp:1302
+
virtual void set_avrc_rn_playstatus_callback(void(*callback)(esp_avrc_playback_stat_t playback))
Define a callback method which provides the avrc notifications.
Definition: BluetoothA2DPSink.h:184
+
virtual void set_mono_downmix(bool enabled)
mix stereo into single mono signal
Definition: BluetoothA2DPSink.h:242
virtual esp_a2d_mct_t get_audio_type()
Determine the actual audio type.
Definition: BluetoothA2DPSink.cpp:298
-
bool is_avrc_peer_rn_cap_available()
Returns true if the is_avrc_peer_rn_cap() method can be called.
Definition: BluetoothA2DPSink.h:281
-
virtual void set_avrc_metadata_attribute_mask(int flags)
defines the requested metadata: eg. ESP_AVRC_MD_ATTR_TITLE | ESP_AVRC_MD_ATTR_ARTIST | ESP_AVRC_MD_AT...
Definition: BluetoothA2DPSink.h:227
-
friend void ccall_app_rc_ct_callback(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)
handle esp_avrc_ct_cb_event_t
Definition: BluetoothA2DPSink.cpp:1338
-
virtual void set_sample_rate_callback(void(*callback)(uint16_t rate))
Defines the method which will be called with the sample rate is updated.
Definition: BluetoothA2DPSink.h:153
-
virtual uint16_t sample_rate()
Provides the actually set data rate (in samples per second)
Definition: BluetoothA2DPSink.h:210
-
void set_reconnect_delay(int delay)
Defines the delay that is added to delay the startup when we automatically reconnect.
Definition: BluetoothA2DPSink.h:264
-
void set_rssi_callback(void(*callback)(esp_bt_gap_cb_param_t::read_rssi_delta_param &rssi))
Defines the callback that is called when we get an new rssi value.
Definition: BluetoothA2DPSink.h:259
-
friend void ccall_av_hdl_a2d_evt(uint16_t event, void *p_param)
a2dp event handler
Definition: BluetoothA2DPSink.cpp:1364
-
virtual void set_avrc_rn_volumechange_completed(void(*callBack)(int))
set the callback that the local volume change is notification is received and complete
Definition: BluetoothA2DPSink.cpp:147
-
virtual void set_bits_per_sample(int bps)
Defines the bits per sample for output (if > 16 output will be expanded)
Definition: BluetoothA2DPSink.h:115
-
virtual void rewind()
AVRC rewind.
Definition: BluetoothA2DPSink.cpp:1245
-
virtual size_t write_audio(const uint8_t *data, size_t size)
output audio data e.g. to i2s or to queue
Definition: BluetoothA2DPSink.h:417
-
virtual void pause()
AVRC pause.
Definition: BluetoothA2DPSink.cpp:1228
-
virtual void set_avrc_metadata_callback(void(*callback)(uint8_t, const uint8_t *))
Define a callback method which provides the meta data.
Definition: BluetoothA2DPSink.h:141
-
virtual void play()
Starts to play music using AVRC.
Definition: BluetoothA2DPSink.cpp:1224
-
virtual void set_i2s_port(i2s_port_t i2s_num)
Define an alternative i2s port other then 0.
Definition: BluetoothA2DPSink.cpp:107
-
size_t i2s_write_data(const uint8_t *data, size_t item_size)
writes the data to i2s
Definition: BluetoothA2DPSink.cpp:1373
-
virtual void set_channels(i2s_channel_t channels)
set output to I2S_CHANNEL_STEREO (default) or I2S_CHANNEL_MONO
Definition: BluetoothA2DPSink.h:110
-
void set_spp_active(bool flag)
Activates SSP (Serial protocol)
Definition: BluetoothA2DPSink.h:269
-
virtual esp_bd_addr_t * get_current_peer_address()
Provides the address of the connected device.
Definition: BluetoothA2DPSink.h:243
-
friend void ccall_audio_data_callback(const uint8_t *data, uint32_t len)
Callback for music stream.
Definition: BluetoothA2DPSink.cpp:1326
-
friend void ccall_i2s_task_handler(void *arg)
task hander for i2s
Definition: BluetoothA2DPSink.cpp:1312
-
virtual void set_on_volumechange(void(*callBack)(int))
Set the callback that is called when they change the volume (kept for compatibility)
Definition: BluetoothA2DPSink.cpp:139
-
friend void ccall_app_rc_tg_callback(esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param)
handle esp_avrc_tg_cb_event_t
Definition: BluetoothA2DPSink.cpp:1474
-
virtual const char * get_peer_name()
Get the name of the connected source device.
Definition: BluetoothA2DPSink.h:286
-
virtual int get_volume()
Determines the volume.
Definition: BluetoothA2DPSink.cpp:1265
-
virtual void set_avrc_rn_volumechange(void(*callBack)(int))
Set the callback that is called when remote changes the volume.
Definition: BluetoothA2DPSink.cpp:143
-
friend void ccall_app_task_handler(void *arg)
task handler
Definition: BluetoothA2DPSink.cpp:1320
-
friend void ccall_app_gap_callback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
GAP callback.
Definition: BluetoothA2DPSink.cpp:1344
-
virtual void set_address_validator(bool(*callBack)(esp_bd_addr_t remote_bda))
Allows you to reject unauthorized addresses.
Definition: BluetoothA2DPSink.h:167
-
virtual void set_avrc_connection_state_callback(void(*callback)(bool))
Define a callback method which provides connection state of AVRC service.
Definition: BluetoothA2DPSink.h:136
-
bool is_avrc_peer_rn_cap(esp_avrc_rn_event_ids_t cmd)
Provides the result of the last result for the esp_avrc_tg_get_rn_evt_cap() callback (Available from ...
Definition: BluetoothA2DPSink.h:277
-
virtual void set_on_data_received(void(*callBack)())
Define callback which is called when we receive data.
Definition: BluetoothA2DPSink.cpp:126
-
virtual void set_pin_config(i2s_pin_config_t pin_config)
Define the pins.
Definition: BluetoothA2DPSink.cpp:103
-
virtual void set_auto_reconnect(bool reconnect, int count=AUTOCONNECT_TRY_NUM)
Defines the number of times that the system tries to automatically reconnect to the last system.
Definition: BluetoothA2DPSink.h:237
-
virtual void start(const char *name, bool auto_reconect)
starts the I2S bluetooth sink with the inidicated name
Definition: BluetoothA2DPSink.cpp:151
-
virtual void i2s_task_handler(void *arg)
dummy functions needed for BluetoothA2DPSinkQueued
Definition: BluetoothA2DPSink.h:426
+
BluetoothA2DPSink(Print &output)
Output to Arduino Print.
Definition: BluetoothA2DPSink.h:127
+
bool is_avrc_peer_rn_cap_available()
Returns true if the is_avrc_peer_rn_cap() method can be called.
Definition: BluetoothA2DPSink.h:318
+
virtual void set_avrc_metadata_attribute_mask(int flags)
defines the requested metadata: eg. ESP_AVRC_MD_ATTR_TITLE | ESP_AVRC_MD_ATTR_ARTIST | ESP_AVRC_MD_AT...
Definition: BluetoothA2DPSink.h:264
+
friend void ccall_app_rc_ct_callback(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param)
handle esp_avrc_ct_cb_event_t
Definition: BluetoothA2DPSink.cpp:1361
+
BluetoothA2DPSink(AudioStream &output)
Output AudioStream using AudioTools library.
Definition: BluetoothA2DPSink.h:117
+
virtual void set_sample_rate_callback(void(*callback)(uint16_t rate))
Defines the method which will be called with the sample rate is updated.
Definition: BluetoothA2DPSink.h:190
+
virtual uint16_t sample_rate()
Provides the actually set data rate (in samples per second)
Definition: BluetoothA2DPSink.h:247
+
void set_reconnect_delay(int delay)
Defines the delay that is added to delay the startup when we automatically reconnect.
Definition: BluetoothA2DPSink.h:301
+
void set_rssi_callback(void(*callback)(esp_bt_gap_cb_param_t::read_rssi_delta_param &rssi))
Defines the callback that is called when we get an new rssi value.
Definition: BluetoothA2DPSink.h:296
+
friend void ccall_av_hdl_a2d_evt(uint16_t event, void *p_param)
a2dp event handler
Definition: BluetoothA2DPSink.cpp:1389
+
virtual void set_avrc_rn_volumechange_completed(void(*callBack)(int))
set the callback that the local volume change is notification is received and complete
Definition: BluetoothA2DPSink.cpp:145
+
virtual void rewind()
AVRC rewind.
Definition: BluetoothA2DPSink.cpp:1275
+
virtual size_t write_audio(const uint8_t *data, size_t size)
output audio data e.g. to i2s or to queue
Definition: BluetoothA2DPSink.h:461
+
virtual void pause()
AVRC pause.
Definition: BluetoothA2DPSink.cpp:1262
+
virtual void set_avrc_metadata_callback(void(*callback)(uint8_t, const uint8_t *))
Define a callback method which provides the meta data.
Definition: BluetoothA2DPSink.h:178
+
virtual void play()
Starts to play music using AVRC.
Definition: BluetoothA2DPSink.cpp:1260
+
size_t i2s_write_data(const uint8_t *data, size_t item_size)
writes the data to i2s
Definition: BluetoothA2DPSink.cpp:1396
+
void set_spp_active(bool flag)
Activates SSP (Serial protocol)
Definition: BluetoothA2DPSink.h:306
+
virtual esp_bd_addr_t * get_current_peer_address()
Provides the address of the connected device.
Definition: BluetoothA2DPSink.h:280
+
friend void ccall_audio_data_callback(const uint8_t *data, uint32_t len)
Callback for music stream.
Definition: BluetoothA2DPSink.cpp:1348
+
friend void ccall_i2s_task_handler(void *arg)
task hander for i2s
Definition: BluetoothA2DPSink.cpp:1336
+
virtual void set_on_volumechange(void(*callBack)(int))
Set the callback that is called when they change the volume (kept for compatibility)
Definition: BluetoothA2DPSink.cpp:137
+
friend void ccall_app_rc_tg_callback(esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param)
handle esp_avrc_tg_cb_event_t
Definition: BluetoothA2DPSink.cpp:1519
+
virtual const char * get_peer_name()
Get the name of the connected source device.
Definition: BluetoothA2DPSink.h:323
+
virtual int get_volume()
Determines the volume.
Definition: BluetoothA2DPSink.cpp:1293
+
virtual void set_avrc_rn_volumechange(void(*callBack)(int))
Set the callback that is called when remote changes the volume.
Definition: BluetoothA2DPSink.cpp:141
+
friend void ccall_app_task_handler(void *arg)
task handler
Definition: BluetoothA2DPSink.cpp:1342
+
friend void ccall_app_gap_callback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
GAP callback.
Definition: BluetoothA2DPSink.cpp:1368
+
virtual void set_address_validator(bool(*callBack)(esp_bd_addr_t remote_bda))
Allows you to reject unauthorized addresses.
Definition: BluetoothA2DPSink.h:204
+
virtual void set_avrc_connection_state_callback(void(*callback)(bool))
Define a callback method which provides connection state of AVRC service.
Definition: BluetoothA2DPSink.h:173
+
bool is_avrc_peer_rn_cap(esp_avrc_rn_event_ids_t cmd)
Provides the result of the last result for the esp_avrc_tg_get_rn_evt_cap() callback (Available from ...
Definition: BluetoothA2DPSink.h:314
+
virtual void set_on_data_received(void(*callBack)())
Define callback which is called when we receive data.
Definition: BluetoothA2DPSink.cpp:132
+
virtual void set_auto_reconnect(bool reconnect, int count=AUTOCONNECT_TRY_NUM)
Defines the number of times that the system tries to automatically reconnect to the last system.
Definition: BluetoothA2DPSink.h:274
+
virtual void start(const char *name, bool auto_reconect)
starts the I2S bluetooth sink with the inidicated name
Definition: BluetoothA2DPSink.cpp:150
+
virtual void i2s_task_handler(void *arg)
dummy functions needed for BluetoothA2DPSinkQueued
Definition: BluetoothA2DPSink.h:470
+
BluetoothA2DPSink(AudioOutput &output)
Output AudioOutput using AudioTools library.
Definition: BluetoothA2DPSink.h:111
Internal message to be sent for BluetoothA2DPSink and BluetoothA2DPSource.
Definition: BluetoothA2DPCommon.h:105
diff --git a/docs/html/_bluetooth_a2_d_p_sink_queued_8h_source.html b/docs/html/_bluetooth_a2_d_p_sink_queued_8h_source.html index fb743ba5..258b6f70 100644 --- a/docs/html/_bluetooth_a2_d_p_sink_queued_8h_source.html +++ b/docs/html/_bluetooth_a2_d_p_sink_queued_8h_source.html @@ -73,93 +73,102 @@
2 
3 #include "BluetoothA2DPSink.h"
4 
-
5 #if A2DP_I2S_SUPPORT
-
6 
-
7 #define RINGBUF_HIGHEST_WATER_LEVEL (32 * 1024)
-
8 #define RINGBUF_PREFETCH_PERCENT 65
-
9 
-
10 enum A2DPRingBufferMode : char {
-
11  RINGBUFFER_MODE_PROCESSING, /* ringbuffer is buffering incoming audio data, I2S is working */
-
12  RINGBUFFER_MODE_PREFETCHING, /* ringbuffer is buffering incoming audio data, I2S is waiting */
-
13  RINGBUFFER_MODE_DROPPING /* ringbuffer is not buffering (dropping) incoming audio data, I2S is working */
-
14 };
-
15 
-
23 class BluetoothA2DPSinkQueued : public BluetoothA2DPSink {
-
24  public:
-
25  BluetoothA2DPSinkQueued() = default;
-
26 
-
28  void set_i2s_stack_size(int size){
-
29  i2s_stack_size = size;
-
30  }
-
31 
-
33  void set_i2s_ringbuffer_size(int size){
-
34  i2s_ringbuffer_size = size;
-
35  }
-
36 
-
38  void set_i2s_ringbuffer_prefetch_percent(int percent){
-
39  if (percent<0) return;
-
40  if (percent>100) return;
-
41  ringbuffer_prefetch_percent = percent;
-
42  }
+
5 #define RINGBUF_HIGHEST_WATER_LEVEL (32 * 1024)
+
6 #define RINGBUF_PREFETCH_PERCENT 65
+
7 
+
8 enum A2DPRingBufferMode : char {
+
9  RINGBUFFER_MODE_PROCESSING, /* ringbuffer is buffering incoming audio data,
+
10  I2S is working */
+
11  RINGBUFFER_MODE_PREFETCHING, /* ringbuffer is buffering incoming audio data,
+
12  I2S is waiting */
+
13  RINGBUFFER_MODE_DROPPING /* ringbuffer is not buffering (dropping) incoming
+
14  audio data, I2S is working */
+
15 };
+
16 
+
24 class BluetoothA2DPSinkQueued : public BluetoothA2DPSink {
+
25  public:
+
26  BluetoothA2DPSinkQueued() = default;
+
27 
+
28 #if A2DP_I2S_AUDIOTOOLS
+
30  BluetoothA2DPSinkQueued(AudioOutput &output) {
+
31  actual_bluetooth_a2dp_sink = this;
+
32  p_print = &output;
+
33  p_audio_print = &output;
+
34  }
+
36  BluetoothA2DPSinkQueued(AudioStream &output) {
+
37  actual_bluetooth_a2dp_sink = this;
+
38  static AdapterAudioStreamToAudioOutput adapter(output);
+
39  p_print = &output;
+
40  p_audio_print = &adapter;
+
41  }
+
42 #endif
43 
-
45  void set_i2s_task_priority(UBaseType_t prio){
-
46  i2s_task_priority = prio;
-
47  }
-
48 
-
49  void set_i2s_write_size_upto(size_t size){
-
50  i2s_write_size_upto = size;
-
51  }
-
52 
-
53  void set_i2s_ticks(int ticks){
-
54  i2s_ticks = ticks;
-
55  }
-
56 
+
44 #ifdef ARDUINO
+
46  BluetoothA2DPSinkQueued(Print &output) {
+
47  actual_bluetooth_a2dp_sink = this;
+
48  p_print = &output;
+
49  }
+
50 #endif
+
51 
+
53  void set_i2s_stack_size(int size) { i2s_stack_size = size; }
+
54 
+
56  void set_i2s_ringbuffer_size(int size) { i2s_ringbuffer_size = size; }
57 
-
58 
-
59  protected:
-
60  xTaskHandle s_bt_i2s_task_handle = nullptr; /* handle of I2S task */
-
61  RingbufHandle_t s_ringbuf_i2s = nullptr; /* handle of ringbuffer for I2S */
-
62  SemaphoreHandle_t s_i2s_write_semaphore = nullptr;
-
63  // I2S task
-
64  int i2s_stack_size = 2048;
-
65  int i2s_ringbuffer_size = RINGBUF_HIGHEST_WATER_LEVEL;
-
66  UBaseType_t i2s_task_priority = configMAX_PRIORITIES - 3;
-
67  volatile A2DPRingBufferMode ringbuffer_mode = RINGBUFFER_MODE_PROCESSING;
-
68  volatile bool is_starting = true;
-
69  size_t i2s_write_size_upto = 240 * 6;
-
70  int i2s_ticks = 20;
-
71  int ringbuffer_prefetch_percent = RINGBUF_PREFETCH_PERCENT;
-
72 
-
73 
-
74  void bt_i2s_task_start_up(void) override;
-
75  void bt_i2s_task_shut_down(void) override;
-
76  void i2s_task_handler(void *arg) override;
-
77  size_t write_audio(const uint8_t *data, size_t size) override;
-
78 
-
79  void set_i2s_active(bool active) override {
-
80  BluetoothA2DPSink::set_i2s_active(active);
-
81  if (active) {
-
82  ringbuffer_mode = RINGBUFFER_MODE_PREFETCHING;
-
83  is_starting = true;
-
84  }
-
85  }
-
86 
-
87  int i2s_ringbuffer_prefetch_size() {
-
88  int bytes = i2s_ringbuffer_size * ringbuffer_prefetch_percent / 100;
-
89  return (bytes / 4 * 4);
-
90  }
-
91 
-
92 };
-
93 
-
94 #endif
-
A2DP Bluethooth Sink - We initialize and start the Bluetooth A2DP Sink. The example https://github....
Definition: BluetoothA2DPSink.h:63
-
The BluetoothA2DPSinkQueued is using a separate Task with an additinal Queue to write the I2S data....
Definition: BluetoothA2DPSinkQueued.h:23
-
size_t write_audio(const uint8_t *data, size_t size) override
output audio data e.g. to i2s or to queue
Definition: BluetoothA2DPSinkQueued.cpp:88
-
void set_i2s_task_priority(UBaseType_t prio)
Defines the priority of the I2S task.
Definition: BluetoothA2DPSinkQueued.h:45
-
void set_i2s_ringbuffer_prefetch_percent(int percent)
Audio starts to play when limit exeeded.
Definition: BluetoothA2DPSinkQueued.h:38
-
void set_i2s_stack_size(int size)
Defines the stack size of the i2s task (in bytes)
Definition: BluetoothA2DPSinkQueued.h:28
-
void i2s_task_handler(void *arg) override
dummy functions needed for BluetoothA2DPSinkQueued
Definition: BluetoothA2DPSinkQueued.cpp:44
-
void set_i2s_ringbuffer_size(int size)
Defines the ringbuffer size used by the i2s task (in bytes)
Definition: BluetoothA2DPSinkQueued.h:33
+
59  void set_i2s_ringbuffer_prefetch_percent(int percent) {
+
60  if (percent < 0) return;
+
61  if (percent > 100) return;
+
62  ringbuffer_prefetch_percent = percent;
+
63  }
+
64 
+
66  void set_i2s_task_priority(UBaseType_t prio) { i2s_task_priority = prio; }
+
67 
+
68  void set_i2s_write_size_upto(size_t size) { i2s_write_size_upto = size; }
+
69 
+
70  void set_i2s_ticks(int ticks) { i2s_ticks = ticks; }
+
71 
+
72  protected:
+
73  xTaskHandle s_bt_i2s_task_handle = nullptr; /* handle of I2S task */
+
74  RingbufHandle_t s_ringbuf_i2s = nullptr; /* handle of ringbuffer for I2S */
+
75  SemaphoreHandle_t s_i2s_write_semaphore = nullptr;
+
76  // I2S task
+
77  int i2s_stack_size = 2048;
+
78  int i2s_ringbuffer_size = RINGBUF_HIGHEST_WATER_LEVEL;
+
79  UBaseType_t i2s_task_priority = configMAX_PRIORITIES - 3;
+
80  volatile A2DPRingBufferMode ringbuffer_mode = RINGBUFFER_MODE_PROCESSING;
+
81  volatile bool is_starting = true;
+
82  size_t i2s_write_size_upto = 240 * 6;
+
83  int i2s_ticks = 20;
+
84  int ringbuffer_prefetch_percent = RINGBUF_PREFETCH_PERCENT;
+
85 
+
86  void bt_i2s_task_start_up(void) override;
+
87  void bt_i2s_task_shut_down(void) override;
+
88  void i2s_task_handler(void *arg) override;
+
89  size_t write_audio(const uint8_t *data, size_t size) override;
+
90 
+
91  void set_i2s_active(bool active) override {
+
92  BluetoothA2DPSink::set_i2s_active(active);
+
93  if (active) {
+
94  ringbuffer_mode = RINGBUFFER_MODE_PREFETCHING;
+
95  is_starting = true;
+
96  }
+
97  }
+
98 
+
99  int i2s_ringbuffer_prefetch_size() {
+
100  int bytes = i2s_ringbuffer_size * ringbuffer_prefetch_percent / 100;
+
101  return (bytes / 4 * 4);
+
102  }
+
103 };
+
A2DP Bluethooth Sink - We initialize and start the Bluetooth A2DP Sink. The example https://github....
Definition: BluetoothA2DPSink.h:75
+
The BluetoothA2DPSinkQueued is using a separate Task with an additinal Queue to write the I2S data....
Definition: BluetoothA2DPSinkQueued.h:24
+
size_t write_audio(const uint8_t *data, size_t size) override
output audio data e.g. to i2s or to queue
Definition: BluetoothA2DPSinkQueued.cpp:87
+
void set_i2s_task_priority(UBaseType_t prio)
Defines the priority of the I2S task.
Definition: BluetoothA2DPSinkQueued.h:66
+
BluetoothA2DPSinkQueued(Print &output)
Output to Arduino Print.
Definition: BluetoothA2DPSinkQueued.h:46
+
void set_i2s_ringbuffer_prefetch_percent(int percent)
Audio starts to play when limit exeeded.
Definition: BluetoothA2DPSinkQueued.h:59
+
BluetoothA2DPSinkQueued(AudioStream &output)
Output AudioStream using AudioTools library.
Definition: BluetoothA2DPSinkQueued.h:36
+
void set_i2s_stack_size(int size)
Defines the stack size of the i2s task (in bytes)
Definition: BluetoothA2DPSinkQueued.h:53
+
void i2s_task_handler(void *arg) override
dummy functions needed for BluetoothA2DPSinkQueued
Definition: BluetoothA2DPSinkQueued.cpp:43
+
void set_i2s_ringbuffer_size(int size)
Defines the ringbuffer size used by the i2s task (in bytes)
Definition: BluetoothA2DPSinkQueued.h:56
+
BluetoothA2DPSinkQueued(AudioOutput &output)
Output AudioOutput using AudioTools library.
Definition: BluetoothA2DPSinkQueued.h:30