Add microphone combobox using SDL (#1709)

This commit is contained in:
falsidge 2023-06-27 12:31:41 -07:00 committed by GitHub
parent 4b32fb802c
commit 52d6265b58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 2 deletions

View File

@ -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());

View File

@ -17,6 +17,7 @@
*/
#include <stdio.h>
#include <SDL2/SDL.h>
#include <QFileDialog>
#include "types.h"
@ -70,6 +71,20 @@ 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);
@ -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()

View File

@ -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">

View File

@ -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},

View File

@ -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;