How to apply BEEP-signal to the Output Stream when you NOT HAVING THE MASTER SIGNAL from BluetoothA2DPSink #932
-
Hi!How to apply BEEP-signal to the Output Stream when you NOT HAVING THE MASTER SIGNAL from BluetoothA2DPSink. Mixer works when you have signals on «both» inputs. But when you stop the BLT signal, you no longer have an output signal on the i2s. So here BLT is the master signal that controls the output signal. But I want to send out a beep when I also don't have this master signal, how do I do this?... Have tried several methods of sending a BEEP-signal out on the i2c bus when I NOT having the master streaming music signal.
How can I do this correctly!.. Have a nice day 😀 My code from my last attempt to send out a BEEP signal when I don't have a Master-BLT signal♬🎸... #include <BluetoothA2DPSink.h>
#include <AudioTools.h>
#define I2S_PORT I2S_NUM_0
BluetoothA2DPSink a2dp_sink; // Music Receiver
I2SStream OutI2S; // Access I2S as stream
static i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
.sample_rate = 44100,
.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,
.dma_buf_count = 4,
.dma_buf_len = 1024,
.use_apll = true,
.tx_desc_auto_clear = true // Avoiding noise in case of data unavailability
};
char BLTNAME[20] = "GuitarSpeaker";
static int BluetoothVolume = 60;
// Apply Effects on an Input Stream
AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave(10000);
GeneratedSoundStream<int16_t> Sound(sineWave);
// Nr-1 MIXER - BluetoothA2DPSink and the Sound-SineWave
OutputMixer<int16_t> mixer(OutI2S, 2);
const int buffer_size = 128;
uint8_t sound_buffer[buffer_size];
//-------------------------------------------------------------------------------------------
// Nr-2 PLAY POLICE-ALARM
StreamCopy copier(OutI2S, Sound); // ♬🎸 Not Bluetooth signal from the Guitar!...
//-------------------------------------------------------------------------------------------
// Copies Sound to OutI2S => BLUETOOTH and SINEWAVE
// Write data to mixer
void read_data_stream(const uint8_t *A2DPdata, uint32_t length) {
// To keep the mixing buffer small we split up the output into small slices
int count = length / buffer_size + 1;
for (int j = 0; j < count; j++) {
const uint8_t *start = A2DPdata + (j * buffer_size);
const uint8_t *end = min(A2DPdata + length, start + buffer_size);
int len = end - start;
if (len > 0) {
// write a2dp slice
mixer.write(start, len);
// write sine tone with identical length
Sound.readBytes(sound_buffer, len);
mixer.write(sound_buffer, len);
}
}
}
void setup() {
a2dp_sink.set_i2s_port(I2S_PORT);
a2dp_sink.set_i2s_config(i2s_config);
// Register data callback for - SINWAVE
a2dp_sink.set_stream_reader(read_data_stream, false);
// Setup Output mixer with min necessary memory
mixer.begin(buffer_size);
// Setup sineWave - Start 0-Hz = OFF
sineWave.begin( info, 0 );
// Start i2s
auto config = OutI2S.defaultConfig();
config.copyFrom(info);
config.pin_data = 2;
config.pin_bck = 32;
config.pin_ws = 33;
config.buffer_count = 8;
config.buffer_size = 256;
OutI2S.begin(config);
// Start Bluetooth Audio Receiver
a2dp_sink.start(BLTNAME, true);
a2dp_sink.set_volume(BluetoothVolume);
}
void loop() {
//------------------------------------------------------------------------------------------------------
// Apply BEEP-signal to the Output Stream when YOU NOT HAVING THE MASTER SIGNAL from BluetoothA2DPSink ♬🎸
//------------------------------------------------------------------------------------------------------
if( a2dp_sink.get_audio_state() == false ){
// PLAY_POLICE_ALARM
int i = 0;
for(i=635; i<912; i++){
sineWave.setFrequency(i);
//################## REBOOT - ERROR ##################
copier.copy(); // PUFF...PUFF...BANG.. ♬🎸 Not Bluetooth signal from the guitar!...
//####################################################
delay(10);
}
for(i=912; i>635; i--){
sineWave.setFrequency(i);
//################## REBOOT - ERROR ##################
copier.copy(); // PUFF...PUFF...BANG.. ♬🎸 Not Bluetooth signal from the guitar!...
//####################################################
delay(10);
}
}
//------------------------------------------------------------------------------------------------------
else{
// To test the mixer - signal!... - OK
sineWave.setFrequency(N_B4); // ♬🎸 Bluetooth signal from the guitar.
delay(1000);
sineWave.setFrequency(0);
}
delay(20000);
}
/* ( THE END ) */ |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Strange question: but with many solutions.
|
Beta Was this translation helpful? Give feedback.
-
👍Thanks for replyFunction Nr-1 «Apply Effects on an Input Stream -MIXER» works as I want. Mix the BLT- signal and the sine/tone signal - OK. But Nr-2 «Police-Alarm» where I come up with my third signal that I want to send out on the i2s-bus that will not work. It is this extra signal that I want to somehow connect to the other signals on the i2s-bus as a independent beep!.. How can I connect this third signal to these, but regardless of the master signal from the BLT?.. 😉 Hope you have a smart solution to this! 😟I have also tried this!.. // Nr-2 PLAY POLICE-ALARM
OutputMixer<int16_t> mixer2(OutI2S, 1); // Output mixer with 1 - outputs mixing to AudioKitStream
StreamCopy copier(mixer2, Sound); // Copies Sound into i2s -> POLICE ALARM
...
mixer2.begin();
...
if( a2dp_sink.get_audio_state() == false ){
// PLAY_POLICE_ALARM
copier.copy(); // PUFF...PUFF...BANG.. ♬🎸 Not Bluetooth signal from the guitar!... |
Beta Was this translation helpful? Give feedback.
-
I am sorry, but I am not here to debug your code! Your sketch is a mess
Finally please also follow these recommendations: https://github.com/pschatzmann/arduino-audio-tools/wiki/It's-not-working |
Beta Was this translation helpful? Give feedback.
Strange question: but with many solutions.