I made the Synthesis ToolKit (SKT) available as Arduino Library.

The Synthesis ToolKit in C++ (STK) is a set of open source audio signal processing and algorithmic synthesis classes written in the C++ programming language. STK was designed to facilitate rapid development of music synthesis and audio processing software, with an emphasis on cross-platform functionality, realtime control, ease of use, and educational example code.

I have demonstrated the MIDI Bluetooth functionality where we can receive MIDI messages over BLE in one of my last posts. Today I will investigate if it is possible to combine this with the output of sound to Bluetooth with A2DP that I have demonstrated in my first post.

The Challenge

So far I have never been using 2 Bluetooth Server processes running in parallel on a ESP32 and this is exactly what we would need: The Bluetooth Sink is starting a Bluetooth Server process for sending sound data and the MIDI BLE Server is running in another process at the same time receiving MIDI messages over BLE.


The functionality is working on a ESP32: I used a Node MCU ESP32 Development Board.
Make sure that you have the latest versions of following libraries installed

The Sketch

We receive MIDI messages via BLE, convert them to sound and send the output to the Bluetooth Sink (e.g. Bluetooth loudspeakers).

The sketch is surprisingly short:

#include "StkAll.h"

Clarinet clarinet(440);
Voicer voicer;
ArdMidiBleServer midi("MidiServer");
ArdBtSource btSource;

void setup() {
  Stk::setSampleRate( 44100.0 );
  voicer.addInstrument(&clarinet, 0);


  btSource.start("RadioPlayer", voicer);

void loop() {

The Voicer is used to communicate between the two processes. It is used to handle the MIDI input by the ArdMidiBleServer and in the ArdBtSource it is used to get and process the sound data.

The startup logic of the ArdMidiBleServer and the ArdBtSource were indeed not compatible. Therfore I added some switches so that we can deactivate the disturbing functionality: setNVSInit(false) is makeing sure that we do not reset the NVS and setResetBLE(false) is making sure that we do not deactivate the BLE MIDI functionality that we have just started before…

If you get compile errors you need to uncomment the #define __BT_A2DP in ArdConfig.h__!

The Testing Environment

I thought that it might be helpful to know how I tested this functionality on my old McBook Air.

Unfortunately my old hardware does not show any BLE devices in the list of Bluetooth devices. I installed BlueSee where they are showing up properly and it is possible to connect from there!

In order to generate the Midi Messages I used Pocket MIDI which is the perfect tool to use if you want to monitor inbound MIDI messages and generate MIDI message for any selected output device. Both are available for free in the Apple App Store.


I think it is pretty impressive that it is possible to define a synthesizer that receives MIDI messages via BLE and sends the output to a Bluetooth Speaker in just with a few lines of code on a cheap 5 USD device…

1 Comment

Holman · 26. June 2022 at 0:41

Hello, this library is spectacular, I can already imagine the number of projects in which it can be used, in fact I have already started one. I have a couple of possible recommendations for a future version, one of them would be to be able to scan and list nearby bluetooth speakers, to be able to choose which one to connect to, the other would be the possibility of adding other instruments such as piano, accordion or harmonica, it would also be useful some tutorial to be able to add more instruments. greetings from Colombia my most sincere congratulations

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *