port audio settings to new config system

This commit is contained in:
Arisotura 2024-05-23 02:23:24 +02:00
parent d634c450bb
commit daf981e7c2
12 changed files with 132 additions and 75 deletions

View File

@ -16,7 +16,6 @@
with melonDS. If not, see http://www.gnu.org/licenses/. with melonDS. If not, see http://www.gnu.org/licenses/.
*/ */
#include <stdio.h>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <QFileDialog> #include <QFileDialog>
@ -25,12 +24,10 @@
#include "Config.h" #include "Config.h"
#include "NDS.h" #include "NDS.h"
#include "DSi.h" #include "DSi.h"
#include "DSi_I2C.h"
#include "AudioSettingsDialog.h" #include "AudioSettingsDialog.h"
#include "ui_AudioSettingsDialog.h" #include "ui_AudioSettingsDialog.h"
#include "main.h" #include "main.h"
#include "EmuInstance.h"
using namespace melonDS; using namespace melonDS;
AudioSettingsDialog* AudioSettingsDialog::currentDlg = nullptr; AudioSettingsDialog* AudioSettingsDialog::currentDlg = nullptr;
@ -44,41 +41,49 @@ AudioSettingsDialog::AudioSettingsDialog(QWidget* parent) : QDialog(parent), ui(
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
emuInstance = ((MainWindow*)parent)->getEmuInstance(); emuInstance = ((MainWindow*)parent)->getEmuInstance();
auto& cfg = emuInstance->getGlobalConfig();
auto& instcfg = emuInstance->getLocalConfig();
bool emuActive = emuInstance->getEmuThread()->emuIsActive(); bool emuActive = emuInstance->getEmuThread()->emuIsActive();
oldInterp = Config::AudioInterp; oldInterp = cfg.GetInt("Audio.Interpolation");
oldBitDepth = Config::AudioBitDepth; oldBitDepth = cfg.GetInt("Audio.BitDepth");
oldVolume = Config::AudioVolume; oldVolume = instcfg.GetInt("Audio.Volume");
oldDSiSync = Config::DSiVolumeSync; oldDSiSync = instcfg.GetBool("Audio.DSiVolumeSync");
volume = oldVolume;
dsiSync = oldDSiSync;
ui->cbInterpolation->addItem("None"); ui->cbInterpolation->addItem("None");
ui->cbInterpolation->addItem("Linear"); ui->cbInterpolation->addItem("Linear");
ui->cbInterpolation->addItem("Cosine"); ui->cbInterpolation->addItem("Cosine");
ui->cbInterpolation->addItem("Cubic"); ui->cbInterpolation->addItem("Cubic");
ui->cbInterpolation->addItem("Gaussian (SNES)"); ui->cbInterpolation->addItem("Gaussian (SNES)");
ui->cbInterpolation->setCurrentIndex(Config::AudioInterp); ui->cbInterpolation->setCurrentIndex(oldInterp);
ui->cbBitDepth->addItem("Automatic"); ui->cbBitDepth->addItem("Automatic");
ui->cbBitDepth->addItem("10-bit"); ui->cbBitDepth->addItem("10-bit");
ui->cbBitDepth->addItem("16-bit"); ui->cbBitDepth->addItem("16-bit");
ui->cbBitDepth->setCurrentIndex(Config::AudioBitDepth); ui->cbBitDepth->setCurrentIndex(oldBitDepth);
bool state = ui->slVolume->blockSignals(true); bool state = ui->slVolume->blockSignals(true);
ui->slVolume->setValue(Config::AudioVolume); ui->slVolume->setValue(oldVolume);
ui->slVolume->blockSignals(state); ui->slVolume->blockSignals(state);
ui->chkSyncDSiVolume->setChecked(Config::DSiVolumeSync); ui->chkSyncDSiVolume->setChecked(oldDSiSync);
// Setup volume slider accordingly // Setup volume slider accordingly
if (emuActive && emuInstance->getNDS()->ConsoleType == 1) if (emuActive && emuInstance->getNDS()->ConsoleType == 1)
{ {
on_chkSyncDSiVolume_clicked(Config::DSiVolumeSync); on_chkSyncDSiVolume_clicked(oldDSiSync);
} }
else else
{ {
ui->chkSyncDSiVolume->setEnabled(false); ui->chkSyncDSiVolume->setEnabled(false);
} }
bool isext = (Config::MicInputType == 1);
int mictype = cfg.GetInt("Mic.InputType");
bool isext = (mictype == micInputType_External);
ui->cbMic->setEnabled(isext); ui->cbMic->setEnabled(isext);
const int count = SDL_GetNumAudioDevices(true); const int count = SDL_GetNumAudioDevices(true);
@ -86,12 +91,14 @@ AudioSettingsDialog::AudioSettingsDialog(QWidget* parent) : QDialog(parent), ui(
{ {
ui->cbMic->addItem(SDL_GetAudioDeviceName(i, true)); ui->cbMic->addItem(SDL_GetAudioDeviceName(i, true));
} }
if (Config::MicDevice == "" && count > 0)
QString micdev = cfg.GetQString("Mic.Device");
if (micdev == "" && count > 0)
{ {
Config::MicDevice = SDL_GetAudioDeviceName(0, true); micdev = SDL_GetAudioDeviceName(0, true);
} }
ui->cbMic->setCurrentText(QString::fromStdString(Config::MicDevice)); ui->cbMic->setCurrentText(micdev);
grpMicMode = new QButtonGroup(this); grpMicMode = new QButtonGroup(this);
grpMicMode->addButton(ui->rbMicNone, micInputType_Silence); grpMicMode->addButton(ui->rbMicNone, micInputType_Silence);
@ -99,15 +106,15 @@ AudioSettingsDialog::AudioSettingsDialog(QWidget* parent) : QDialog(parent), ui(
grpMicMode->addButton(ui->rbMicNoise, micInputType_Noise); grpMicMode->addButton(ui->rbMicNoise, micInputType_Noise);
grpMicMode->addButton(ui->rbMicWav, micInputType_Wav); grpMicMode->addButton(ui->rbMicWav, micInputType_Wav);
connect(grpMicMode, SIGNAL(buttonClicked(int)), this, SLOT(onChangeMicMode(int))); connect(grpMicMode, SIGNAL(buttonClicked(int)), this, SLOT(onChangeMicMode(int)));
grpMicMode->button(Config::MicInputType)->setChecked(true); grpMicMode->button(mictype)->setChecked(true);
ui->txtMicWavPath->setText(QString::fromStdString(Config::MicWavPath)); ui->txtMicWavPath->setText(cfg.GetQString("Mic.WavPath"));
bool iswav = (Config::MicInputType == micInputType_Wav); bool iswav = (mictype == micInputType_Wav);
ui->txtMicWavPath->setEnabled(iswav); ui->txtMicWavPath->setEnabled(iswav);
ui->btnMicWavBrowse->setEnabled(iswav); ui->btnMicWavBrowse->setEnabled(iswav);
int inst = Platform::InstanceID(); int inst = emuInstance->getInstanceID();
if (inst > 0) if (inst > 0)
{ {
ui->lblInstanceNum->setText(QString("Configuring settings for instance %1").arg(inst+1)); ui->lblInstanceNum->setText(QString("Configuring settings for instance %1").arg(inst+1));
@ -130,26 +137,30 @@ AudioSettingsDialog::~AudioSettingsDialog()
void AudioSettingsDialog::onSyncVolumeLevel() void AudioSettingsDialog::onSyncVolumeLevel()
{ {
if (Config::DSiVolumeSync && emuInstance->getNDS()->ConsoleType == 1) if (dsiSync && emuInstance->getNDS()->ConsoleType == 1)
{ {
auto dsi = static_cast<DSi*>(emuInstance->getNDS()); auto dsi = static_cast<DSi*>(emuInstance->getNDS());
volume = dsi->I2C.GetBPTWL()->GetVolumeLevel();
bool state = ui->slVolume->blockSignals(true); bool state = ui->slVolume->blockSignals(true);
ui->slVolume->setValue(dsi->I2C.GetBPTWL()->GetVolumeLevel()); ui->slVolume->setValue(volume);
ui->slVolume->blockSignals(state); ui->slVolume->blockSignals(state);
} }
} }
void AudioSettingsDialog::onConsoleReset() void AudioSettingsDialog::onConsoleReset()
{ {
on_chkSyncDSiVolume_clicked(Config::DSiVolumeSync); on_chkSyncDSiVolume_clicked(dsiSync);
ui->chkSyncDSiVolume->setEnabled(emuInstance->getNDS()->ConsoleType == 1); ui->chkSyncDSiVolume->setEnabled(emuInstance->getNDS()->ConsoleType == 1);
} }
void AudioSettingsDialog::on_AudioSettingsDialog_accepted() void AudioSettingsDialog::on_AudioSettingsDialog_accepted()
{ {
Config::MicDevice = ui->cbMic->currentText().toStdString(); auto& cfg = emuInstance->getGlobalConfig();
Config::MicInputType = grpMicMode->checkedId(); cfg.SetQString("Mic.Device", ui->cbMic->currentText());
Config::MicWavPath = ui->txtMicWavPath->text().toStdString(); cfg.SetInt("Mic.InputType", grpMicMode->checkedId());
cfg.SetQString("Mic.WavPath", ui->txtMicWavPath->text());
Config::Save(); Config::Save();
closeDlg(); closeDlg();
@ -157,10 +168,15 @@ void AudioSettingsDialog::on_AudioSettingsDialog_accepted()
void AudioSettingsDialog::on_AudioSettingsDialog_rejected() void AudioSettingsDialog::on_AudioSettingsDialog_rejected()
{ {
Config::AudioInterp = oldInterp; auto& cfg = emuInstance->getGlobalConfig();
Config::AudioBitDepth = oldBitDepth; auto& instcfg = emuInstance->getLocalConfig();
Config::AudioVolume = oldVolume; cfg.SetInt("Audio.Interpolation", oldInterp);
Config::DSiVolumeSync = oldDSiSync; cfg.SetInt("Audio.BitDepth", oldBitDepth);
instcfg.SetInt("Audio.Volume", oldVolume);
instcfg.SetBool("Audio.DSiVolumeSync", oldDSiSync);
emit updateAudioVolume(oldVolume, oldDSiSync);
emit updateAudioSettings();
closeDlg(); closeDlg();
} }
@ -170,7 +186,8 @@ void AudioSettingsDialog::on_cbBitDepth_currentIndexChanged(int idx)
// prevent a spurious change // prevent a spurious change
if (ui->cbBitDepth->count() < 3) return; if (ui->cbBitDepth->count() < 3) return;
Config::AudioBitDepth = ui->cbBitDepth->currentIndex(); auto& cfg = emuInstance->getGlobalConfig();
cfg.SetInt("Audio.BitDepth", ui->cbBitDepth->currentIndex());
emit updateAudioSettings(); emit updateAudioSettings();
} }
@ -180,29 +197,37 @@ void AudioSettingsDialog::on_cbInterpolation_currentIndexChanged(int idx)
// prevent a spurious change // prevent a spurious change
if (ui->cbInterpolation->count() < 5) return; if (ui->cbInterpolation->count() < 5) return;
Config::AudioInterp = ui->cbInterpolation->currentIndex(); auto& cfg = emuInstance->getGlobalConfig();
cfg.SetInt("Audio.Interpolation", ui->cbInterpolation->currentIndex());
emit updateAudioSettings(); emit updateAudioSettings();
} }
void AudioSettingsDialog::on_slVolume_valueChanged(int val) void AudioSettingsDialog::on_slVolume_valueChanged(int val)
{ {
if (Config::DSiVolumeSync && emuInstance->getNDS()->ConsoleType == 1) auto& cfg = emuInstance->getLocalConfig();
if (dsiSync && emuInstance->getNDS()->ConsoleType == 1)
{ {
auto dsi = static_cast<DSi*>(emuInstance->getNDS()); auto dsi = static_cast<DSi*>(emuInstance->getNDS());
dsi->I2C.GetBPTWL()->SetVolumeLevel(val); dsi->I2C.GetBPTWL()->SetVolumeLevel(val);
return; return;
} }
Config::AudioVolume = val; volume = val;
cfg.SetInt("Audio.Volume", val);
emit updateAudioVolume(val, dsiSync);
} }
void AudioSettingsDialog::on_chkSyncDSiVolume_clicked(bool checked) void AudioSettingsDialog::on_chkSyncDSiVolume_clicked(bool checked)
{ {
Config::DSiVolumeSync = checked; dsiSync = checked;
auto& cfg = emuInstance->getLocalConfig();
cfg.SetBool("Audio.DSiVolumeSync", dsiSync);
bool state = ui->slVolume->blockSignals(true); bool state = ui->slVolume->blockSignals(true);
if (Config::DSiVolumeSync && emuInstance->getNDS()->ConsoleType == 1) if (dsiSync && emuInstance->getNDS()->ConsoleType == 1)
{ {
auto dsi = static_cast<DSi*>(emuInstance->getNDS()); auto dsi = static_cast<DSi*>(emuInstance->getNDS());
ui->slVolume->setMaximum(31); ui->slVolume->setMaximum(31);
@ -212,13 +237,16 @@ void AudioSettingsDialog::on_chkSyncDSiVolume_clicked(bool checked)
} }
else else
{ {
Config::AudioVolume = oldVolume; volume = oldVolume;
cfg.SetInt("Audio.Volume", oldVolume);
ui->slVolume->setMaximum(256); ui->slVolume->setMaximum(256);
ui->slVolume->setValue(Config::AudioVolume); ui->slVolume->setValue(oldVolume);
ui->slVolume->setPageStep(16); ui->slVolume->setPageStep(16);
ui->slVolume->setTickPosition(QSlider::NoTicks); ui->slVolume->setTickPosition(QSlider::NoTicks);
} }
ui->slVolume->blockSignals(state); ui->slVolume->blockSignals(state);
emit updateAudioVolume(volume, dsiSync);
} }
void AudioSettingsDialog::onChangeMicMode(int mode) void AudioSettingsDialog::onChangeMicMode(int mode)

View File

@ -57,6 +57,7 @@ public:
void onConsoleReset(); void onConsoleReset();
signals: signals:
void updateAudioVolume(int vol, bool dsisync);
void updateAudioSettings(); void updateAudioSettings();
private slots: private slots:
@ -80,6 +81,9 @@ private:
int oldVolume; int oldVolume;
bool oldDSiSync; bool oldDSiSync;
QButtonGroup* grpMicMode; QButtonGroup* grpMicMode;
int volume;
bool dsiSync;
}; };
#endif // AUDIOSETTINGSDIALOG_H #endif // AUDIOSETTINGSDIALOG_H

View File

@ -244,14 +244,6 @@ extern bool DirectLAN;
extern bool SavestateRelocSRAM; extern bool SavestateRelocSRAM;
extern int AudioInterp;
extern int AudioBitDepth;
extern int AudioVolume;
extern bool DSiVolumeSync;
extern int MicInputType;
extern std::string MicDevice;
extern std::string MicWavPath;
extern std::string LastROMFolder; extern std::string LastROMFolder;
extern std::string RecentROMList[10]; extern std::string RecentROMList[10];

View File

@ -987,8 +987,8 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB
std::move(arm7bios), std::move(arm7bios),
std::move(*firmware), std::move(*firmware),
jitargs, jitargs,
static_cast<AudioBitDepth>(Config::AudioBitDepth), static_cast<AudioBitDepth>(globalCfg.GetInt("Audio.BitDepth")),
static_cast<AudioInterpolation>(Config::AudioInterp), static_cast<AudioInterpolation>(globalCfg.GetInt("Audio.Interpolation")),
gdbargs, gdbargs,
}; };

