is this libary single threaded? #736
-
|
If I use this library will I have a free core to do more work without disturbing the audio? :) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
|
The ESP32 runs the Bluetooth stack on core 0 and the Arduino code on core 1. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @pschatzmann for taking the time to answer. I think what I'm learning from the docs is that a function like If that's the case, then, to update the callback I can give it volatile data? #include "BluetoothA2DPSource.h"
#include <math.h>
#define c3_frequency 130.81
#define D_PHA 0.01
#define DELAY_MS 2
volatile float PHASE = 0.0;
BluetoothA2DPSource a2dp_source;
int32_t get_data_frames(Frame *frame, int32_t frame_count) {
static float m_time = 0.0;
float m_amplitude = 10000.0;
float m_deltaTime = 1.0 / 44100.0;
float pi_2 = PI * 2.0;
float m_phase = PHASE; // <<---- VOLATILE
for (int sample = 0; sample < frame_count; ++sample) {
float angle = pi_2 * c3_frequency * m_time + m_phase;
frame[sample].channel1 = m_amplitude * sin(angle);
frame[sample].channel2 = frame[sample].channel1;
m_time += m_deltaTime;
}
delay(DELAY_MS);
return frame_count;
}
void setup() {
a2dp_source.set_auto_reconnect(false);
a2dp_source.set_data_callback_in_frames(get_data_frames);
a2dp_source.set_volume(30);
a2dp_source.start("MY_BT_HEADPHONES");
}
void loop() {
PHASE = fmod(PHASE + D_PHA, 1.0);
delay(DELAY_MS);
} |
Beta Was this translation helpful? Give feedback.
-
|
I am note sure: I guess this is directly called by the bluetooth stack, so I would be from core 0. |
Beta Was this translation helpful? Give feedback.
-
Sounds like experiments required. Will report back. :) |
Beta Was this translation helpful? Give feedback.
The ESP32 runs the Bluetooth stack on core 0 and the Arduino code on core 1.
The A2DP task is running on the core configured with the set_task_core(BaseType_t core) method; by default it is core 1.