dp_doom: switch to own sdl sound impl because issues
Wasn't a bug in the sound code at all. This version is just cleaned up and is not compatible with SDL1 anymore.
This commit is contained in:
parent
cd25a3380a
commit
c51f83a5fa
2 changed files with 60 additions and 1 deletions
|
@ -213,7 +213,7 @@ elseif(BACKEND STREQUAL "SDL2")
|
||||||
target_compile_definitions(dp_doom PRIVATE INCLUDE_SDL2_MAIN)
|
target_compile_definitions(dp_doom PRIVATE INCLUDE_SDL2_MAIN)
|
||||||
elseif(BACKEND STREQUAL "nng")
|
elseif(BACKEND STREQUAL "nng")
|
||||||
target_sources(dp_doom PRIVATE
|
target_sources(dp_doom PRIVATE
|
||||||
"linuxdoom-1.10/ib_sound/ib_sound_sdl.c"
|
"linuxdoom-1.10/ib_sound/ib_sound_nng.c"
|
||||||
"linuxdoom-1.10/ib_system/ib_system_nng.c"
|
"linuxdoom-1.10/ib_system/ib_system_nng.c"
|
||||||
"linuxdoom-1.10/ib_video/ib_video_nng.c"
|
"linuxdoom-1.10/ib_video/ib_video_nng.c"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,22 +1,81 @@
|
||||||
#include "../ib_sound.h"
|
#include "../ib_sound.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <dp_common.h>
|
||||||
|
|
||||||
|
#include "SDL.h"
|
||||||
|
|
||||||
|
/* The function that actually produces the output audio */
|
||||||
|
static void (*audio_callback)(short* output_buffer, size_t frames_to_do, void *user_data);
|
||||||
|
|
||||||
|
static void dp_sdl_error(const char *const msg)
|
||||||
|
{
|
||||||
|
log_error("%s: %s", msg, SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
static SDL_AudioDeviceID audio_device;
|
||||||
|
|
||||||
|
static void Callback(void *user_data, Uint8 *output_buffer, int bytes_to_do)
|
||||||
|
{
|
||||||
|
const int frames_to_do = bytes_to_do / 2 / sizeof(short);
|
||||||
|
|
||||||
|
audio_callback((short*)output_buffer, (size_t)frames_to_do, user_data);
|
||||||
|
}
|
||||||
|
|
||||||
int IB_StartupSound(void (*initial_callback)(unsigned int output_sample_rate, void *user_data), void (*_audio_callback)(short* output_buffer, size_t frames_to_do, void *user_data), void *user_data)
|
int IB_StartupSound(void (*initial_callback)(unsigned int output_sample_rate, void *user_data), void (*_audio_callback)(short* output_buffer, size_t frames_to_do, void *user_data), void *user_data)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
unsigned int freq = 48000;
|
unsigned int freq = 48000;
|
||||||
initial_callback(freq, user_data);
|
initial_callback(freq, user_data);
|
||||||
return 1;
|
return 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SDL_AudioSpec desired_audio_specification;
|
||||||
|
SDL_AudioSpec obtained_audio_specification;
|
||||||
|
|
||||||
|
audio_callback = _audio_callback;
|
||||||
|
|
||||||
|
if (SDL_Init(SDL_INIT_AUDIO))
|
||||||
|
{
|
||||||
|
dp_sdl_error("IB_StartupSound: SDL_INIT_AUDIO failed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
desired_audio_specification.freq = 48000;
|
||||||
|
desired_audio_specification.format = AUDIO_S16;
|
||||||
|
desired_audio_specification.channels = 2;
|
||||||
|
desired_audio_specification.samples = 0x200; /* About 10ms at 48000Hz. */
|
||||||
|
desired_audio_specification.callback = Callback;
|
||||||
|
desired_audio_specification.userdata = user_data;
|
||||||
|
|
||||||
|
audio_device = SDL_OpenAudioDevice(NULL,
|
||||||
|
0, &desired_audio_specification, &obtained_audio_specification,
|
||||||
|
SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_SAMPLES_CHANGE);
|
||||||
|
|
||||||
|
if (audio_device)
|
||||||
|
{
|
||||||
|
initial_callback(obtained_audio_specification.freq, user_data);
|
||||||
|
SDL_PauseAudioDevice(audio_device, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dp_sdl_error("IB_StartupSound: SDL_INIT_AUDIO failed");
|
||||||
|
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IB_ShutdownSound(void)
|
void IB_ShutdownSound(void)
|
||||||
{
|
{
|
||||||
|
SDL_CloseAudioDevice(audio_device);
|
||||||
|
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IB_LockSound(void)
|
void IB_LockSound(void)
|
||||||
{
|
{
|
||||||
|
SDL_LockAudioDevice(audio_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IB_UnlockSound(void)
|
void IB_UnlockSound(void)
|
||||||
{
|
{
|
||||||
|
SDL_UnlockAudioDevice(audio_device);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue