Overview of SoLoud audio engine
mainflutter_soloud provides the Flutter plugin interface, the underlying engine is SoLoud.repository·main·Indexed 19 days ago
https://github.com/alnitak/flutter_soloudA high-performance, low-latency audio plugin for Flutter designed for games and immersive applications. It provides advanced features including 3D positional audio, mixing buses, sample-accurate scheduling, and real-time audio visualization via waveforms and FFT data. The plugin supports Android, iOS, macOS, Windows, Linux, and Web, offering capabilities such as pitch shifting, dynamic range compression, and pull-buffer streaming for PCM, MP3, WAV, and Ogg formats.
flutter_soloud provides the Flutter plugin interface, the underlying engine is SoLoud.The plugin is a high-performance, low-latency audio engine suitable for games and immersive apps. Key capabilities include:
playClocked for sub-millisecond spacing and playScheduled for batch scheduling (ideal for rhythm games/sequencers).The example directory contains several implementations demonstrating the capabilities of flutter_soloud. Use these as templates for your own implementation:
lib/main.dart shows the fundamental initialization and usage.lib/output_device/output_device.dart demonstrates how to list and select available audio output devices.lib/audio_data/audio_data.dart shows how to use AudioData for visualization.lib/wave_data/wave_data.dart demonstrates reading and displaying audio samples from files.lib/waveform/waveform.dart) and precise metronome creation (lib/metronome/metronome.dart).Isolate (lib/buffer_stream/generate.dart) or streaming PCM/Opus audio via WebSockets (lib/buffer_stream/websocket.dart).lib/filters/compressor.dart).lib/filters/limiter.dart).lib/filters/pitchshift.dart).Time-stretching is achieved by passing differently sized input and output buffers to the .process() method.
Because inputSamples and outputSamples are integers, you must manage the block lengths so that they average out to your desired stretch ratio over time. There is no maximum block size for either input or output.
The library reports latency in two parts: .inputLatency() and .outputLatency().
Automation Tip: To follow pitch/time automation accurately, provide automation values from the current processing time (.outputLatency() samples ahead of the output) and feed input from .inputLatency() samples ahead of the current processing time.
Managing the lifecycle of a sound (especially fixed-length sounds):
.seek(inputBuffers, inputSamples, playbackRateHint) to move through audio. For the very first block (or after a .reset()), it is recommended to call .seek() with inputSamples = stretch.inputLatency() to align processing time with the start of the input..inputLatency() samples of silence to .process() to ensure the processing time reaches the end..flush(outputBuffers, outputSamples) to read the final remaining output. It is recommended to read at least .outputLatency() samples.// Seeking
stretch.seek(inputBuffers, inputSamples, playbackRateHint);
// Ending a fixed-length sound
// 1. Feed silence to reach the end
float **silence = ...;
stretch.process(silence, stretch.inputLatency(), outputBuffers, outputSamples);
// 2. Flush remaining output
stretch.flush(outputBuffers, outputSamples);To use the library, include signalsmith-stretch.h and instantiate signalsmith::stretch::SignalsmithStretch<T>.
Configuration can be done via presets or manual configuration:
.presetDefault(channels, sampleRate) for standard settings or .presetCheaper(channels, sampleRate) for lower computational cost..configure(channels, blockSamples, intervalSamples) to specify custom block and interval sizes. You can query the current settings using .blockSamples() and .intervalSamples().Both preset and configure methods accept an optional splitComputation flag. When enabled, this spreads computation out more evenly by introducing one extra interval of output latency, which can help in strict real-time environments.
#include "signalsmith-stretch.h"
signalsmith::stretch::SignalsmithStretch<float> stretch;
// Using presets
stretch.presetDefault(2, 44100);
// Manual configuration
stretch.configure(2, 512, 128);If not using CMake, you must manually define preprocessor flags and link frameworks to enable hardware acceleration.
Link the Accelerate framework and define SIGNALSMITH_USE_ACCELERATE:
g++ -framework Accelerate -DSIGNALSMITH_USE_ACCELERATEDefine SIGNALSMITH_USE_IPP and link to IPP::ippcore and IPP::ipps.
Use SIGNALSMITH_USE_PFFFT or SIGNALSMITH_USE_PFFFT_DOUBLE depending on whether you require double-precision support.
g++ -framework Accelerate -DSIGNALSMITH_USE_ACCELERATETo use flutter_soloud, you must first access the singleton instance via SoLoud.instance and call init() before performing any audio operations. When finished with the audio engine, call deinit() to release resources.
You can play sounds in two ways:
playSource(asset: ...) for quick playback.loadAsset(...) to get a Sound object, then use play(sound) to get a SoundHandle. This is more efficient for sounds that will be played multiple times.import 'package:flutter_soloud/flutter_soloud.dart';
void example() async {
final soloud = SoLoud.instance;
await soloud.init();
// Option 1: Play directly from asset
await soloud.playSource(asset: 'assets/sound.mp3');
// Option 2: Pre-load and play
final sound = await soloud.loadAsset('assets/sound.mp3');
final handle = soloud.play(sound);
// ... perform audio operations ...
soloud.deinit();
}To run the sample projects provided in the repository, follow these steps:
example directory.flutter run -t <path_to_file>.git clone https://github.com/alnitak/flutter_soloud.git
cd flutter_soloud/example
flutter pub get
# Run the basic example
flutter run -t lib/main.dart
# Run a specific feature example
flutter run -t lib/waveform/waveform.dartTo change the launch screen image for the iOS version of your Flutter app, you can use one of two methods:
Replace the existing image files located in the example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory with your own assets.
open ios/Runner.xcworkspace from your terminal.Runner/Assets.xcassets.open ios/Runner.xcworkspaceThe library has been tested primarily with AppleClang (Mac) and MSVC (Windows).
Important Notes:
-ffast-math (or equivalent) is supported, except on Apple Clang 16.0.0, which generates incorrect SIMD code with this flag.SIGNALSMITH_USE_ACCELERATE, SIGNALSMITH_USE_IPP, SIGNALSMITH_USE_PFFFT, or SIGNALSMITH_USE_PFFFT_DOUBLE.