Skip to content

Oscillators

In order for your synth to make any sound, it needs to have a generator attached to it. It supports any number of generators, although each one you add has a performance cost. The most important generator is the oscillator. This is the thing that makes musical sound!

Adding oscillators

gml
synth = synth_create();
synth_add_osc(synth, synth_waveform_sine);
synth_add_osc(synth, synth_waveform_saw);
synth_add_osc(synth, synth_waveform_square);
synth_add_osc(synth, synth_waveform_triangle);

The above code will add four oscillators to the synth, one of every kind of waveform preset that comes with SynthEngine. When a note is triggered on the synth, it will play all four of these oscillators at once, combining their waveforms into one single sound.

INFO

SynthEnginePro comes with 20 waveform presets, which you can view here.

Oscillator properties

Each oscillator also has two individually controllable properties:

gml
synth = synth_create();

// Default properties
var _semitone_offset = 0;
var _amp_factor = 1;

synth_add_osc(synth, synth_waveform_sine, _semitone_offset, _amp_factor);

The semitone offset property dictates what note the oscillator should play in terms of musical semitones away from the actual played note. The default value is 0, which means the oscillator will produce the exact note that was played. If you put a value of 12 here, it will be a full octave above the played note, -12 will be a full octave below the played note, 7 will be a perfect fifth above, and so on. You can use this property to create synthesizers that automatically play full chords from one note trigger, for example.

The amp factor property provides a way to control how loud a specific oscillator is. This is 1 by default to indicate full volume. A value of 0 would be totally silent, and 0.5 would be half volume. It's important to know that an amp factor of 0 still requires extra processing power even though no sound is generated.

Custom waveforms

SynthEngine comes with built-in waveform presets, but you can create your own custom waveforms as well. This is done by leveraging GameMaker's animation curve assets. Here's the animation curve for the built-in sine wave:

Sine wave

Notice that the maximum value is 1 and the minimum value is -1. For an animation curve to be a valid SynthEngine waveform, it must stay within the -1 to 1 range of values. As long as you adhere to that rule, you can define any shape that you'd like.

To use these custom shapes with SynthEngine, you can add custom oscillators like this:

gml
synth = synth_create();

var _animation_curve_asset = ac_synth_waves_smooth;
var _curve_name = "Sine";

synth_add_osc_ext(synth, _animation_curve_asset, _curve_name);