Skip to content

Sound Effects

Hangman edited this page Nov 8, 2021 · 17 revisions

TuningFork allows to enable powerful real time special effects on sound sources.

Attaching An Effect To A Sound Source

First you need to create an effect. We use the reverb effect in this example.

SoundEffect effect = new SoundEffect(new Reverb());

You can then attach it to a source (this works on both BufferedSoundSources and StreamedSoundSources):

soundSource.attachEffect(effect);

Note: You can only attach 2 effects to a sound source in total. If you attach more than 2 effects, the oldest attached effect will be kicked out. Attaching an effect that is already attached to a source does nothing. Though you can attach an effect to as many sound sources as you want.

Detaching Effects

soundSource.detachEffect(effect);

// or to detach all effects
soundSource.detachAllEffects();

Disposing Effects

SoundEffects must be disposed when they are no longer needed. You don't have to detach them before disposing, TuningFork takes care of that.

effect.dispose();

Configuring Effects

All effects have different properties you can change to your needs. For the reverb effect it could look like this:

Reverb reverb = new Reverb(); // initializes the reverb with default values
reverb.density = 0.5f;
reverb.diffusion = 0.8f;
reverb.roomRolloffFactor = 2f;

// now we're ready to create and attach the effect
SoundEffect effect = new SoundEffect(reverb);
soundSource.attachEffect(effect);

The different parameters and their ranges are documented in javadoc, so just let your IDE help you.

Environmental

There's one setting you might want to activate when using reverberation.

effect.setEnvironmental(true);

This is set to false by default. Enabling this leads to a more realistic impression of the environment by dynamical adjustment of effect properties. Usually this is only used for reverb effects that should simulate the environment surrounding the listener or a source. It makes a difference, you should definitely check it out.

Using Effect Presets

There are static factory methods to create effects based on a preset. At the time of writing, there are only presets for EaxReverb.

SoundEffect effect = new SoundEffect(EaxReverb.domeSaintPauls());

An Overview Of Available Effects

These effects are available:

Effect Description
AutoWah The Auto-wah effect emulates the sound of a wah-wah pedal used with an electric guitar, or a mute on a brass instrument. Such effects allow a musician to control the tone of their instrument by varying the point at which high frequencies are cut off.
Chorus The chorus effect essentially replays the input audio accompanied by another slightly delayed version of the signal, creating a doubling effect. This was originally intended to emulate the effect of several musicians playing the same notes simultaneously, to create a thicker, more satisfying sound.
Compressor The Automatic Gain Control effect performs the same task as a studio compressor – evening out the audio dynamic range of an input sound. This results in audio exhibiting smaller variation in intensity between the loudest and quietest portions. The AGC Compressor will boost quieter portions of the audio, while louder portions will stay the same or may even be reduced. The Compressor effect cannot be tweaked in depth – it can just be switched on and off.
Distortion The distortion effect simulates turning up (overdriving) the gain stage on a guitar amplifier or adding a distortion pedal to an instrument’s output. It is achieved by clipping the signal (adding more square wave-like components) and adding rich harmonics. The distortion effect could be very useful for adding extra dynamics to engine sounds in a driving simulator, or modifying samples such as vocal communications.
EaxReverb The EAX Reverb parameter set is a superset of the standard OpenAL Effects Extension environmental reverb effect. Additional parameters allow for: Closer control over the tone of the reverb, Reverb directivity using panning vectors and Reverb granularity using echo controls.
Echo The echo effect generates discrete, delayed instances of the input signal. The amount of delay and feedback is controllable. The delay is two tap – you can control the interaction between two separate instances of echoes.
Equalizer The EQ is very flexible, providing tonal control over four different adjustable frequency ranges.
Flanger The flanger effect creates a "tearing" or "whooshing" sound (like a jet flying overhead).
FrequencyShifter Applications of the frequency shifter include the creation of bizarre distortion, phaser, stereo widening and rotating speaker effects.
PitchShifter The pitch shifter applies time-invariant pitch shifting to the input signal, over a one octave range and controllable at a semi-tone and cent resolution.
Reverb The standard environmental reverberation effect.
RingModulator The ring modulator multiplies an input signal by a carrier signal in the time domain, resulting in tremolo or inharmonic effects.
VocalMorpher The vocal morpher consists of a pair of 4-band formant filters, used to impose vocal tract effects upon the input signal. If the input signal is a broadband sound such as pink noise or a car engine, the vocal morpher can provide a wide variety of filtering effects. A low-frequency oscillator can be used to morph the filtering effect between two different phonemes. The vocal morpher is not necessarily intended for use on voice signals; it is primarily intended for pitched noise effects, vocal-like wind effects, etc.

Full Example

You can find a simple self-contained and runnable example in this repository here.