Overview

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.

You can find further information in the original Readme of the STK Project

Like many other sound libraries it originates from an University (Princeton) and can look back at a very long history: it was created in 1995. In the 90s the computers had limited processor power and memory available. In todays world we can get some cheap Microcontrollers, which provide almost the same capabilities.

The goal of this project has been to implemented the STK as Arduino Library and I hardly knew what I was getting into.

  • Some things were easy to resolve: e.g. I needed to copy the header files into the src directory because Arduino wants it that way.
  • Some others were more difficult: I started to add FreeRTOS functionality to provide the missing multiprocessing and locking functionality. In hindsight that was a waste of time and I came to the conclusion that it is much better just to use the sound generation part of the framework and to use the standard Arduino functionality for doing input and output!

Here is an easy introduction on how to use STK in Arduino.

Unsupported Functionality

Use the Arduino standard functionality instead of the following

  • RtAudioError
  • RtMidi
  • RtMidiError
  • RtMidiIn
  • RtMidiOut
  • RtWvIn (stk)
  • RtWvOut (stk)
  • TcpClient (stk)
  • TcpServer (stk)
  • Mutex (stk)
  • UdpSocket (stk)

Additional Functionality

Output

We provide the following additional Arduino specific output functionality:

  • ArdStreamBinaryOut
  • ArdStreamHexOut
  • ArdStreamOut
  • ArdI2SOut

Raw Files

The framework is using raw files for some instruments (e.g. Mandolin). These files have been converted to binary arrays. It took me more time then expected to figure out how to resolve the restrictions coming from the fact that this data resides in program (flash) memory. Details can be found in my related Blog!

MIDI

The implementation of MIDI was quite easy and I have added quite a few MIDI related classes.

Caveats

I did not have the time to test every functionality, so we might still find some issues.

It also has never been my intention to provide a full implementation of all MIDI networking functionality that is out there but the goal was to cover the integration cases that use standard Arduino functionality.

Installation

Download the project as zip and install the file in the Arduino IDE via -> Sketch -> Include Library -> Add ZIP Library or execute the following command in the Arduino Library Folder

git clone https://github.com/pschatzmann/Arduino-STK.git

4 Comments

Vishal · 25. October 2020 at 6:49

Hi Phil, this seems pretty incredible. I’ve been looking for a way to implement physical modelling synthesis using a microcontroller to make a synthesizer, but I’m very new to microcontrollers, programming for audio, etc. so it seemed like a huge challenge. I think your library is exactly what I need, so thank you for bringing STK to MCUs.

I have one question…I’m not very clear on the difference between ESP32, AVR and ARM cortex processors, but I’ve been experimenting with Teensy 4 (which has an ARM Cortex M7) as it already has a great audio library. How do you think it would work with your library?

    pschatzmann · 26. October 2020 at 16:54

    I think the major challenge is memory. I think the ESP32 has much more memory then the Teensy and honestly even with 4MB PSRAM I hit the memory limits quite quickly because some instruments are using multiple „sound-files“.
    The other challenge is that in Arduino/ESP32 we have the standard C++ standard library (STL) available. I am not sure if you have this with Teensy as well.

    Did you try to compile the library ?

      Vishal · 29. October 2020 at 11:38

      You’re right. After installing STL through Library Manager, I tried to compile the ‘Instrument’ example, but without success. The errors seem to be related to the C++ library (“\Arduino\libraries\ArduinoSTL\src/utility:40:33: error: redefinition of ‘template bool std::rel_ops::operator<=(const T&, const T&)'"). So I tried removing STL, but that resulted in a lot of other errors that I don't understand at all. And of course, the memory issue that you mentioned would come into play, even if it did somehow compile.

      Well, I guess I'll just get myself an ESP32 board, since I do want to play with the STK library (and they're pretty inexpensive too). Thanks for your help, though!

Vishal Bhardwaj · 24. October 2020 at 17:38

Hi Phil, this seems pretty incredible. I’ve been looking for a way to implement physical modelling synthesis using a microcontroller to make a synthesizer, but I’m very new to microcontrollers, programming for audio, etc. so it seemed like a huge challenge. I think your library is exactly what I need, so thank you for bringing STK to MCUs.

I have one question…I’m not very clear on the difference between ESP32, AVR and ARM cortex processors, but I’ve been experimenting with Teensy 4 (which has an ARM Cortex M7) as it already has a great audio library. How do you think it would work with your library?

Leave a Reply

Avatar placeholder

Your email address will not be published.