Fixed SDL audio using the wrong audio specification
This bug was responsible for audio on Windows not working without forcefully setting the audio driver to DirectSound. The problem was that WASAPI (or whatever API SDL2 was choosing) defaults to an incompatible audio specification (possibly F32 sample format - I didn't check). Despite the `audio` struct requesting the S16 sample format, SDL2 was granted permission to use whatever format it preferred because it was given the `SDL_AUDIO_ALLOW_ANY_CHANGE` flag. To fix this, I've removed that flag, effectively forcing SDL2 to use the audio specification VBA-M requires.
This commit is contained in:
parent
bb903e5e08
commit
7db3c817eb
|
@ -55,7 +55,7 @@ void SoundSDL::read(uint16_t* stream, int length) {
|
|||
if (length <= 0)
|
||||
return;
|
||||
|
||||
SDL_memset(stream, audio_spec.silence, length);
|
||||
SDL_memset(stream, 0, length);
|
||||
|
||||
// if not initialzed, paused or shutting down, do nothing
|
||||
if (!initialized || !emulating)
|
||||
|
@ -117,11 +117,6 @@ void SoundSDL::write(uint16_t * finalWave, int length) {
|
|||
bool SoundSDL::init(long sampleRate) {
|
||||
if (initialized) deinit();
|
||||
|
||||
// no sound on windows unless we do this
|
||||
#ifdef _WIN32
|
||||
SDL_setenv("SDL_AUDIODRIVER", "directsound", true);
|
||||
#endif
|
||||
|
||||
SDL_AudioSpec audio;
|
||||
SDL_memset(&audio, 0, sizeof(audio));
|
||||
|
||||
|
@ -136,7 +131,7 @@ bool SoundSDL::init(long sampleRate) {
|
|||
|
||||
if (!SDL_WasInit(SDL_INIT_AUDIO)) SDL_Init(SDL_INIT_AUDIO);
|
||||
|
||||
sound_device = SDL_OpenAudioDevice(NULL, 0, &audio, &audio_spec, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||
sound_device = SDL_OpenAudioDevice(NULL, 0, &audio, NULL, 0);
|
||||
|
||||
if(sound_device == 0) {
|
||||
std::cerr << "Failed to open audio: " << SDL_GetError() << std::endl;
|
||||
|
|
Loading…
Reference in New Issue