In the last Blog, I have shown how to use the Synthesizer class. I wanted to verify the audio quality issue by sending the output to Bluetooth
Here is the sketch. I just added a callback method to feed the bluetooth source:
Arduino Sketch
#define USE_MIDI
#include "BluetoothA2DPSource.h"
#include "AudioTools.h"
#include "AudioTools/Synthesizer.h"
#include "AudioLibs/AudioKit.h"
BluetoothA2DPSource a2dp_source;
AudioKitStream kit;
Synthesizer synthesizer;
GeneratedSoundStream<int16_t> in(synthesizer);
SynthesizerKey keys[] = {{PIN_KEY1, N_C3},{PIN_KEY2, N_D3},{PIN_KEY3, N_E3},{PIN_KEY4, N_F3},{PIN_KEY5, N_G3},{PIN_KEY6, N_A3},{0,0}};
int32_t get_sound_data(Frame *data, int32_t len) {
int16_t sample = synthesizer.readSamples((int16_t(*)[2])data,len);
delay(1);
return len;
}
void setup() {
Serial.begin(115200);
AudioLogger::instance().begin(Serial,AudioLogger::Info);
// setup synthezizer keys
synthesizer.setKeys(kit.audioActions(), keys, AudioActions::ActiveLow);
synthesizer.setMidiName("AudioKit Synthesizer");
// define generated audio format
auto cfg = in.defaultConfig();
cfg.channels = 2;
cfg.sample_rate = 44100;
in.begin(cfg);
a2dp_source.start("LEXON MINO L", get_sound_data);
a2dp_source.set_volume(20);
}
void loop() {
kit.processActions();
delay(1);
}
I still need the AudioKitStream class, but just to handle the keys. In the get_sound_data callback method we can just forward the call to the synthezizer to provide the data. The delay(1) are necessary to avoid any errors from the Watchdog…
Unfortunately I can confirm the issue with the polyphoinc sound generation: So at least I have narrowed down the source of the problem.
There is also a lag between the key press and the audible sound, which if from my feeling a little bit too high to be practically useful!
Source Code
The (potentially updated) source code can be found in the samples directory.
3 Comments
herman perman · 13. February 2022 at 14:35
Thansk for the answer. This order work:
#include “BluetoothA2DPSource.h”
#include “AudioTools.h”
#include “AudioLibs/AudioKit.h”
herman perman · 13. February 2022 at 12:44
Hi,
this sketch does not work:
##################################################
#include “AudioTools.h”
#include “AudioLibs/AudioKit.h”
#include “BluetoothA2DPSource.h”
void setup() {
}
void loop() {
// put your main code here, to run repeatedly:
}
###############################################
Error:
Arduino/libraries/ESP32-A2DP/src/VolumeControl.h:66:37: error: reference to ‘VolumeControl’ is ambiguous
Any hint to solve that problem?
Best regards
herman
pschatzmann · 13. February 2022 at 13:17
Just use the updated source code indicated in the link indicated under Source Code.
Note: the sequence of imports is important.