Waveform Generation
Learn how to generate and control waveforms
Overview
flutter_soloud can generate various waveform types without loading audio files. This is useful for synthesizing sound effects, creating game audio, or testing audio systems.
Available Waveforms
The following waveform types are supported:
square
- Square wave oscillatorsaw
- Sawtooth wave oscillatorsin
- Sine wave oscillatortriangle
- Triangle wave oscillatorbounce
- Bouncing ball effectjaws
- Increasing frequency sweephumps
- Multiple humps waveformfsquare
- Filtered square wavefsaw
- Filtered saw wave
Loading Waveforms
Create a waveform sound source:
final sound = await SoLoud.instance.loadWaveform(
WaveForm.sin, // waveform type
true, // enable super wave
1.0, // scale
0.0, // detune
);
Change Waveform Type
// Switch between waveform types
SoLoud.instance.setWaveform(sound, WaveForm.square);
Super Wave Parameters
Super waves create a richer sound by combining multiple oscillators:
// Enable/disable super wave
SoLoud.instance.setWaveformSuperWave(sound, true);
// Adjust super wave scale
SoLoud.instance.setWaveformScale(sound, 2.0);
// Set super wave detune
SoLoud.instance.setWaveformDetune(sound, 0.1);
Simple Tone Generator
// Create a sine wave at 440 Hz (A4 note)
final tone = await SoLoud.instance.loadWaveform(
WaveForm.sin,
false,
1.0,
0.0,
);
// Play the tone
final handle = await SoLoud.instance.play(tone);
// Fade out after 1 second
SoLoud.instance.fadeVolume(
handle,
0.0,
Duration(seconds: 1),
);
Rich Sound Effect
// Create a detuned super saw wave
final richSound = await SoLoud.instance.loadWaveform(
WaveForm.fsaw,
true, // super wave enabled
2.0, // increased scale
0.1, // slight detune
);
// Play with frequency sweep
final handle = await SoLoud.instance.play(richSound);
SoLoud.instance.setWaveformFreq(richSound, 220.0);