diff --git a/_a2_d_p_stream_8h_source.html b/_a2_d_p_stream_8h_source.html index d5dcfca66..f1dcbf229 100644 --- a/_a2_d_p_stream_8h_source.html +++ b/_a2_d_p_stream_8h_source.html @@ -309,93 +309,97 @@
287  return a2dp_buffer;
288  }
289 
-
290  protected:
-
291  A2DPConfig config;
-
292  BluetoothA2DPSource *a2dp_source = nullptr;
-
293  BluetoothA2DPSink *a2dp_sink = nullptr;
-
294  BluetoothA2DPCommon *a2dp=nullptr;
-
295  const int A2DP_MAX_VOL = 128;
-
296 
-
297  // auto-detect device to send audio to (TX-Mode)
-
298  static bool detected_device(const char* ssid, esp_bd_addr_t address, int rssi){
-
299  LOGW("found Device: %s rssi: %d", ssid, rssi);
-
300  //filter out weak signals
-
301  return (rssi > -75);
-
302  }
-
303 
-
304  static void a2dp_state_callback(esp_a2d_connection_state_t state, void *caller){
-
305  TRACED();
-
306  A2DPStream *self = (A2DPStream*)caller;
-
307  if (state==ESP_A2D_CONNECTION_STATE_CONNECTED && self->config.startup_logic==StartOnConnect){
-
308  is_a2dp_active = true;
-
309  }
-
310  LOGW("==> state: %s", self->a2dp->to_str(state));
-
311  }
-
312 
-
313 
-
314  // callback used by A2DP to provide the a2dp_source sound data
-
315  static int32_t a2dp_stream_source_sound_data(uint8_t* data, int32_t len) {
-
316  int32_t result_len = 0;
-
317  A2DPConfig config = A2DPStream_self->config;
+
291  void setSilenceOnNoData(bool silence){
+
292  config.silence_on_nodata = silence;
+
293  }
+
294 
+
295  protected:
+
296  A2DPConfig config;
+
297  BluetoothA2DPSource *a2dp_source = nullptr;
+
298  BluetoothA2DPSink *a2dp_sink = nullptr;
+
299  BluetoothA2DPCommon *a2dp=nullptr;
+
300  const int A2DP_MAX_VOL = 128;
+
301 
+
302  // auto-detect device to send audio to (TX-Mode)
+
303  static bool detected_device(const char* ssid, esp_bd_addr_t address, int rssi){
+
304  LOGW("found Device: %s rssi: %d", ssid, rssi);
+
305  //filter out weak signals
+
306  return (rssi > -75);
+
307  }
+
308 
+
309  static void a2dp_state_callback(esp_a2d_connection_state_t state, void *caller){
+
310  TRACED();
+
311  A2DPStream *self = (A2DPStream*)caller;
+
312  if (state==ESP_A2D_CONNECTION_STATE_CONNECTED && self->config.startup_logic==StartOnConnect){
+
313  is_a2dp_active = true;
+
314  }
+
315  LOGW("==> state: %s", self->a2dp->to_str(state));
+
316  }
+
317 
318 
-
319  // at first call we start with some empty data
-
320  if (is_a2dp_active){
-
321  // the data in the file must be in int16 with 2 channels
-
322  yield();
-
323  result_len = a2dp_buffer.readArray((uint8_t*)data, len);
-
324 
-
325  // provide silence data
-
326  if (config.silence_on_nodata && result_len == 0){
-
327  memset(data,0, len);
-
328  result_len = len;
-
329  }
-
330  } else {
-
331 
-
332  // prevent underflow on first call
-
333  switch (config.startup_nodata) {
-
334  case A2DPSilence:
-
335  memset(data, 0, len);
-
336  break;
-
337  case A2DPWhoosh:
-
338  int16_t *data16 = (int16_t*)data;
-
339  for (int j=0;j<len/4;j+=2){
-
340  data16[j+1] = data16[j] = (rand() % 50) - 25;
-
341  }
-
342  break;
-
343  }
-
344  result_len = len;
-
345 
-
346  // Priority: 22 on core 0
-
347  // LOGI("Priority: %d on core %d", uxTaskPriorityGet(NULL), xPortGetCoreID());
-
348 
-
349  }
-
350  LOGD("a2dp_stream_source_sound_data: %d -> %d", len, result_len);
-
351  return result_len;
-
352  }
+
319  // callback used by A2DP to provide the a2dp_source sound data
+
320  static int32_t a2dp_stream_source_sound_data(uint8_t* data, int32_t len) {
+
321  int32_t result_len = 0;
+
322  A2DPConfig config = A2DPStream_self->config;
+
323 
+
324  // at first call we start with some empty data
+
325  if (is_a2dp_active){
+
326  // the data in the file must be in int16 with 2 channels
+
327  yield();
+
328  result_len = a2dp_buffer.readArray((uint8_t*)data, len);
+
329 
+
330  // provide silence data
+
331  if (config.silence_on_nodata && result_len == 0){
+
332  memset(data,0, len);
+
333  result_len = len;
+
334  }
+
335  } else {
+
336 
+
337  // prevent underflow on first call
+
338  switch (config.startup_nodata) {
+
339  case A2DPSilence:
+
340  memset(data, 0, len);
+
341  break;
+
342  case A2DPWhoosh:
+
343  int16_t *data16 = (int16_t*)data;
+
344  for (int j=0;j<len/4;j+=2){
+
345  data16[j+1] = data16[j] = (rand() % 50) - 25;
+
346  }
+
347  break;
+
348  }
+
349  result_len = len;
+
350 
+
351  // Priority: 22 on core 0
+
352  // LOGI("Priority: %d on core %d", uxTaskPriorityGet(NULL), xPortGetCoreID());
353 
-
355  static void a2dp_stream_sink_sound_data(const uint8_t* data, uint32_t len) {
-
356  if (is_a2dp_active){
-
357  uint32_t result_len = a2dp_buffer.writeArray(data, len);
-
358  LOGD("a2dp_stream_sink_sound_data %d -> %d", len, result_len);
-
359  }
-
360  }
-
361 
-
363  void notify_base_Info(int rate){
-
364  AudioInfo info;
-
365  info.channels = 2;
-
366  info.bits_per_sample = 16;
-
367  info.sample_rate = rate;
-
368  notifyAudioChange(info);
-
369  }
-
370 
-
372  static void sample_rate_callback(uint16_t rate) {
-
373  A2DPStream_self->info.sample_rate = rate;
-
374  A2DPStream_self->notify_base_Info(rate);
-
375  }
-
376 
-
377 };
-
378 
-
379 }
+
354  }
+
355  LOGD("a2dp_stream_source_sound_data: %d -> %d", len, result_len);
+
356  return result_len;
+
357  }
+
358 
+
360  static void a2dp_stream_sink_sound_data(const uint8_t* data, uint32_t len) {
+
361  if (is_a2dp_active){
+
362  uint32_t result_len = a2dp_buffer.writeArray(data, len);
+
363  LOGD("a2dp_stream_sink_sound_data %d -> %d", len, result_len);
+
364  }
+
365  }
+
366 
+
368  void notify_base_Info(int rate){
+
369  AudioInfo info;
+
370  info.channels = 2;
+
371  info.bits_per_sample = 16;
+
372  info.sample_rate = rate;
+
373  notifyAudioChange(info);
+
374  }
+
375 
+
377  static void sample_rate_callback(uint16_t rate) {
+
378  A2DPStream_self->info.sample_rate = rate;
+
379  A2DPStream_self->notify_base_Info(rate);
+
380  }
+
381 
+
382 };
+
383 
+
384 }
AudioTools.h
audio_tools::A2DPConfig
Configuration for A2DPStream.
Definition: A2DPStream.h:42
audio_tools::A2DPConfig::silence_on_nodata
bool silence_on_nodata
when a2dp source is active but has no data we generate silence data
Definition: A2DPStream.h:56
@@ -404,16 +408,17 @@
audio_tools::A2DPConfig::name
const char * name
A2DP name.
Definition: A2DPStream.h:50
audio_tools::A2DPConfig::startup_logic
A2DPStartLogic startup_logic
Logic when the processing is activated.
Definition: A2DPStream.h:45
audio_tools::A2DPStream
Stream support for A2DP using https://github.com/pschatzmann/ESP32-A2DP: begin(TX_MODE) opens a a2dp_...
Definition: A2DPStream.h:77
-
audio_tools::A2DPStream::notify_base_Info
void notify_base_Info(int rate)
notify subscriber with AudioInfo
Definition: A2DPStream.h:363
+
audio_tools::A2DPStream::notify_base_Info
void notify_base_Info(int rate)
notify subscriber with AudioInfo
Definition: A2DPStream.h:368
audio_tools::A2DPStream::sink
BluetoothA2DPSink & sink()
provides access to the BluetoothA2DPSink
Definition: A2DPStream.h:116
audio_tools::A2DPStream::buffer
BaseBuffer< uint8_t > & buffer()
Provides access to the buffer.
Definition: A2DPStream.h:286
audio_tools::A2DPStream::readBytes
size_t readBytes(uint8_t *data, size_t len) override
Reads the data from the temporary buffer.
Definition: A2DPStream.h:251
-
audio_tools::A2DPStream::a2dp_stream_sink_sound_data
static void a2dp_stream_sink_sound_data(const uint8_t *data, uint32_t len)
callback used by A2DP to write the sound data
Definition: A2DPStream.h:355
+
audio_tools::A2DPStream::a2dp_stream_sink_sound_data
static void a2dp_stream_sink_sound_data(const uint8_t *data, uint32_t len)
callback used by A2DP to write the sound data
Definition: A2DPStream.h:360
audio_tools::A2DPStream::setVolume
bool setVolume(float volume) override
Define the volume (values between 0.0 and 1.0)
Definition: A2DPStream.h:278
audio_tools::A2DPStream::available
int available() override
Provides the number of bytes available to read.
Definition: A2DPStream.h:263
-
audio_tools::A2DPStream::sample_rate_callback
static void sample_rate_callback(uint16_t rate)
callback to update audio info with used a2dp sample rate
Definition: A2DPStream.h:372
+
audio_tools::A2DPStream::sample_rate_callback
static void sample_rate_callback(uint16_t rate)
callback to update audio info with used a2dp sample rate
Definition: A2DPStream.h:377
audio_tools::A2DPStream::write
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.
Definition: A2DPStream.h:220
audio_tools::A2DPStream::isConnected
bool isConnected()
checks if we are connected
Definition: A2DPStream.h:203
+
audio_tools::A2DPStream::setSilenceOnNoData
void setSilenceOnNoData(bool silence)
Manage config.silence_on_nodata dynamically.
Definition: A2DPStream.h:291
audio_tools::A2DPStream::availableForWrite
int availableForWrite() override
Provides the number of bytes available to write.
Definition: A2DPStream.h:270
audio_tools::A2DPStream::begin
bool begin(RxTxMode mode, const char *name)
Starts the processing.
Definition: A2DPStream.h:124
audio_tools::A2DPStream::~A2DPStream
~A2DPStream()
Release the allocate a2dp_source or a2dp_sink.
Definition: A2DPStream.h:91
diff --git a/classaudio__tools_1_1_a2_d_p_stream-members.html b/classaudio__tools_1_1_a2_d_p_stream-members.html index 77afb0f88..c512ba74e 100644 --- a/classaudio__tools_1_1_a2_d_p_stream-members.html +++ b/classaudio__tools_1_1_a2_d_p_stream-members.html @@ -119,19 +119,20 @@ sample_rate_callback(uint16_t rate)A2DPStreaminlineprotectedstatic setAudioInfo(AudioInfo newInfo) overrideAudioStreaminlinevirtual setNotifyActive(bool flag)AudioInfoSourceinline - setVolume(float volume) overrideA2DPStreaminlinevirtual - sink()A2DPStreaminline - source()A2DPStreaminline - tmp_in (defined in BaseStream)BaseStreamprotected - tmp_out (defined in BaseStream)BaseStreamprotected - volume()VolumeSupportinlinevirtual - volume_value (defined in VolumeSupport)VolumeSupportprotected - write(const uint8_t *data, size_t len) overrideA2DPStreaminlinevirtual - write(uint8_t ch) override (defined in BaseStream)BaseStreaminlinevirtual - writeSilence(size_t len)AudioStreaminlinevirtual - ~A2DPStream()A2DPStreaminline - ~AudioStream()=default (defined in AudioStream)AudioStreamvirtual - ~BaseStream()=default (defined in BaseStream)BaseStreamvirtual + setSilenceOnNoData(bool silence)A2DPStreaminline + setVolume(float volume) overrideA2DPStreaminlinevirtual + sink()A2DPStreaminline + source()A2DPStreaminline + tmp_in (defined in BaseStream)BaseStreamprotected + tmp_out (defined in BaseStream)BaseStreamprotected + volume()VolumeSupportinlinevirtual + volume_value (defined in VolumeSupport)VolumeSupportprotected + write(const uint8_t *data, size_t len) overrideA2DPStreaminlinevirtual + write(uint8_t ch) override (defined in BaseStream)BaseStreaminlinevirtual + writeSilence(size_t len)AudioStreaminlinevirtual + ~A2DPStream()A2DPStreaminline + ~AudioStream()=default (defined in AudioStream)AudioStreamvirtual + ~BaseStream()=default (defined in BaseStream)BaseStreamvirtual