1. Products
  2.   Audio
  3.   C++
  4.   STK
 
  

Free C++ API for Audio Synthesis & Digital Signal Processing

Leading Open Source C++ Library STK(Synthesis ToolKit), enables Software Developers to Audio Synthesis and Digital Signal Processing.Explore its Key features, Real-time Audio Capabilities, and Practical Code Examples for Developers.

What is STK (Synthesis ToolKit)?

The Synthesis ToolKit in C++ (STK) is a prestigious open-source library designed for audio signal processing and algorithmic music synthesis. Developed at Stanford University's CCRMA, it provides developers with a robust set of C++ classes that simplify the creation of complex audio software. Unlike monolithic applications, STK is a collection of unit generators—modular building blocks—that allow for the rapid development of synthesizers, effects processors, and musical instruments. The STK library is valuable for developers working with digital music instruments, audio effects software, game audio engines, sound synthesis research, educational DSP projects and so on.

The Synthesis ToolKit in C++ (STK) is an open-source C++ library that provides reusable classes for audio signal processing, digital synthesis, and musical instrument modeling. It is particularly useful because of its emphasis on portability and ease of use. It shields developers from the low-level complexities of cross-platform audio drivers and MIDI handling, allowing them to focus on the creative aspects of sound design. Whether you are building a professional plugin or an educational tool, STK offers the stability and flexibility required for high-performance real-time audio. Unlike large audio frameworks, STK keeps the architecture simple and transparent. Developers can easily understand how audio algorithms work and modify them for their own experiments. It also provides ready-to-use instrument models like flute, clarinet, and plucked string simulations, which makes it a great starting point for building software synthesizers.

Previous Next

Getting Started with STK

Please use the following command for a complete installation.

Install STK from GitHub

 git clone https://github.com/thestk/stk.git

Real-Time Audio Synthesis

One of the most powerful capabilities of STK is its support for real-time sound generation. Developers can generate audio signals dynamically during program execution rather than relying on pre-recorded samples. This is essential for applications like digital synthesizers, music production tools, and live audio performance software. STK provides efficient processing functions that generate audio frames continuously while maintaining low latency. Because of this capability, STK is often used in research and music technology environments where responsive audio synthesis is required. Here is simple example that demonstrates how STK can generate sound programmatically.

How to Generate Sound Programmatically via C++ Library?

#include "SineWave.h"
#include "RtAudio.h"

int main() {
    stk::SineWave oscillator;
    oscillator.setFrequency(440.0); // A4 note

    for (int i = 0; i < 100; i++) {
        double sample = oscillator.tick();
        std::cout << sample << std::endl;
    }

    return 0;
}

Physical Modeling Instruments

The open source STK library includes built-in classes that simulate real musical instruments using physical modeling algorithms. These models reproduce how instruments behave in the physical world. For examples flute, clarinet, mandolin and bowed string instruments. Physical modeling is useful because it allows developers to control expressive parameters such as breath pressure, bow force, or string vibration.

How to Create Realistic Digital Instruments via STK Library?

#include "Clarinet.h"

int main() {
    stk::Clarinet clarinet;
    
    clarinet.noteOn(440.0, 0.8);

    for(int i = 0; i < 200; i++) {
        double sound = clarinet.tick();
        std::cout << sound << std::endl;
    }

    clarinet.noteOff(0.5);

    return 0;
}
 

Built-in Audio and MIDI Support

The STK library also includes support for real-time audio and MIDI input/output. This enables applications to interact with external devices such as MIDI keyboards and audio interfaces. With MIDI integration, developers can control synthesis parameters in real time, making it possible to create software synthesizers, interactive music applications, live performance tools and so on. The following example create a program that listens for incoming MIDI messages.

How to Listen and Store MIDI Messages inside C++ Apps?

#include "RtMidi.h"

int main() {
    RtMidiIn midi;

    if (midi.getPortCount() == 0) {
        std::cout << "No MIDI ports available!" << std::endl;
        return 0;
    }

    midi.openPort(0);

    std::cout << "Listening for MIDI input..." << std::endl;

    while (true) {
        std::vector message;
        midi.getMessage(&message);

        if (!message.empty()) {
            std::cout << "MIDI message received!" << std::endl;
        }
    }

    return 0;
}

 

Modular Unit Generators via C++

The STK library follows a modular design philosophy, offering a vast array of "unit generators" (UGens). These include oscillators, filters, envelopes, and delay effects that can be patched together like a virtual modular synthesizer. This granularity gives developers total control over the signal chain. Because each class is designed to handle audio frames efficiently, you can build everything from simple sine-wave generators to complex, multi-stage granular synthesis engines by simply connecting different STK objects.