Modules

Sound_Player

moduleSource
macOSLinuxWindows

#import "Sound_Player";

Procedures#

Samples#

Mixer#

(stream: *Sound_Stream, samples: *s16, page_start: s64, page_end: s64, source_cursor: float64, samples_return: [] float, no_overflow: bool)

Panning#

(camera_position: Vector3, camera_orientation: Quaternion)

Tells the player where the listener is, so sounds with a position can be panned and softened by distance.

Cache#

ADPCM#

Decode queue#

Vorbis#

Loading#

(filename: string, optional := false) -> Sound_Data

Reads a sound file. The result has loaded set when it worked.

(name_for_error_reporting: string, data: string) -> Sound_Data

Reads a sound from memory. The result has loaded set when it worked.

release_sound_datasince 0.31.0
(data: *Sound_Data)

Stops every stream that plays data, frees the bytes it was loaded from and clears it, so that nothing points into it any more.

samples: [64] s16;
data := Sound_Data.{ loaded = true, type = .LINEAR_SAMPLE_ARRAY, samples = samples.data, nsamples_times_nchannels = samples.count };
data.buffer = copy_string("stands in for the file bytes");

release_sound_data(*data);
assert(!data.loaded && data.buffer.count == 0);

Doesn't run in the browser (skipped on wasm).

replace_sound_datasince 0.31.0
(data: *Sound_Data, replacement: Sound_Data) -> bool

Swaps in a new sound for data without moving it: the streams playing the old one are stopped, its bytes are freed and replacement takes its place. Anything that holds the *Sound_Data keeps a valid pointer and gets the new sound from the next make_stream on. This is how to hot-reload a sound.

first := load_audio_data("first", copy_string("not audio"));
assert(!first.loaded); // too short to be a sound; its bytes are still ours
free(first.buffer.data);

samples: [64] s16;
data := Sound_Data.{ loaded = true, type = .LINEAR_SAMPLE_ARRAY, samples = samples.data, nsamples_times_nchannels = samples.count };
data.buffer = copy_string("old bytes");

louder: [64] s16;
louder[0] = 100;
replacement := Sound_Data.{ loaded = true, type = .LINEAR_SAMPLE_ARRAY, samples = louder.data, nsamples_times_nchannels = louder.count };
replacement.buffer = copy_string("new bytes");

assert(replace_sound_data(*data, replacement));
assert(data.samples == louder.data && data.buffer == "new bytes");
release_sound_data(*data);

Doesn't run in the browser (skipped on wasm).

History#

Player#

(data: *Sound_Data, category := Sound_Category.GENERAL_SFX) -> *Sound_Stream

Makes a stream to play data. Returns null when the sound is not loaded or has more channels than a stream can take.

(dt := FLOAT32_INFINITY)

Windows ABI#

Types#

Constants#

:: SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT
:: SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT
:: SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_FRONT_LEFT_OF_CENTER ...
:: SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_SIDE_LEFT | SPEAKER_S ...
:: SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT