blob: e063a57a648970700e5e70ee4645bbc2fc03ff5f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// This file is part of the 64k demo project.
// It defines the public interface for the audio system.
// Includes initialization, shutdown, and frame updates.
#pragma once
#include "generated/assets.h"
#include <cstdint>
// Forward declarations
class AudioBackend;
class AudioRingBuffer;
// Expose ring buffer for backends
AudioRingBuffer* audio_get_ring_buffer();
struct SpecHeader {
char magic[4];
int32_t version;
int32_t dct_size;
int32_t num_frames;
};
void audio_init();
void audio_start(); // Starts the audio device callback
// Ring buffer audio rendering (main thread fills buffer)
void audio_render_ahead(float music_time, float dt);
// Get current playback time (in seconds) based on samples consumed
// This is the ring buffer READ position (what's being played NOW)
float audio_get_playback_time();
// Get current render time (in seconds) based on samples written
// This is the ring buffer WRITE position (where we're currently rendering)
// Use this for calculating sample-accurate trigger offsets
float audio_get_render_time();
// Get peak amplitude of samples currently being played (real-time sync)
// Returns: Peak amplitude in range [0.0, 1.0+]
// Use this for visual effects to ensure audio-visual synchronization
// Note: Measured at actual playback time, not pre-buffer time (~400ms ahead)
float audio_get_realtime_peak();
#if !defined(STRIP_ALL)
void audio_render_silent(float duration_sec); // Fast-forwards audio state
// Backend injection for testing
void audio_set_backend(AudioBackend* backend);
AudioBackend* audio_get_backend();
#endif /* !defined(STRIP_ALL) */
void audio_update();
void audio_shutdown();
|