View File

@ -39,6 +39,9 @@ public:
EmuThread* getEmuThread() { return emuThread; } EmuThread* getEmuThread() { return emuThread; }
melonDS::NDS* getNDS() { return nds; } melonDS::NDS* getNDS() { return nds; }
Config::Table& getGlobalConfig() { return globalCfg; }
Config::Table& getLocalConfig() { return localCfg; }
void createWindow(); void createWindow();
// return: empty string = setup OK, non-empty = error message // return: empty string = setup OK, non-empty = error message
@ -182,6 +185,13 @@ private:
melonDS::u32 micBufferLength; melonDS::u32 micBufferLength;
melonDS::u32 micBufferReadPos; melonDS::u32 micBufferReadPos;
//int audioInterp;
int audioVolume;
bool audioDSiVolumeSync;
int micInputType;
std::string micDeviceName;
std::string micWavPath;
friend class EmuThread; friend class EmuThread;
friend class MainWindow; friend class MainWindow;
}; };

View File

@ -91,7 +91,7 @@ void EmuInstance::audioCallback(void* data, Uint8* stream, int len)
num_in = len_in-margin; num_in = len_in-margin;
} }
inst->audioResample(buf_in, num_in, (s16*)stream, len, Config::AudioVolume); inst->audioResample(buf_in, num_in, (s16*)stream, len, inst->audioVolume);
} }
void EmuInstance::micCallback(void* data, Uint8* stream, int len) void EmuInstance::micCallback(void* data, Uint8* stream, int len)
@ -139,7 +139,7 @@ void EmuInstance::audioMute()
void EmuInstance::micOpen() void EmuInstance::micOpen()
{ {
if (Config::MicInputType != micInputType_External) if (micInputType != micInputType_External)
{ {
micDevice = 0; micDevice = 0;
return; return;
@ -158,9 +158,9 @@ void EmuInstance::micOpen()
whatIwant.callback = micCallback; whatIwant.callback = micCallback;
whatIwant.userdata = this; whatIwant.userdata = this;
const char* mic = NULL; const char* mic = NULL;
if (Config::MicDevice != "") if (micDeviceName != "")
{ {
mic = Config::MicDevice.c_str(); mic = micDeviceName.c_str();
} }
micDevice = SDL_OpenAudioDevice(mic, 1, &whatIwant, &whatIget, 0); micDevice = SDL_OpenAudioDevice(mic, 1, &whatIwant, &whatIget, 0);
if (!micDevice) if (!micDevice)
@ -264,7 +264,7 @@ void EmuInstance::micLoadWav(const std::string& name)
void EmuInstance::micProcess() void EmuInstance::micProcess()
{ {
int type = Config::MicInputType; int type = micInputType;
bool cmd = Input::HotkeyDown(HK_Mic); bool cmd = Input::HotkeyDown(HK_Mic);
if (type != micInputType_External && !cmd) if (type != micInputType_External && !cmd)
@ -335,7 +335,11 @@ void EmuInstance::setupMicInputData()
micWavLength = 0; micWavLength = 0;
} }
switch (Config::MicInputType) micInputType = globalCfg.GetInt("Mic.InputType");
micDeviceName = globalCfg.GetString("Mic.Device");
micWavPath = globalCfg.GetString("Mic.WavPath");
switch (micInputType)
{ {
case micInputType_Silence: case micInputType_Silence:
case micInputType_Noise: case micInputType_Noise:
@ -347,7 +351,7 @@ void EmuInstance::setupMicInputData()
micBufferLength = sizeof(micExtBuffer)/sizeof(s16); micBufferLength = sizeof(micExtBuffer)/sizeof(s16);
break; break;
case micInputType_Wav: case micInputType_Wav:
micLoadWav(Config::MicWavPath); micLoadWav(micWavPath);
micBuffer = micWavBuffer; micBuffer = micWavBuffer;
micBufferLength = micWavLength; micBufferLength = micWavLength;
break; break;
@ -358,6 +362,9 @@ void EmuInstance::setupMicInputData()
void EmuInstance::audioInit() void EmuInstance::audioInit()
{ {
audioVolume = localCfg.GetInt("Audio.Volume");
audioDSiVolumeSync = localCfg.GetBool("Audio.DSiVolumeSync");
audioMuted = false; audioMuted = false;
audioSyncCond = SDL_CreateCond(); audioSyncCond = SDL_CreateCond();
audioSyncLock = SDL_CreateMutex(); audioSyncLock = SDL_CreateMutex();
@ -432,7 +439,8 @@ void EmuInstance::audioUpdateSettings()
{ {
micClose(); micClose();
nds->SPU.SetInterpolation(static_cast<AudioInterpolation>(Config::AudioInterp)); int audiointerp = globalCfg.GetInt("Audio.Interpolation");
nds->SPU.SetInterpolation(static_cast<AudioInterpolation>(audiointerp));
setupMicInputData(); setupMicInputData();
micOpen(); micOpen();

View File

@ -16,11 +16,8 @@
with melonDS. If not, see http://www.gnu.org/licenses/. with melonDS. If not, see http://www.gnu.org/licenses/.
*/ */
#include <stdio.h>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QList>
#include <QDateEdit>
#include "types.h" #include "types.h"
#include "Platform.h" #include "Platform.h"
@ -28,6 +25,7 @@
#include "EmuSettingsDialog.h" #include "EmuSettingsDialog.h"
#include "ui_EmuSettingsDialog.h" #include "ui_EmuSettingsDialog.h"
#include "main.h"
using namespace melonDS::Platform; using namespace melonDS::Platform;
using namespace melonDS; using namespace melonDS;
@ -59,8 +57,9 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new
ui->setupUi(this); ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
Config::Table cfg = Config::GetGlobalTable(); emuInstance = ((MainWindow*)parent)->getEmuInstance();
Config::Table instcfg = Config::GetLocalTable(Platform::InstanceID()); auto& cfg = emuInstance->getGlobalConfig();
auto& instcfg = emuInstance->getLocalConfig();
lastBIOSFolder = cfg.GetQString("LastBIOSFolder"); lastBIOSFolder = cfg.GetQString("LastBIOSFolder");
@ -253,8 +252,8 @@ void EmuSettingsDialog::done(int r)
QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok) QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok)
return; return;
Config::Table cfg = Config::GetGlobalTable(); auto& cfg = emuInstance->getGlobalConfig();
Config::Table instcfg = Config::GetLocalTable(Platform::InstanceID()); auto& instcfg = emuInstance->getLocalConfig();
cfg.SetBool("Emu.ExternalBIOSEnable", ui->chkExternalBIOS->isChecked()); cfg.SetBool("Emu.ExternalBIOSEnable", ui->chkExternalBIOS->isChecked());
cfg.SetQString("DS.BIOS9Path", ui->txtBIOS9Path->text()); cfg.SetQString("DS.BIOS9Path", ui->txtBIOS9Path->text());

View File

@ -24,6 +24,8 @@
namespace Ui { class EmuSettingsDialog; } namespace Ui { class EmuSettingsDialog; }
class EmuSettingsDialog; class EmuSettingsDialog;
class EmuInstance;
class EmuSettingsDialog : public QDialog class EmuSettingsDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -84,6 +86,7 @@ private:
void updateLastBIOSFolder(QString& filename); void updateLastBIOSFolder(QString& filename);
Ui::EmuSettingsDialog* ui; Ui::EmuSettingsDialog* ui;
EmuInstance* emuInstance;
QString lastBIOSFolder; QString lastBIOSFolder;
}; };

View File

@ -397,7 +397,7 @@ void EmuThread::run()
window->setGLSwapInterval(0); window->setGLSwapInterval(0);
} }
if (Config::DSiVolumeSync && emuInstance->nds->ConsoleType == 1) if (emuInstance->audioDSiVolumeSync && emuInstance->nds->ConsoleType == 1)
{ {
DSi* dsi = static_cast<DSi*>(emuInstance->nds); DSi* dsi = static_cast<DSi*>(emuInstance->nds);
u8 volumeLevel = dsi->I2C.GetBPTWL()->GetVolumeLevel(); u8 volumeLevel = dsi->I2C.GetBPTWL()->GetVolumeLevel();
@ -407,7 +407,7 @@ void EmuThread::run()
emit syncVolumeLevel(); emit syncVolumeLevel();
} }
Config::AudioVolume = volumeLevel * (256.0 / 31.0); emuInstance->audioVolume = volumeLevel * (256.0 / 31.0);
} }
if (Config::AudioSync && !fastforward) if (Config::AudioSync && !fastforward)

View File

@ -198,10 +198,12 @@ static void signalHandler(int)
int test = 0; int test = 0;
MainWindow::MainWindow(EmuInstance* inst, QWidget* parent) : QMainWindow(parent) MainWindow::MainWindow(EmuInstance* inst, QWidget* parent) :
QMainWindow(parent),
emuInstance(inst),
globalCfg(inst->globalCfg),
localCfg(inst->localCfg)
{ {
emuInstance = inst;
test_num = test++; test_num = test++;
#ifndef _WIN32 #ifndef _WIN32
if (!parent) if (!parent)
@ -1767,6 +1769,7 @@ void MainWindow::onOpenAudioSettings()
AudioSettingsDialog* dlg = AudioSettingsDialog::openDlg(this); AudioSettingsDialog* dlg = AudioSettingsDialog::openDlg(this);
connect(emuThread, &EmuThread::syncVolumeLevel, dlg, &AudioSettingsDialog::onSyncVolumeLevel); connect(emuThread, &EmuThread::syncVolumeLevel, dlg, &AudioSettingsDialog::onSyncVolumeLevel);
connect(emuThread, &EmuThread::windowEmuStart, dlg, &AudioSettingsDialog::onConsoleReset); connect(emuThread, &EmuThread::windowEmuStart, dlg, &AudioSettingsDialog::onConsoleReset);
connect(dlg, &AudioSettingsDialog::updateAudioVolume, this, &MainWindow::onUpdateAudioVolume);
connect(dlg, &AudioSettingsDialog::updateAudioSettings, this, &MainWindow::onUpdateAudioSettings); connect(dlg, &AudioSettingsDialog::updateAudioSettings, this, &MainWindow::onUpdateAudioSettings);
connect(dlg, &AudioSettingsDialog::finished, this, &MainWindow::onAudioSettingsFinished); connect(dlg, &AudioSettingsDialog::finished, this, &MainWindow::onAudioSettingsFinished);
} }
@ -1803,15 +1806,24 @@ void MainWindow::onPathSettingsFinished(int res)
emuThread->emuUnpause(); emuThread->emuUnpause();
} }
void MainWindow::onUpdateAudioVolume(int vol, int dsisync)
{
emuInstance->audioVolume = vol;
emuInstance->audioDSiVolumeSync = dsisync;
}
void MainWindow::onUpdateAudioSettings() void MainWindow::onUpdateAudioSettings()
{ {
assert(emuInstance->nds != nullptr); assert(emuInstance->nds != nullptr);
emuInstance->nds->SPU.SetInterpolation(static_cast<AudioInterpolation>(Config::AudioInterp));
if (Config::AudioBitDepth == 0) int interp = globalCfg.GetInt("Audio.Interpolation");
emuInstance->nds->SPU.SetInterpolation(static_cast<AudioInterpolation>(interp));
int bitdepth = globalCfg.GetInt("Audio.BitDepth");
if (bitdepth == 0)
emuInstance->nds->SPU.SetDegrade10Bit(emuInstance->nds->ConsoleType == 0); emuInstance->nds->SPU.SetDegrade10Bit(emuInstance->nds->ConsoleType == 0);
else else
emuInstance->nds->SPU.SetDegrade10Bit(Config::AudioBitDepth == 1); emuInstance->nds->SPU.SetDegrade10Bit(bitdepth == 1);
} }
void MainWindow::onAudioSettingsFinished(int res) void MainWindow::onAudioSettingsFinished(int res)

