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.
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
Create a waveform sound source:
dart
final sound = await SoLoud.instance.loadWaveform(
WaveForm.sin, // waveform type
true, // enable super wave
1.0, // scale
0.0, // detune
);dart
// Switch between waveform types
SoLoud.instance.setWaveform(sound, WaveForm.square);dart
// Set frequency in Hz
SoLoud.instance.setWaveformFreq(sound, 440.0); // A4 noteSuper waves create a richer sound by combining multiple oscillators:
dart
// 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);dart
// 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),
);dart
// 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);- Use simple waveforms for basic sound effects
- Combine super waves for richer sounds
- Consider using filtered waveforms for smoother tones
- Be careful with volume levels when using square waves
- Use frequency sweeps for dynamic effects