Skip to content

Commit

Permalink
SDL: Use SDL2 audio API for output.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Oct 8, 2019
1 parent daf0703 commit 141258c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
20 changes: 13 additions & 7 deletions Qt/QtMain.cpp
Expand Up @@ -29,7 +29,9 @@
#ifdef SDL
#include "SDL/SDLJoystick.h"
#include "SDL_audio.h"
#define MainAudioDeviceID SDL_AudioDeviceID
#endif
#define MainAudioDeviceID int
#include "QtMain.h"
#include "gfx_es2/gpu_features.h"
#include "i18n/i18n.h"
Expand Down Expand Up @@ -168,7 +170,7 @@ float CalculateDPIScale()
#endif
}

static int mainInternal(QApplication &a) {
static int mainInternal(QApplication &a, MainAudioDeviceID &audioDev) {
#ifdef MOBILE_DEVICE
emugl = new MainUI();
emugl->resize(pixel_xres, pixel_yres);
Expand All @@ -194,7 +196,8 @@ static int mainInternal(QApplication &a) {
fmt.callback = &mixaudio;
fmt.userdata = (void *)0;

if (SDL_OpenAudio(&fmt, &ret_fmt) < 0) {
audioDev = SDL_OpenAudioDevice(nullptr, 0, &fmt, &ret_fmt, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
if (audioDev <= 0) {
ELOG("Failed to open audio: %s", SDL_GetError());
} else {
if (ret_fmt.samples != fmt.samples) // Notify, but still use it
Expand All @@ -205,10 +208,10 @@ static int mainInternal(QApplication &a) {
ELOG("Output audio format: %d (requested: %d)", ret_fmt.format, fmt.format);
ELOG("Output audio channels: %d (requested: %d)", ret_fmt.channels, fmt.channels);
ELOG("Provided output format does not match requirement, turning audio off");
SDL_CloseAudio();
SDL_CloseAudioDevice(audioDev);
}
SDL_PauseAudioDevice(audioDev, 0);
}
SDL_PauseAudio(0);
#else
QScopedPointer<MainAudio> audio(new MainAudio());
audio->run();
Expand Down Expand Up @@ -608,12 +611,15 @@ int main(int argc, char *argv[])
// TODO: Support other backends than GL, like Vulkan, in the Qt backend.
g_Config.iGPUBackend = (int)GPUBackend::OPENGL;

int ret = mainInternal(a);
MainAudioDeviceID audioDev = 0;
int ret = mainInternal(a, audioDev);
ILOG("Left mainInternal here.");

#ifdef SDL
SDL_PauseAudio(1);
SDL_CloseAudio();
if (audioDev > 0) {
SDL_PauseAudioDevice(audioDev, 1);
SDL_CloseAudioDevice(audioDev);
}
#endif
NativeShutdown();
glslang::FinalizeProcess();
Expand Down
16 changes: 10 additions & 6 deletions SDL/SDLMain.cpp
Expand Up @@ -582,7 +582,8 @@ int main(int argc, char *argv[]) {
fmt.callback = &mixaudio;
fmt.userdata = (void *)0;

if (SDL_OpenAudio(&fmt, &ret_fmt) < 0) {
SDL_AudioDeviceID audioDev = SDL_OpenAudioDevice(nullptr, 0, &fmt, &ret_fmt, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
if (audioDev <= 0) {
ELOG("Failed to open audio: %s", SDL_GetError());
} else {
if (ret_fmt.samples != fmt.samples) // Notify, but still use it
Expand All @@ -593,12 +594,13 @@ int main(int argc, char *argv[]) {
ELOG("Output audio format: %d (requested: %d)", ret_fmt.format, fmt.format);
ELOG("Output audio channels: %d (requested: %d)", ret_fmt.channels, fmt.channels);
ELOG("Provided output format does not match requirement, turning audio off");
SDL_CloseAudio();
SDL_CloseAudioDevice(audioDev);
}

// Audio must be unpaused _after_ NativeInit()
SDL_PauseAudioDevice(audioDev, 0);
}

// Audio must be unpaused _after_ NativeInit()
SDL_PauseAudio(0);
if (joystick_enabled) {
joystick = new SDLJoystick();
} else {
Expand Down Expand Up @@ -927,8 +929,10 @@ int main(int argc, char *argv[]) {
graphicsContext->ShutdownFromRenderThread();
delete graphicsContext;

SDL_PauseAudio(1);
SDL_CloseAudio();
if (audioDev > 0) {
SDL_PauseAudioDevice(audioDev, 1);
SDL_CloseAudioDevice(audioDev);
}
SDL_Quit();
#if PPSSPP_PLATFORM(RPI)
bcm_host_deinit();
Expand Down

0 comments on commit 141258c

Please sign in to comment.