From c527acfc79f3bda8cfe13a7b51b0b16a32683960 Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 29 Jun 2026 09:41:42 +0900 Subject: First partial working attempt at sound. Producing output, but very distorted --- src/audio.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/audio.c') diff --git a/src/audio.c b/src/audio.c index b5ce1df..7eef433 100644 --- a/src/audio.c +++ b/src/audio.c @@ -27,17 +27,41 @@ #include #include "audio.h" +#include "util.h" -/* ---------------------------------------- INTERFACES +/* ---------------------------------------- INTERNAL DATA */ +static SDL_AudioSpec actual; +static SDL_AudioDeviceID device; + +/* ---------------------------------------- INTERFACES +*/ int AUDIOInit(void) { - return 0; + SDL_AudioSpec spec = {0}; + + spec.freq = SAMPLE_RATE; + spec.format = AUDIO_S8; + spec.channels = 1; + spec.samples = 4096; + + device = SDL_OpenAudioDevice(NULL, 0, &spec, &actual, 0); + + if (device != 0) + { + SDL_PauseAudioDevice(device, 0); + } + + return device != 0; } -void AUDIOQueue(char *buffer, size_t len) +void AUDIOQueue(Uint8 *buffer, size_t len) { + if (device != 0) + { + SDL_QueueAudio(device, buffer, len); + } } -- cgit v1.3