Hello, sound#
The smallest dart-yse program — init the engine, play an audio
file, wait, shut down.
import 'package:yse/yse.dart';
void main() {
final sys = System.instance;
sys.init();
final sound = Sound.fromFile('drone.ogg', loop: true);
sound.play();
// Pump the engine for 3 seconds.
for (var i = 0; i < 180; i++) {
sys.update();
sys.sleep(16);
}
sound.dispose();
sys.close();
}
What just happened#
System.instance.init()opens the default audio device and starts the engine’s worker threads. ThrowsYseExceptionwhen no audio device opens (example/hello_sound.dartcatches it); a host that must also run without audio hardware falls back toinitOffline(), see Sessions and devices.Sound.fromFile('drone.ogg', loop: true)asynchronously loadsdrone.oggand returns aSoundhandle. The file path is relative to the working directory; an absolute path is more predictable.Sound.play()is safe to call before the load finishes — the start is queued.The
update/sleeploop pumps engine state from Dart code. If you prefer event-driven scheduling, callSystem.startUpdateTimer()instead — it runsupdate()off a periodicTimer.sound.dispose()releases the native sound. The DSP buffer it decoded survives in the engine’s cache until the nextSystem.close().System.instance.close()stops the engine and releases the audio device.
What’s not here#
Every call you would make in a real application — but that this minimal example skips — is covered in the tutorials:
3D positioning of sounds and the listener
Volume, pitch, looping
Routing sounds through
ChannelsubtreesReverbzonesThe modular
Patchergraph
See Tutorials for the full walk-through.