diff options
| author | skal <pascal.massimino@gmail.com> | 2026-01-28 09:31:13 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-01-28 09:31:13 +0100 |
| commit | 302d883f34864bc66a5e04532ae27d7e89fd94e8 (patch) | |
| tree | 8f813865d5dc5b70ee8bf9ee4866546116859825 /src/audio/audio.cc | |
| parent | f804dcb9740540b3735628ebf8c006235cc56fca (diff) | |
style: Add 3-line descriptive headers to all source files
This commit applies a new project-wide rule that every source file must begin with a concise 3-line comment header describing its purpose.
- Updated CONTRIBUTING.md with the new rule.
- Applied headers to all .cc and .h files in src/ and tools/.
- Fixed various minor compilation errors and missing includes discovered during the header update process.
Diffstat (limited to 'src/audio/audio.cc')
| -rw-r--r-- | src/audio/audio.cc | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/src/audio/audio.cc b/src/audio/audio.cc index 0eceed5..e79e741 100644 --- a/src/audio/audio.cc +++ b/src/audio/audio.cc @@ -1,30 +1,48 @@ +// This file is part of the 64k demo project. +// It manages the low-level audio device and high-level audio state. +// Implementation uses miniaudio for cross-platform support. + +#include "audio.h" #define MINIAUDIO_IMPLEMENTATION #include "miniaudio.h" #include "synth.h" -#include <math.h> -static ma_device device; +#include <stdio.h> + +static ma_device g_device; -static void audio_callback(ma_device *, void *output, const void *, - ma_uint32 frames) { - synth_render((float *)output, frames); +void audio_data_callback(ma_device *pDevice, void *pOutput, const void *pInput, + ma_uint32 frameCount) { + (void)pInput; + float *fOutput = (float *)pOutput; + synth_render(fOutput, (int)frameCount); } void audio_init() { synth_init(); - ma_device_config cfg = ma_device_config_init(ma_device_type_playback); - cfg.playback.format = ma_format_f32; - cfg.playback.channels = 2; - cfg.sampleRate = 32000; - cfg.dataCallback = audio_callback; - ma_device_init(nullptr, &cfg, &device); - ma_device_start(&device); -} + ma_device_config config = ma_device_config_init(ma_device_type_playback); + config.playback.format = ma_format_f32; + config.playback.channels = 2; + config.sampleRate = 32000; + config.dataCallback = audio_data_callback; + + if (ma_device_init(NULL, &config, &g_device) != MA_SUCCESS) { + printf("Failed to open playback device.\n"); + return; + } -void audio_update() { + if (ma_device_start(&g_device) != MA_SUCCESS) { + printf("Failed to start playback device.\n"); + ma_device_uninit(&g_device); + return; + } } + +void audio_update() {} + void audio_shutdown() { + ma_device_stop(&g_device); + ma_device_uninit(&g_device); synth_shutdown(); - ma_device_uninit(&device); -} +}
\ No newline at end of file |
