v2026.11.2
All Bundles
Bundle

SDL2 multimedia library for 2D graphics, input handling, audio playback, and window management. Core types: Window, Renderer, Texture, Surface, Event, and Mixer. Compile with -lib sdl2.

AudioDevice

An audio playback device fed by queueing samples, for streaming audio generated by the program (synthesis, sonification) rather than loaded from a file. Initialize the audio subsystem first. The device opens paused.

Operations

Clear #

Drop all queued audio that has not played yet

method : public : Clear() ~ Nil

Close #

Close the device; safe to call twice

method : public : Close() ~ Nil

GetId #

Get the SDL audio device id

method : public : GetId() ~ Int

Return

TypeDescription
Intdevice id, 0 if not open

GetQueuedSize #

Get the number of bytes still queued for playback

method : public : GetQueuedSize() ~ Int

Return

TypeDescription
Intqueued byte count, 0 if not open

IsNull #

Determines if the device failed to open or has been closed

method : public : IsNull() ~ Bool

Return

TypeDescription
Booltrue if there is no open device, false otherwise

New # constructor

Open the default playback device for queued audio

New(frequency:Int, format:Int, channels:Int, samples:Int)

Parameters

NameTypeDescription
frequencyIntsamples per second, such as 44100
formatIntsample format, such as AudioFormat->SDL_AUDIO_S16 or AudioFormat->SDL_AUDIO_F32
channelsInt1 for mono, 2 for stereo
samplesIntthe device buffer size in sample frames, a power of 2 such as 4096

Example

Core->Init(SubsystemFlags->SDL_INIT_AUDIO);
device := AudioDevice->New(44100, AudioFormat->SDL_AUDIO_F32, 1, 4096);
if(<>device->IsNull()) {
tone := Float->New[44100];
each(i : tone) {
tone[i] := Float->Sin(2.0 * Float->Pi() * 440.0 * i->As(Float) / 44100.0) * 0.25;
};
device->QueueFloats(tone);
device->Pause(false);
Timer->Delay(1000);
device->Close();
};

Pause #

Pause or resume playback

method : public : Pause(pause:Bool) ~ Nil

Parameters

NameTypeDescription
pauseBooltrue to pause, false to play

Queue #

Queue raw sample bytes, laid out in the device's format, for playback

method : public : Queue(bytes:Byte[]) ~ Int

Parameters

NameTypeDescription
bytesBytethe sample bytes

Return

TypeDescription
Int0 on success or a negative error code on failure

QueueFloats #

Queue samples given as Float values, normally from -1.0 to 1.0, interleaved by channel. The device must have been opened with AudioFormat->SDL_AUDIO_F32.

method : public : QueueFloats(samples:Float[]) ~ Int

Parameters

NameTypeDescription
samplesFloatthe samples

Return

TypeDescription
Int0 on success, or a negative value on failure or for a device of another format