aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfalsidge <falsidge@users.noreply.github.com>2023-06-27 12:31:41 -0700
committerGitHub <noreply@github.com>2023-06-27 21:31:41 +0200
commit52d6265b5840b0d36e65040ac33b1d6476b4b8b9 (patch)
tree6b2feba806ace0bb47486dc8effc84dd3458aa19
parent4b32fb802c1e3e30bbdc1825828611d5a166b57f (diff)
Add microphone combobox using SDL (#1709)
-rw-r--r--src/frontend/qt_sdl/AudioInOut.cpp7
-rw-r--r--src/frontend/qt_sdl/AudioSettingsDialog.cpp19
-rw-r--r--src/frontend/qt_sdl/AudioSettingsDialog.ui9
-rw-r--r--src/frontend/qt_sdl/Config.cpp2
-rw-r--r--src/frontend/qt_sdl/Config.h1
5 files changed, 36 insertions, 2 deletions
diff --git a/src/frontend/qt_sdl/AudioInOut.cpp b/src/frontend/qt_sdl/AudioInOut.cpp
index e63db1a..395dcf8 100644
--- a/src/frontend/qt_sdl/AudioInOut.cpp
+++ b/src/frontend/qt_sdl/AudioInOut.cpp
@@ -133,7 +133,12 @@ void MicOpen()
whatIwant.channels = 1;
whatIwant.samples = 1024;
whatIwant.callback = MicCallback;
- micDevice = SDL_OpenAudioDevice(NULL, 1, &whatIwant, &whatIget, 0);
+ const char* mic = NULL;
+ if (Config::MicDevice != "")
+ {
+ mic = Config::MicDevice.c_str();
+ }
+ micDevice = SDL_OpenAudioDevice(mic, 1, &whatIwant, &whatIget, 0);
if (!micDevice)
{
Platform::Log(Platform::LogLevel::Error, "Mic init failed: %s\n", SDL_GetError());
diff --git a/src/frontend/qt_sdl/AudioSettingsDialog.cpp b/src/frontend/qt_sdl/AudioSettingsDialog.cpp
index 0a6002c..ef1f571 100644
--- a/src/frontend/qt_sdl/AudioSettingsDialog.cpp
+++ b/src/frontend/qt_sdl/AudioSettingsDialog.cpp
@@ -17,6 +17,7 @@
*/
#include <stdio.h>
+#include <SDL2/SDL.h>
#include <QFileDialog>
#include "types.h"
@@ -70,7 +71,21 @@ AudioSettingsDialog::AudioSettingsDialog(QWidget* parent, bool emuActive) : QDia
{
ui->chkSyncDSiVolume->setEnabled(false);
}
+ bool isext = (Config::MicInputType == 1);
+ ui->cbMic->setEnabled(isext);
+ const int count = SDL_GetNumAudioDevices(true);
+ for (int i = 0; i < count; i++)
+ {
+ ui->cbMic->addItem(SDL_GetAudioDeviceName(i, true));
+ }
+ if (Config::MicDevice == "" && count > 0)
+ {
+ Config::MicDevice = SDL_GetAudioDeviceName(0, true);
+ }
+
+ ui->cbMic->setCurrentText(QString::fromStdString(Config::MicDevice));
+
grpMicMode = new QButtonGroup(this);
grpMicMode->addButton(ui->rbMicNone, micInputType_Silence);
grpMicMode->addButton(ui->rbMicExternal, micInputType_External);
@@ -95,6 +110,7 @@ AudioSettingsDialog::AudioSettingsDialog(QWidget* parent, bool emuActive) : QDia
btn->setEnabled(false);
ui->txtMicWavPath->setEnabled(false);
ui->btnMicWavBrowse->setEnabled(false);
+ ui->cbMic->setEnabled(false);
}
else
ui->lblInstanceNum->hide();
@@ -123,6 +139,7 @@ void AudioSettingsDialog::onConsoleReset()
void AudioSettingsDialog::on_AudioSettingsDialog_accepted()
{
+ Config::MicDevice = ui->cbMic->currentText().toStdString();
Config::MicInputType = grpMicMode->checkedId();
Config::MicWavPath = ui->txtMicWavPath->text().toStdString();
Config::Save();
@@ -197,8 +214,10 @@ void AudioSettingsDialog::on_chkSyncDSiVolume_clicked(bool checked)
void AudioSettingsDialog::onChangeMicMode(int mode)
{
bool iswav = (mode == 3);
+ bool isext = (mode == 1);
ui->txtMicWavPath->setEnabled(iswav);
ui->btnMicWavBrowse->setEnabled(iswav);
+ ui->cbMic->setEnabled(isext);
}
void AudioSettingsDialog::on_btnMicWavBrowse_clicked()
diff --git a/src/frontend/qt_sdl/AudioSettingsDialog.ui b/src/frontend/qt_sdl/AudioSettingsDialog.ui
index e57ce8c..380197e 100644
--- a/src/frontend/qt_sdl/AudioSettingsDialog.ui
+++ b/src/frontend/qt_sdl/AudioSettingsDialog.ui
@@ -136,7 +136,7 @@
</property>
</widget>
</item>
- <item row="1" column="0" colspan="3">
+ <item row="1" column="0">
<widget class="QRadioButton" name="rbMicExternal">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Input from an external microphone, if available, will be forwarded to the emulated microphone.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -146,6 +146,13 @@
</property>
</widget>
</item>
+ <item row="1" column="1" colspan="2">
+ <widget class="QComboBox" name="cbMic">
+ <property name="whatsThis">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The selected microphone to be used.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ </widget>
+ </item>
<item row="2" column="0" colspan="3">
<widget class="QRadioButton" name="rbMicNoise">
<property name="whatsThis">
diff --git a/src/frontend/qt_sdl/Config.cpp b/src/frontend/qt_sdl/Config.cpp
index 217d0d7..a32e172 100644
--- a/src/frontend/qt_sdl/Config.cpp
+++ b/src/frontend/qt_sdl/Config.cpp
@@ -120,6 +120,7 @@ int AudioBitDepth;
int AudioVolume;
bool DSiVolumeSync;
int MicInputType;
+std::string MicDevice;
std::string MicWavPath;
std::string LastROMFolder;
@@ -300,6 +301,7 @@ ConfigEntry ConfigFile[] =
{"AudioVolume", 0, &AudioVolume, 256, true},
{"DSiVolumeSync", 0, &DSiVolumeSync, 0, true},
{"MicInputType", 0, &MicInputType, 1, false},
+ {"MicDevice", 2, &MicDevice, (std::string)"", false},
{"MicWavPath", 2, &MicWavPath, (std::string)"", false},
{"LastROMFolder", 2, &LastROMFolder, (std::string)"", true},
diff --git a/src/frontend/qt_sdl/Config.h b/src/frontend/qt_sdl/Config.h
index ba8d345..c6fd297 100644
--- a/src/frontend/qt_sdl/Config.h
+++ b/src/frontend/qt_sdl/Config.h
@@ -177,6 +177,7 @@ extern int AudioBitDepth;
extern int AudioVolume;
extern bool DSiVolumeSync;
extern int MicInputType;
+extern std::string MicDevice;
extern std::string MicWavPath;
extern std::string LastROMFolder;