Skip to content

Creating a synthesizer

Each synthesizer has a few properties that you can specify on creation. These are polyphony, channels, format, and sample rate:

gml
var _polyphony = 4;
var _channels = audio_stereo;
var _format = buffer_s16;
var _sample_rate = 44100;

// Create a synthesizer using all of the default values
synth = synth_create(_polyphony, _channels, _format, _sample_rate);

// The same result as above
synth = synth_create();

Polyphony

Arguably the most important of these is polyphony, as this dictates how many notes can be played at once when playing live (when using the synth_note_* functions). The default polyphony is 4, but can be any number above 0. An important thing to note is that the more notes played simultaneously, the more operations have to be done per-frame, so higher simultaneous notes come with a performance cost. For single oscillator synthesizers, 6 notes can usually be handled with ease at 60 frames per second.

INFO

Polyphony only has an effect on live audio, since rendering audio will always only produce one single note from the synthesizer.

Channels

Channels dictates if the synthesizer outputs audio in mono or stereo. This defaults to stereo (audio_stereo), which supports left/right panning on your audio. You can make your synthesizer mono by using audio_mono for this argument. Doing so will remove the ability to pan your audio, but will halve the amount of data that needs to be written, and so can have a slightly positive effect on performance.

Format

Format is the kind of data that should be written to the buffer. GameMaker only supports buffer_s16 (the default) and buffer_u8, so those are the only two allowed values. Using buffer_u8 will (theoretically) result in lower quality audio, but will result in half of the bytes needed to be written per sample, and so can have a positive effect on performance.

Sample rate

The final argument is sample rate, which is how many samples per second are processed as audio. The default is 44100, which is a common number for audio. GameMaker supports any value between 8000 and 48000, but note that higher numbers require more samples to be written and thus come with a performance hit. Lower values result in lower quality audio, but can have a positive effect on performance since less samples have to be generated.

Synth data

The return value of synth_create() is a reference to an instance of obj_synth_engine that manages this synthesizer. This means that each synth you create also creates an instance, and this also means you can't create a synth on the first frame of your game via a script asset (since instances can't be created this way either). It's recommended to create a synth in the create event of an object.

Attached to the instance is an instance variable data which is a big struct that contains all of the information to make the synthesizer operate correctly, including a handful of buffers and an audio queue. It is not recommended to edit this data, but it may be helpful to access this data to get information about your synthesizer after it's already been created. An example of how you might inspect that data is by logging a debug message:

gml
show_debug_message(synth.data);