actually implement the fun audio settings

This commit is contained in:
Arisotura
2022-09-19 21:56:12 +02:00
parent 502f7d08d4
commit dce96a426d
2 changed files with 37 additions and 1 deletions

View File

@ -104,6 +104,7 @@ bool videoSettingsDirty;
SDL_AudioDeviceID audioDevice; SDL_AudioDeviceID audioDevice;
int audioFreq; int audioFreq;
bool audioMuted;
SDL_cond* audioSync; SDL_cond* audioSync;
SDL_mutex* audioSyncLock; SDL_mutex* audioSyncLock;
@ -141,7 +142,7 @@ void audioCallback(void* data, Uint8* stream, int len)
SDL_CondSignal(audioSync); SDL_CondSignal(audioSync);
SDL_UnlockMutex(audioSyncLock); SDL_UnlockMutex(audioSyncLock);
if (num_in < 1) if ((num_in < 1) || audioMuted)
{ {
memset(stream, 0, len*sizeof(s16)*2); memset(stream, 0, len*sizeof(s16)*2);
return; return;
@ -161,6 +162,23 @@ void audioCallback(void* data, Uint8* stream, int len)
Frontend::AudioOut_Resample(buf_in, num_in, (s16*)stream, len, Config::AudioVolume); Frontend::AudioOut_Resample(buf_in, num_in, (s16*)stream, len, Config::AudioVolume);
} }
void audioMute()
{
int inst = Platform::InstanceID();
audioMuted = false;
switch (Config::MPAudioMode)
{
case 1: // only instance 1
if (inst > 0) audioMuted = true;
break;
case 2: // only currently focused instance
if (!mainWindow->isActiveWindow()) audioMuted = true;
break;
}
}
void micOpen() void micOpen()
{ {
@ -1341,6 +1359,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
setWindowTitle("melonDS " MELONDS_VERSION); setWindowTitle("melonDS " MELONDS_VERSION);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
setAcceptDrops(true); setAcceptDrops(true);
setFocusPolicy(Qt::ClickFocus);
int inst = Platform::InstanceID(); int inst = Platform::InstanceID();
@ -1969,6 +1988,16 @@ void MainWindow::dropEvent(QDropEvent* event)
} }
} }
void MainWindow::focusInEvent(QFocusEvent* event)
{
audioMute();
}
void MainWindow::focusOutEvent(QFocusEvent* event)
{
audioMute();
}
void MainWindow::onAppStateChanged(Qt::ApplicationState state) void MainWindow::onAppStateChanged(Qt::ApplicationState state)
{ {
if (state == Qt::ApplicationInactive) if (state == Qt::ApplicationInactive)
@ -2802,6 +2831,7 @@ void MainWindow::onOpenMPSettings()
void MainWindow::onMPSettingsFinished(int res) void MainWindow::onMPSettingsFinished(int res)
{ {
audioMute();
LocalMP::SetRecvTimeout(Config::MPRecvTimeout); LocalMP::SetRecvTimeout(Config::MPRecvTimeout);
emuThread->emuUnpause(); emuThread->emuUnpause();
@ -3135,6 +3165,7 @@ int main(int argc, char** argv)
format.setSwapInterval(0); format.setSwapInterval(0);
QSurfaceFormat::setDefaultFormat(format); QSurfaceFormat::setDefaultFormat(format);
audioMuted = false;
audioSync = SDL_CreateCond(); audioSync = SDL_CreateCond();
audioSyncLock = SDL_CreateMutex(); audioSyncLock = SDL_CreateMutex();
@ -3188,6 +3219,8 @@ int main(int argc, char** argv)
emuThread->start(); emuThread->start();
emuThread->emuPause(); emuThread->emuPause();
audioMute();
QObject::connect(&melon, &QApplication::applicationStateChanged, mainWindow, &MainWindow::onAppStateChanged); QObject::connect(&melon, &QApplication::applicationStateChanged, mainWindow, &MainWindow::onAppStateChanged);
if (argc > 1) if (argc > 1)

View File

@ -226,6 +226,9 @@ protected:
void dragEnterEvent(QDragEnterEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override; void dropEvent(QDropEvent* event) override;
void focusInEvent(QFocusEvent* event) override;
void focusOutEvent(QFocusEvent* event) override;
signals: signals:
void screenLayoutChange(); void screenLayoutChange();