Skip to content

Commit

Permalink
Shared initSoundDevices() function
Browse files Browse the repository at this point in the history
Used by initSelectedSoundDevices() and initDefaultSoundDevices().
  • Loading branch information
bear101 committed Mar 5, 2025
1 parent 6ca14d3 commit 4aa9e48
Showing 1 changed file with 22 additions and 45 deletions.
67 changes: 22 additions & 45 deletions Client/qtTeamTalk/utilsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ QAudioDevice getSelectedOutputAudioDevice()
}
#endif

QStringList initSelectedSoundDevices(SoundDevice& indev, SoundDevice& outdev)
QStringList initSoundDevices(const SoundDevice& indev, const SoundDevice& outdev)
{
QStringList result;

Expand All @@ -293,13 +293,6 @@ QStringList initSelectedSoundDevices(SoundDevice& indev, SoundDevice& outdev)
//Restart sound system so we have the latest sound devices
TT_RestartSoundSystem();

int inputid = getSelectedSndInputDevice();
int outputid = getSelectedSndOutputDevice();

QVector<SoundDevice> devs = getSoundDevices();
getSoundDevice(inputid, devs, indev);
getSoundDevice(outputid, devs, outdev);

SoundDeviceEffects effects = {};
bool echocancel = ttSettings->value(SETTINGS_SOUND_ECHOCANCEL, SETTINGS_SOUND_ECHOCANCEL_DEFAULT).toBool();

Expand All @@ -324,32 +317,42 @@ QStringList initSelectedSoundDevices(SoundDevice& indev, SoundDevice& outdev)
preprocess.webrtc.echocanceller.bEnable &= duplex;
}

TT_SetSoundInputPreprocessEx(ttInst, & preprocess);
TT_SetSoundInputPreprocessEx(ttInst, &preprocess);

if (duplex)
{
if (!TT_InitSoundDuplexDevices(ttInst, inputid, outputid))
if (!TT_InitSoundDuplexDevices(ttInst, indev.nDeviceID, outdev.nDeviceID))
{
result.append(QObject::tr("Failed to initialize sound duplex mode"));
indev = {}, outdev = {};
result.append(QObject::tr("Failed to initialize sound duplex mode: %1 - %2")
.arg(_Q(indev.szDeviceName), _Q(outdev.szDeviceName)));
}
}
else
{
if (!TT_InitSoundInputDevice(ttInst, inputid))
if (!TT_InitSoundInputDevice(ttInst, indev.nDeviceID))
{
result.append(QObject::tr("Failed to initialize sound input device"));
indev = {};
result.append(QObject::tr("Failed to initialize sound input device: %1").arg(_Q(indev.szDeviceName)));
}
if (!TT_InitSoundOutputDevice(ttInst, outputid))
if (!TT_InitSoundOutputDevice(ttInst, outdev.nDeviceID))
{
result.append(QObject::tr("Failed to initialize sound output device"));
outdev = {};
result.append(QObject::tr("Failed to initialize sound output device: %1").arg(_Q(outdev.szDeviceName)));
}
}
return result;
}

QStringList initSelectedSoundDevices(SoundDevice& indev, SoundDevice& outdev)
{
int inputid = getSelectedSndInputDevice();
int outputid = getSelectedSndOutputDevice();

QVector<SoundDevice> devs = getSoundDevices();
getSoundDevice(inputid, devs, indev);
getSoundDevice(outputid, devs, outdev);

return initSoundDevices(indev, outdev);
}

QStringList initDefaultSoundDevices(SoundDevice& indev, SoundDevice& outdev)
{
QStringList result;
Expand All @@ -374,33 +377,7 @@ QStringList initDefaultSoundDevices(SoundDevice& indev, SoundDevice& outdev)
getSoundDevice(inputid, devs, indev);
getSoundDevice(outputid, devs, outdev);

// reset sound device effects
SoundDeviceEffects effects = {};
TT_SetSoundDeviceEffects(ttInst, &effects);

bool duplex = getSoundDuplexSampleRate(indev, outdev) > 0;

if (duplex)
{
if (!TT_InitSoundDuplexDevices(ttInst, inputid, outputid))
{
result.append(QObject::tr("Failed to initialize sound duplex mode"));
indev = {}, outdev = {};
}
}
else
{
if (!TT_InitSoundInputDevice(ttInst, inputid))
{
result.append(QObject::tr("Failed to initialize default sound input device"));
indev = {};
}
if (!TT_InitSoundOutputDevice(ttInst, outputid))
{
result.append(QObject::tr("Failed to initialize default sound output device"));
outdev = {};
}
}
result += initSoundDevices(indev, outdev);
}
return result;
}
Expand Down

0 comments on commit 4aa9e48

Please sign in to comment.