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;
int audioFreq;
bool audioMuted;
SDL_cond* audioSync;
SDL_mutex* audioSyncLock;
@ -141,7 +142,7 @@ void audioCallback(void* data, Uint8* stream, int len)
SDL_CondSignal(audioSync);
SDL_UnlockMutex(audioSyncLock);
if (num_in < 1)
if ((num_in < 1) || audioMuted)
{
memset(stream, 0, len*sizeof(s16)*2);
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);
}
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()
{
@ -1341,6 +1359,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
setWindowTitle("melonDS " MELONDS_VERSION);
setAttribute(Qt::WA_DeleteOnClose);
setAcceptDrops(true);
setFocusPolicy(Qt::ClickFocus);
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)
{
if (state == Qt::ApplicationInactive)
@ -2802,6 +2831,7 @@ void MainWindow::onOpenMPSettings()
void MainWindow::onMPSettingsFinished(int res)
{
audioMute();
LocalMP::SetRecvTimeout(Config::MPRecvTimeout);
emuThread->emuUnpause();
@ -3135,6 +3165,7 @@ int main(int argc, char** argv)
format.setSwapInterval(0);
QSurfaceFormat::setDefaultFormat(format);
audioMuted = false;
audioSync = SDL_CreateCond();
audioSyncLock = SDL_CreateMutex();
@ -3188,6 +3219,8 @@ int main(int argc, char** argv)
emuThread->start();
emuThread->emuPause();
audioMute();
QObject::connect(&melon, &QApplication::applicationStateChanged, mainWindow, &MainWindow::onAppStateChanged);
if (argc > 1)

View File

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