Square wave to the dome
16 Oct 2024
Nothing quite as sobering as taking a 440 hz square wave right to the dome. After fiddling for just over an hour by adjusting the volume, frequency, period, and reading the new SDL3 documentation, I realized that I didn’t have my AudioStream bound to any AudioDevice.
fn SDLInitAudio() !void {
const srcSpec = c.SDL_AudioSpec{
.format = c.SDL_AUDIO_S16,
.channels = 1,
.freq = 48000,
};
const dstSpec = c.SDL_AudioSpec{
.format = c.SDL_AUDIO_F32,
.channels = 2,
.freq = 48000,
};
const audioDeviceId = c.SDL_OpenAudioDevice(c.SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &dstSpec);
if (audioDeviceId == 0) {
c.SDL_LogError(c.SDL_LOG_CATEGORY_APPLICATION, "%s", c.SDL_GetError());
return error.SDLOpenAudioDevice;
}
audioStream = c.SDL_CreateAudioStream(&srcSpec, &dstSpec);
if (audioStream == null) {
c.SDL_LogError(c.SDL_LOG_CATEGORY_APPLICATION, "%s", c.SDL_GetError());
return error.SDLCreateAudioStream;
}
const success = c.SDL_BindAudioStream(audioDeviceId, audioStream);
if (!success) {
c.SDL_LogError(c.SDL_LOG_CATEGORY_APPLICATION, "%s", c.SDL_GetError());
return error.SDLBindAudioStream;
}
}
Now that I have the volume lowered from 30k to 2k, I now have keyboard, gamepad, video, and sound all working for SDL3 using Zig by following alongside Casey Muratori’s Handmade Hero series.
I’m also going to try blogging this process as much as I can. It’s been ages since I have had to write paragraphs of just my rambling, but it could be valuable for future Ian as well as anyone else foolish enough to try making a video game over the course of a decade. My goal for right now is to chuck a few paragraphs into this once a week chronicling my progress.
-Ian