comparison win95kggui/dep/ft2play/audiodrivers/sdl/sdldriver.c @ 126:8e4ee43d3b81

remove submodules
author Paper <mrpapersonic@gmail.com>
date Sun, 01 Oct 2023 03:48:43 -0400
parents
children
comparison
equal deleted inserted replaced
125:5cc85ef3a675 126:8e4ee43d3b81
1 // SDL audio driver for ft2play
2
3 #include <SDL2/SDL.h>
4 #include <stdint.h>
5 #include <stdbool.h>
6 #include <string.h>
7 #include "../../pmp_mix.h"
8
9 static SDL_AudioDeviceID dev;
10
11 static void SDLCALL audioCallback(void *userdata, Uint8 *stream, int len)
12 {
13 mix_UpdateBuffer((int16_t *)stream, len / 4); // pmp_mix.c function
14 (void)userdata;
15 }
16
17 void lockMixer(void)
18 {
19 if (dev != 0)
20 SDL_LockAudioDevice(dev);
21 }
22
23 void unlockMixer(void)
24 {
25 if (dev != 0)
26 SDL_UnlockAudioDevice(dev);
27 }
28
29 bool openMixer(int32_t mixingFrequency, int32_t mixingBufferSize)
30 {
31 SDL_AudioSpec want, have;
32
33 if (dev != 0)
34 return true;
35
36 if (SDL_Init(SDL_INIT_AUDIO) != 0)
37 return false;
38
39 memset(&want, 0, sizeof (want));
40 want.freq = mixingFrequency;
41 want.format = AUDIO_S16;
42 want.channels = 2;
43 want.samples = (uint16_t)mixingBufferSize;
44 want.callback = audioCallback;
45
46 dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
47 if (dev == 0)
48 return false;
49
50 SDL_PauseAudioDevice(dev, false);
51 return true;
52 }
53
54 void closeMixer(void)
55 {
56 if (dev != 0)
57 {
58 SDL_PauseAudioDevice(dev, true);
59 SDL_CloseAudioDevice(dev);
60 dev = 0;
61 }
62
63 SDL_Quit();
64 }