view win95kggui/dep/ft2play/audiodrivers/sdl/sdldriver.c @ 133:0d8eabdd12ab default tip

create: write H:MM:SS timestamps, add option to fill with gaussian-blur instead of black many albums are longer than one hour so writing H:MM:SS is a necessity. if anything there will just be verbose info that isn't important for my use-case. however the gaussian-blur is simply broken. It works, and it plays locally just fine, but YouTube in particular elongates the video to fit the full width. I'm not entirely sure why it does this, but it makes it useless and ugly.
author Paper <paper@tflc.us>
date Sat, 03 Jan 2026 20:25:38 -0500
parents 8e4ee43d3b81
children
line wrap: on
line source

// SDL audio driver for ft2play

#include <SDL2/SDL.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "../../pmp_mix.h"

static SDL_AudioDeviceID dev;

static void SDLCALL audioCallback(void *userdata, Uint8 *stream, int len)
{
	mix_UpdateBuffer((int16_t *)stream, len / 4); // pmp_mix.c function
	(void)userdata;
}

void lockMixer(void)
{
	if (dev != 0)
		SDL_LockAudioDevice(dev);
}

void unlockMixer(void)
{
	if (dev != 0)
		SDL_UnlockAudioDevice(dev);
}

bool openMixer(int32_t mixingFrequency, int32_t mixingBufferSize)
{
	SDL_AudioSpec want, have;

	if (dev != 0)
		return true;

	if (SDL_Init(SDL_INIT_AUDIO) != 0)
		return false;

	memset(&want, 0, sizeof (want));
	want.freq = mixingFrequency;
	want.format = AUDIO_S16;
	want.channels = 2;
	want.samples = (uint16_t)mixingBufferSize;
	want.callback = audioCallback;

	dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
	if (dev == 0)
		return false;

	SDL_PauseAudioDevice(dev, false);
	return true;
}

void closeMixer(void)
{
	if (dev != 0)
	{
		SDL_PauseAudioDevice(dev, true);
		SDL_CloseAudioDevice(dev);
		dev = 0;
	}

	SDL_Quit();
}