From 2050c0e0576f05156f192aa4caf48834d2f28b14 Mon Sep 17 00:00:00 2001 From: fschildt Date: Fri, 22 Aug 2025 15:23:11 +0200 Subject: first commit --- src/client/sound.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/client/sound.c (limited to 'src/client/sound.c') diff --git a/src/client/sound.c b/src/client/sound.c new file mode 100644 index 0000000..965f5b1 --- /dev/null +++ b/src/client/sound.c @@ -0,0 +1,52 @@ +#include +#include +#include + + +void +play_sound_update(PlaySound *ps, OSSoundBuffer *dest) +{ + if (!dest) { + return; + } + + i32 samples_readable = ps->sound->sample_count - ps->play_cursor; + i32 samples_writable = dest->sample_count; + i32 samples_to_play; + if (samples_readable > samples_writable) { + samples_to_play = samples_writable; + } else { + samples_to_play = samples_readable; + } + + i16 *from = &ps->sound->samples[ps->play_cursor]; + i16 *to = dest->samples; + for (i32 i = 0; i < samples_to_play; i++) { + to[i] = from[i]; + } + + ps->play_cursor += samples_to_play; +} + + +void +play_sound_init(PlaySound *ps, Sound *sound) +{ + ps->play_cursor = 0; + ps->sound = sound; +} + +Sound * +sound_load(SoundId id) +{ + if (id == 0) { + Sound *sound = (Sound*)(g_asset_sound_user_connected); + sound->samples = (i16*)(sound + 1); + return sound; + } else { + Sound *sound = (Sound*)(g_asset_sound_user_disconnected); + sound->samples = (i16*)(sound + 1); + return sound; + } +} + -- cgit v1.2.3