#import "Sound_Player";
Procedures#
Samples#
Mixer#
Panning#
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#
Reads a sound file. The result has loaded set when it worked.
Reads a sound from memory. The result has loaded set when it worked.
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).
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#
Makes a stream to play data. Returns null when the sound is not loaded or has more channels than a stream can take.
Makes a stream loop, or stops it from looping.