You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you Start and Stop the Music too quickly (for example from Spotify) before or at the end of the Main loop, the OutputMixer goes into lock/crasy.
When you continues to play music again and adding more Bluetooth-Data then everything works as it should again!
How can I check that I have sufficient Music data stored in cache before running the Sin-frequency => Play(XX.YY) function!... So that the OutputMixer does not stall!... (Should only play Note when I have music).
Have tested around a bit with: mixer.flushMixer();
#include<BluetoothA2DPSink.h>
#include<AudioConfig.h>
#include<AudioTools.h>
I2SStream OutI2S;
BluetoothA2DPSink a2dp_sink(OutI2S);
AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave(10000);
GeneratedSoundStream<int16_t> Sound(sineWave);
OutputMixer<int16_t> mixer(OutI2S, 2);
constint buffer_size = 128;
uint8_t sound_buffer[buffer_size];
//=================================================================// Enough Bluetooth-Data ?..//=================================================================// How to test that I have enough Bluetooth Data in Cache?...//=================================================================voidPlay(float frequency, int durationMs) {
sineWave.setFrequency(frequency);
delay(durationMs);
sineWave.setFrequency(0);
}
//=================================================================voidRead_Data_Stream(constuint8_t *A2DPdata, uint32_t length) {
// Write data to Mixer.// To keep the mixing buffer small we split up the output into small chunksint count = length / buffer_size + 1;
for (int j = 0; j < count; j++) {
constuint8_t *start = A2DPdata + (j * buffer_size);
constuint8_t *end = min(A2DPdata + length, start + buffer_size);
int len = end - start;
if (len > 0) {
// write a2dp
mixer.write(start, len);
// write sine tone with identical length
Sound.readBytes(sound_buffer, len);
mixer.write(sound_buffer, len);
}
}
}
voidsetup() {
// Register data callback
a2dp_sink.set_stream_reader(Read_Data_Stream, false);
// Setup Output mixer with min necessary memory
mixer.begin(buffer_size); // 128// Update sample rate
info.sample_rate = a2dp_sink.sample_rate();
// Start sine wave
sineWave.begin(info, 0);
// Setup Outputauto config = OutI2S.defaultConfig();
config.copyFrom(info);
// Configure I2S pins for the external DAC - PCM5102
config.pin_data = 25; // Data pin -> 25
config.pin_bck = 32; // Bit Clock pin
config.pin_ws = 33; // Word Select pin
config.buffer_count = 4;
config.buffer_size = buffer_size; // 4*128=1024
OutI2S.begin(config);
// Start Bluetooth Audio
a2dp_sink.start("BluetoothAudio", true);
}
//--------------------------------------------------------// If not enough Music data..."MAD-MAX..."//--------------------------------------------------------voidloop() {
Play(N_E5, 700);
Play(N_CS5, 700);
Play(N_A4, 700);
delay(5000);
}
//--------------------------------------------------------
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
ツ🎵 Hope someone can help me with this!
If you Start and Stop the Music too quickly (for example from Spotify) before or at the end of the Main loop, the OutputMixer goes into lock/crasy.
When you continues to play music again and adding more Bluetooth-Data then everything works as it should again!
How can I check that I have sufficient Music data stored in cache before running the Sin-frequency => Play(XX.YY) function!...
So that the OutputMixer does not stall!... (Should only play Note when I have music).
Have tested around a bit with: mixer.flushMixer();
Beta Was this translation helpful? Give feedback.
All reactions