reverted to SDL 1.x compatible audio APIs (which still work in SDL2)
This commit is contained in:
parent
573ffee8b1
commit
22eaa317a8
|
@ -45,8 +45,6 @@ static int audio_sample_size_index = 0;
|
|||
static int audio_channel_count_index = 0;
|
||||
|
||||
// Global variables
|
||||
SDL_AudioDeviceID audio_device = 0;
|
||||
SDL_AudioSpec audio_spec_obtained;
|
||||
static SDL_sem *audio_irq_done_sem = NULL; // Signal from interrupt to streaming thread: data block read
|
||||
static uint8 silence_byte; // Byte value to use to fill sound buffers with silence
|
||||
static uint8 *audio_mix_buf = NULL;
|
||||
|
@ -88,36 +86,40 @@ static bool open_sdl_audio(void)
|
|||
audio_channel_count_index = audio_channel_counts.size() - 1;
|
||||
}
|
||||
|
||||
SDL_AudioSpec audio_spec_desired;
|
||||
SDL_zero(audio_spec_desired);
|
||||
audio_spec_desired.freq = audio_sample_rates[audio_sample_rate_index] >> 16;
|
||||
audio_spec_desired.format = (audio_sample_sizes[audio_sample_size_index] == 8) ? AUDIO_U8 : AUDIO_S16MSB;
|
||||
audio_spec_desired.channels = audio_channel_counts[audio_channel_count_index];
|
||||
audio_spec_desired.samples = 4096;
|
||||
audio_spec_desired.callback = stream_func;
|
||||
audio_spec_desired.userdata = NULL;
|
||||
SDL_AudioSpec audio_spec;
|
||||
SDL_zero(audio_spec);
|
||||
audio_spec.freq = audio_sample_rates[audio_sample_rate_index] >> 16;
|
||||
audio_spec.format = (audio_sample_sizes[audio_sample_size_index] == 8) ? AUDIO_U8 : AUDIO_S16MSB;
|
||||
audio_spec.channels = audio_channel_counts[audio_channel_count_index];
|
||||
audio_spec.samples = 4096;
|
||||
audio_spec.callback = stream_func;
|
||||
audio_spec.userdata = NULL;
|
||||
|
||||
// Open the audio device, forcing the desired format
|
||||
SDL_zero(audio_spec_obtained);
|
||||
audio_device = SDL_OpenAudioDevice(NULL, 0, &audio_spec_desired, &audio_spec_obtained, 0);
|
||||
if (!audio_device) {
|
||||
if (SDL_OpenAudio(&audio_spec, NULL) < 0) {
|
||||
fprintf(stderr, "WARNING: Cannot open audio: %s\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// HACK: workaround a bug in SDL pre-2.0.6 (reported via https://bugzilla.libsdl.org/show_bug.cgi?id=3710 )
|
||||
// whereby SDL does not update audio_spec.size
|
||||
if (audio_spec.size == 0) {
|
||||
audio_spec.size = (SDL_AUDIO_BITSIZE(audio_spec.format) / 8) * audio_spec.channels * audio_spec.samples;
|
||||
}
|
||||
|
||||
#if defined(BINCUE)
|
||||
OpenAudio_bincue(audio_spec_obtained.freq, audio_spec_obtained.format, audio_spec_obtained.channels,
|
||||
audio_spec_obtained.silence);
|
||||
OpenAudio_bincue(audio_spec.freq, audio_spec.format, audio_spec.channels,
|
||||
audio_spec.silence);
|
||||
#endif
|
||||
|
||||
const char * driver_name = SDL_GetCurrentAudioDriver();
|
||||
printf("Using SDL/%s audio output\n", driver_name ? driver_name : "");
|
||||
silence_byte = audio_spec_obtained.silence;
|
||||
SDL_PauseAudioDevice(audio_device, 0);
|
||||
silence_byte = audio_spec.silence;
|
||||
SDL_PauseAudio(0);
|
||||
|
||||
// Sound buffer size = 4096 frames
|
||||
audio_frames_per_block = audio_spec_obtained.samples;
|
||||
audio_mix_buf = (uint8*)malloc(audio_spec_obtained.size);
|
||||
audio_frames_per_block = audio_spec.samples;
|
||||
audio_mix_buf = (uint8*)malloc(audio_spec.size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -166,10 +168,7 @@ void AudioInit(void)
|
|||
static void close_audio(void)
|
||||
{
|
||||
// Close audio device
|
||||
if (audio_device) {
|
||||
SDL_CloseAudioDevice(audio_device);
|
||||
audio_device = 0;
|
||||
}
|
||||
SDL_CloseAudio();
|
||||
free(audio_mix_buf);
|
||||
audio_mix_buf = NULL;
|
||||
audio_open = false;
|
||||
|
@ -232,7 +231,7 @@ static void stream_func(void *arg, uint8 *stream, int stream_len)
|
|||
// Send data to audio device
|
||||
Mac2Host_memcpy(audio_mix_buf, ReadMacInt32(apple_stream_info + scd_buffer), work_size);
|
||||
memset((uint8 *)stream, silence_byte, stream_len);
|
||||
SDL_MixAudioFormat(stream, audio_mix_buf, audio_spec_obtained.format, work_size, audio_volume);
|
||||
SDL_MixAudio(stream, audio_mix_buf, work_size, audio_volume);
|
||||
|
||||
D(bug("stream: data written\n"));
|
||||
|
||||
|
|
|
@ -49,8 +49,6 @@ static int bincue_core_audio_callback(void);
|
|||
#ifdef USE_SDL_AUDIO
|
||||
#include <SDL.h>
|
||||
#include <SDL_audio.h>
|
||||
extern SDL_AudioDeviceID audio_device;
|
||||
extern SDL_AudioSpec audio_spec_obtained;
|
||||
#endif
|
||||
|
||||
#include "bincue_unix.h"
|
||||
|
@ -666,7 +664,7 @@ bool CDPlay_bincue(void *fh, uint8 start_m, uint8 start_s, uint8 start_f,
|
|||
MSF msf;
|
||||
|
||||
#ifdef USE_SDL_AUDIO
|
||||
SDL_LockAudioDevice(audio_device);
|
||||
SDL_LockAudio();
|
||||
#endif
|
||||
|
||||
player.audiostatus = CDROM_AUDIO_NO_STATUS;
|
||||
|
@ -711,7 +709,7 @@ bool CDPlay_bincue(void *fh, uint8 start_m, uint8 start_s, uint8 start_f,
|
|||
D(bug("CDPlay_bincue: play beyond last track !\n"));
|
||||
|
||||
#ifdef USE_SDL_AUDIO
|
||||
SDL_UnlockAudioDevice(audio_device);
|
||||
SDL_UnlockAudio();
|
||||
#endif
|
||||
|
||||
if (audio_enabled) {
|
||||
|
@ -806,7 +804,7 @@ void MixAudio_bincue(uint8 *stream, int stream_len)
|
|||
if (audio_enabled && (player.audiostatus == CDROM_AUDIO_PLAY)) {
|
||||
uint8 *buf = fill_buffer(stream_len);
|
||||
if (buf)
|
||||
SDL_MixAudioFormat(stream, buf, audio_spec_obtained.format, stream_len, SDL_MIX_MAXVOLUME);
|
||||
SDL_MixAudio(stream, buf, stream_len, SDL_MIX_MAXVOLUME);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue