Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


STK Fundamentals

The Synthesis ToolKit is implemented in the C++ programming language. STK does not attempt to provide a new programming environment or paradigm but rather provides a set of objects that can be used within a normal C++ programming framework. Therefore, it is expected that users of STK will have some familiarity with C/C++ programming concepts. That said, the STK classes do have some particular idiosyncrasies that we will mention here. Starting with STK version 4.4, all STK classes except RtAudio, RtMidi, and RtError are defined within the stk namespace.

Computations:

Audio and control signals throughout STK use a floating-point data type, StkFloat, the exact precision of which can be controlled via a typedef statement in Stk.h. By default, an StkFloat is a double-precision floating-point value. Thus, the ToolKit can use any normalization scheme desired. The base instruments and algorithms are implemented with a general audio sample dynamic maximum of +/-1.0.

In general, the computation and/or passing of values is performed on a "single-sample" basis. For example, the stk::Noise class outputs random floating-point numbers in the range +/-1.0. The computation of such values occurs in the stk::Noise::tick() function. The following program will generate 20 random floating-point (StkFloat) values in the range -1.0 to +1.0:

#include "Noise.h"
using namespace stk;

int main()
{
  StkFloat output;
  Noise noise;

  for ( unsigned int i=0; i<20; i++ ) {
    output = noise.tick();
    std::cout << "i = " << i << " : output = " << output << std::endl;
  }

  return 0;
}

Nearly all STK classes implement tick() functions that take and/or return sample values. Within the tick() function, the fundamental sample calculations are performed for a given class. Most STK classes consume/generate a single sample per operation and their tick() method takes/returns each sample "by value". In addition, every class implementing a tick() function also provides one or more overloaded tick() functions that can be used for vectorized computations, as shown in the next example.

#include "Noise.h"
using namespace stk;

int main()
{
  StkFrames output(20, 1);   // initialize StkFrames to 20 frames and 1 channel (default: interleaved)
  Noise noise;

  noise.tick( output );
  for ( unsigned int i=0; i<output.size(); i++ ) {
    std::cout << "i = " << i << " : output = " << output[i] << std::endl;
  }

  return 0;
}

In this way, it might be possible to achieve improved processing efficiency using vectorized computations. The StkFrames class is a relatively new addition to the ToolKit to provide a general "mechanism" for handling and passing vectorized, multi-channel audio data. The StkFrames "type" provides functions to set and/or determine the number of audio channels and sample frames it holds. Further, the StkFrames class provides data interpolation and subscripting functionality by frame/channel values.

Inheritance:

Nearly all STK classes inherit from the Stk abstract base class, which provides common functionality related to error reporting, sample rate control, and byte swapping. Several other base classes exist that roughly group many of the classes according to function as follows:

[Main tutorial page]   [Next tutorial]


The Synthesis ToolKit in C++ (STK)
©1995-2012 Perry R. Cook and Gary P. Scavone. All Rights Reserved.