From 302d883f34864bc66a5e04532ae27d7e89fd94e8 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 28 Jan 2026 09:31:13 +0100 Subject: 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. --- src/audio/audio.cc | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'src/audio/audio.cc') 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 -static ma_device device; +#include + +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); -} -void audio_update() { + 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; + } + + 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 -- cgit v1.2.3