This is a walkthrough of a very simple Tremolo plugin that I created for my senior progject at University. Creating a plugin is as simple as modifying the example provided in the Steinberg Software Developers Kit (SDK) that you can download from Steinberg at: http://www.steinberg.net (visit support and then "3rd Party Developers). The SDK is freely licensed and all you need is a C++ compiler and a text editor to start creating.
With the software developers kit, Steinberg includes the source code for a fully functional gain changing plugin called AGain. This simple plugin reads a sample of audio and adjusts the volume from unity (no adjustments are made) to infinity (no output) depending on the value of the single user adjustable parameter called “Gain”. AGain is the basis for the tremolo plugin, however where tremolo adjusts the volume periodically with time, AGain does not change the volume over time unless the user manually adjusts the settings during playback. The code presented in this tutorial is really just a simple modification of the code from the SDK. If you have read the VST Example Plugin Walkthrough on this site then the following pages will make perfect sense. If not, I suggest you read or print out that tutorial first. Here we go!
Tremolo.h
//------------------------------------------------------------
// Chris Larsen October 2003 Senior Project University of Hartford Ward College
// EA Tremolo
// A stereo plugin that takes audio samples and adjusts their amplitude periodically
// with a user adjustable rate and depth to provide the classic tremolo sound
//------------------------------------------------------------
#ifndef __TREMOLO_H
#define __TREMOLO_H
#include "audioeffectx.h"
enum
{
// Parameters identifiers
kDepth,
kFrequency,
kNumParams
};
Looking at our new tremolo.hpp header file we can see that the comments were changed to reflect the nature of the new plugin. Also the preprocessor declaration names were change to reflect the filename changes. Again the audioeffectx.hpp header file is included so that we can inherit its class. New to the code is the enum statement and our parameter identifiers. An enumeration data type is an ordered list of names (enumerators) that allow for easier reading and code organizing. Each enumerator corresponds to an integer value. In our case “kDepth” = 0, “kFrequency” = 1 and “kNumParams” = 2. If we wanted to add more parameters to our plugin we could insert them just before “kNumParams”. That way “kNumParams” will always contain the actual number of parameters by default. By using the enum data type we can reference “kDepth” and “kFrequency” as the index values in our code instead of having to remember the integer numbers. Paramter names makes it much easier to understand the code. The rest of the function declarations in our header file are the same as the AGain example. The only other difference in the code is where we declare our protected variables after line 50.
protected : float fDepth; float fFrequency; // global counter used to calculate the time long counter; char programName[32];
We declared two float variables to hold the values that our user sets via the GUI for our depth and frequency parameters. We also declared a counter to hold a value we will use to calculate timing information as required by our tremolo equation 8. We will have more information about timing under the process() function.