Files
breeze/tests/audio_first_cue_host.c
T
waozi a21f90b858 Load cue sounds when wanted and restart stale sync pages
The breath and bell cues are Practices assets. Startup loaded them
while Practices was still opening, so the lookup failed once and the
cues stayed silent. Cues now load when first played and retry after
the asset generation changes.

Background sync kept failing with result 6 because a paged download
resumed from a cursor older than since_server_version, which Daochi
rejects with 400. daochi-client now restarts such a page.
2026-10-30 01:07:03 -03:00

179 lines
3.1 KiB
C

#include "audio_runtime.h"
#include "zir_string.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
static bool ready;
static int errors;
static int initialized;
static int played;
static unsigned int played_frames;
void InitAudioDevice(void)
{
assert(!ready);
ready = true;
initialized++;
}
bool IsAudioDeviceReady(void)
{
return ready;
}
// Radio's background playback is not part of a cue's first frame.
void BackgroundAudioInterrupt(void)
{
}
void CloseAudioDevice(void)
{
ready = false;
}
NativeWave LoadWaveFromMemory(unsigned char *extension, unsigned char *bytes, int size)
{
assert(ready && extension && bytes && size > 0);
NativeWave wave = {0};
wave.frame_count = 128;
wave.data = bytes;
return wave;
}
NativeWave LoadWave(unsigned char *path)
{
(void)path;
assert(0);
return (NativeWave){0};
}
void WaveFormat(NativeWave *wave, int rate, int bits, int channels)
{
(void)rate;
(void)bits;
(void)channels;
assert(wave->frame_count);
}
void UnloadWave(NativeWave wave)
{
assert(wave.frame_count);
}
NativeSound LoadSoundFromWave(NativeWave wave)
{
NativeSound sound = {0};
sound.frame_count = wave.frame_count;
return sound;
}
bool IsSoundValid(NativeSound sound)
{
return sound.frame_count > 0;
}
void UnloadSound(NativeSound sound)
{
assert(sound.frame_count);
}
void StopSound(NativeSound sound)
{
assert(sound.frame_count);
}
void PlaySound(NativeSound sound)
{
assert(ready && sound.frame_count);
played++;
played_frames = sound.frame_count;
}
bool IsSoundPlaying(NativeSound sound)
{
return ready && sound.frame_count == played_frames;
}
void SetSoundVolume(NativeSound sound, float volume)
{
assert(sound.frame_count && volume > 0);
}
void SetSoundPitch(NativeSound sound, float pitch)
{
assert(sound.frame_count && pitch > 0);
}
void AttachAudioMixedProcessor(void (*callback)(void *, unsigned int))
{
assert(callback);
}
void DetachAudioMixedProcessor(void (*callback)(void *, unsigned int))
{
assert(callback);
}
int app_preview_mode(void)
{
return 0;
}
void app_audio_trace(int level, String message)
{
if(level >= 5) {
fprintf(stderr, "%.*s\n", (int)message.length, message.data);
errors++;
}
}
int AudioErrorCount(void)
{
return errors;
}
void app_audio_trace_frames(int level, String message, int frames)
{
(void)message;
assert(level < 5 && frames > 0);
}
void app_audio_meter_raise(int value)
{
(void)value;
}
unsigned char *app_audio_decoder_data(String bytes)
{
return (unsigned char *)bytes.data;
}
String app_audio_cstring_view(Slice bytes)
{
return StringView((char *)bytes.data, strlen((char *)bytes.data));
}
String app_audio_cstring_pointer(unsigned char *bytes, int capacity)
{
(void)capacity;
return StringView((char *)bytes, strlen((char *)bytes));
}
bool app_audio_file_readable(Slice path)
{
(void)path;
return false;
}
int CheckSound(SoundHandle sound)
{
return errors == 0 && sound.frame_count > 0 && played == initialized &&
played_frames == sound.frame_count;
}
int PlayedCount(void)
{
return played;
}