Switch to SDL AudioStream to convert CD Audio

This commit is contained in:
Seth 2019-06-13 12:59:49 -05:00
parent a25325fc7d
commit 2bcfae861f
4 changed files with 36 additions and 11 deletions

View File

@ -252,7 +252,7 @@ static void stream_func(void *arg, uint8 *stream, int stream_len)
silence: memset(stream, silence_byte, stream_len);
}
#if defined(BINCUE)
MixAudio_bincue(stream, stream_len);
MixAudio_bincue(stream, stream_len, audio_volume);
#endif
}

View File

@ -115,6 +115,9 @@ typedef struct {
#ifdef OSX_CORE_AUDIO
OSXsoundOutput soundoutput;
#endif
#ifdef USE_SDL_AUDIO
SDL_AudioStream *stream;
#endif
} CDPlayer;
// Minute,Second,Frame data type
@ -810,25 +813,49 @@ static uint8 *fill_buffer(int stream_len)
#ifdef USE_SDL_AUDIO
void MixAudio_bincue(uint8 *stream, int stream_len)
void MixAudio_bincue(uint8 *stream, int stream_len, int volume)
{
// if (audio_enabled && (player.audiostatus == CDROM_AUDIO_PLAY)) {
// uint8 *buf = fill_buffer(stream_len);
// if (buf)
// SDL_MixAudio(stream, buf, stream_len, volume);
// }
if (audio_enabled && (player.audiostatus == CDROM_AUDIO_PLAY)) {
uint8 *buf = fill_buffer(stream_len);
if (buf)
SDL_MixAudio(stream, buf, stream_len, SDL_MIX_MAXVOLUME);
SDL_AudioStreamPut(player.stream, buf, stream_len);
int avail = SDL_AudioStreamAvailable(player.stream);
if (avail >= stream_len) {
uint8 converted[stream_len];
SDL_AudioStreamGet(player.stream, converted, stream_len);
SDL_MixAudio(stream, converted, stream_len, volume);
}
}
}
void OpenAudio_bincue(int freq, int format, int channels, uint8 silence)
{
if (freq == 44100 && format == AUDIO_S16MSB && channels == 2) {
// audio_enabled = true;
// silence_byte = silence;
// audio stream handles converting cd audio to destination output
player.stream = SDL_NewAudioStream(AUDIO_S16LSB, 2, 44100, format, channels, freq);
if (player.stream == NULL) {
D(bug("Failed to open CD player audio stream using SDL!"));
}
else {
audio_enabled = true;
silence_byte = silence;
}
else {
D(bug("unexpected frequency %d , format %d, or channels %d\n",
freq, format, channels));
}
// audio_enabled = true;
// silence_byte = silence;
// if (freq == 44100 && format == AUDIO_S16MSB && channels == 2) {
// audio_enabled = true;
// silence_byte = silence;
// }
// else {
// D(bug("unexpected frequency %d , format %d, or channels %d\n",
// freq, format, channels));
// }
}
#endif

View File

@ -37,7 +37,7 @@ extern bool CDStop_bincue(void *);
#ifdef USE_SDL_AUDIO
extern void OpenAudio_bincue(int, int, int, uint8);
extern void MixAudio_bincue(uint8 *, int);
extern void MixAudio_bincue(uint8 *, int, int);
#endif
#endif

View File

@ -1291,7 +1291,6 @@
_THREAD_SAFE,
_REENTRANT,
"BINCUE=1",
"OSX_CORE_AUDIO=1",
"USE_SDL_AUDIO=1",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
@ -1354,7 +1353,6 @@
_THREAD_SAFE,
_REENTRANT,
"BINCUE=1",
"OSX_CORE_AUDIO=1",
"USE_SDL_AUDIO=1",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;