From 38199766ce66ec542ad6060204e7a51bba3ab81e Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Fri, 9 Apr 2021 12:53:13 +0200 Subject: [PATCH] fixes for volume adjustment on raspi --- ScStwLibraries/sources/scstwsoundplayer.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ScStwLibraries/sources/scstwsoundplayer.cpp b/ScStwLibraries/sources/scstwsoundplayer.cpp index 1dc116a..4bde4e8 100644 --- a/ScStwLibraries/sources/scstwsoundplayer.cpp +++ b/ScStwLibraries/sources/scstwsoundplayer.cpp @@ -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