View File

@ -34,6 +34,7 @@
#include <QCloseEvent> #include <QCloseEvent>
#include "Screen.h" #include "Screen.h"
#include "Config.h"
class EmuInstance; class EmuInstance;
@ -177,6 +178,7 @@ private slots:
void onOpenCameraSettings(); void onOpenCameraSettings();
void onCameraSettingsFinished(int res); void onCameraSettingsFinished(int res);
void onOpenAudioSettings(); void onOpenAudioSettings();
void onUpdateAudioVolume(int vol, int dsisync);
void onUpdateAudioSettings(); void onUpdateAudioSettings();
void onAudioSettingsFinished(int res); void onAudioSettingsFinished(int res);
void onOpenMPSettings(); void onOpenMPSettings();
@ -240,9 +242,11 @@ private:
int test_num; int test_num;
EmuInstance* emuInstance; EmuInstance* emuInstance;
EmuThread* emuThread; EmuThread* emuThread;
Config::Table& globalCfg;
Config::Table& localCfg;
public: public:
ScreenPanel* panel; ScreenPanel* panel;

View File

@ -347,9 +347,6 @@ int main(int argc, char** argv)
#endif #endif
SANITIZE(Config::ScreenVSyncInterval, 1, 20); SANITIZE(Config::ScreenVSyncInterval, 1, 20);
SANITIZE(Config::GL_ScaleFactor, 1, 16); SANITIZE(Config::GL_ScaleFactor, 1, 16);
SANITIZE(Config::AudioInterp, 0, 4);
SANITIZE(Config::AudioVolume, 0, 256);
SANITIZE(Config::MicInputType, 0, (int)micInputType_MAX);
SANITIZE(Config::ScreenRotation, 0, (int)Frontend::screenRot_MAX); SANITIZE(Config::ScreenRotation, 0, (int)Frontend::screenRot_MAX);
SANITIZE(Config::ScreenGap, 0, 500); SANITIZE(Config::ScreenGap, 0, 500);
SANITIZE(Config::ScreenLayout, 0, (int)Frontend::screenLayout_MAX); SANITIZE(Config::ScreenLayout, 0, (int)Frontend::screenLayout_MAX);