fixes for volume adjustment on raspi

This commit is contained in:
Dorian Zedler 2021-04-09 12:53:13 +02:00
parent b801a72d29
commit 38199766ce
Signed by: dorian
GPG Key ID: 989DE36109AFA354
1 changed files with 17 additions and 4 deletions

View File

@ -48,11 +48,24 @@ ScStwSoundPlayer::PlayResult ScStwSoundPlayer::play(ScStwSoundPlayer::StartSound
// update currently playing action
this->currentlyPlayingSound = sound;
// update volume
#ifdef RASPI
// set volume on raspi using alsamixer
QProcess::execute("amixer -q -M sset PCM " + QString::number(volume * 100, 'f', 0) + "%");
// set volume on raspi using amixer
QProcess soundProcess;
// determine current audio output device
soundProcess.start("amixer", {"scontrols"});
soundProcess.waitForFinished();
QStringList outputDeviceNameList = QString(soundProcess.readAllStandardOutput()).split("'");
if(outputDeviceNameList.length() == 3) {
QString outputDeviceName = outputDeviceNameList[1];
soundProcess.execute("amixer", {"sset", outputDeviceName, QString::number(volume * 100, 'f', 0) + "%"});
}
else {
qDebug() << "[WARNING][SoundPlayer] Could not determine output device to set volume";
}
this->soundEffect->setVolume(1);
#else
this->soundEffect->setVolume(volume);
#endif