diff --git a/client/player/alsa_player.cpp b/client/player/alsa_player.cpp index 9d2fe5b8..688a1c0e 100644 --- a/client/player/alsa_player.cpp +++ b/client/player/alsa_player.cpp @@ -41,10 +41,10 @@ AlsaPlayer::AlsaPlayer(boost::asio::io_context& io_context, const ClientSettings if (settings_.mixer.parameter.empty()) mixer_name_ = DEFAULT_MIXER; else - utils::string::split_left(settings_.mixer.parameter, ':', mixer_name_, tmp); + mixer_name_ = utils::string::split_left(settings_.mixer.parameter, ':', tmp); // default:CARD=ALSA => default - utils::string::split_left(settings_.pcm_device.name, ':', mixer_device_, tmp); + mixer_device_ = utils::string::split_left(settings_.pcm_device.name, ':', tmp); LOG(DEBUG, LOG_TAG) << "Mixer: " << mixer_name_ << ", device: " << mixer_device_ << "\n"; } } @@ -229,6 +229,7 @@ void AlsaPlayer::initMixer() void AlsaPlayer::initAlsa() { + std::lock_guard lock(mutex_); unsigned int tmp, rate; int err, channels; snd_pcm_hw_params_t* params; diff --git a/client/player/player.cpp b/client/player/player.cpp index 1bc22af6..bdba9855 100644 --- a/client/player/player.cpp +++ b/client/player/player.cpp @@ -24,6 +24,7 @@ #include "common/aixlog.hpp" #include "common/snap_exception.hpp" #include "common/str_compat.hpp" +#include "common/utils/string_utils.hpp" #include "player.hpp" @@ -51,7 +52,8 @@ void Player::start() playerThread_ = thread(&Player::worker, this); // If hardware mixer is used, send the initial volume to the server, because this is - // the volume that is configured by the user on his local device + // the volume that is configured by the user on his local device, so we shouldn't change it + // on client start up if (settings_.mixer.mode == ClientSettings::Mixer::Mode::hardware) { double volume; @@ -128,7 +130,7 @@ void Player::adjustVolume(char* buffer, size_t frames) void Player::setVolume_poly(double volume, double exp) { volume_ = std::pow(volume, exp); - LOG(DEBUG, LOG_TAG) << "setVolume poly: " << volume << " => " << volume_ << "\n"; + LOG(DEBUG, LOG_TAG) << "setVolume poly with exp " << exp << ": " << volume << " => " << volume_ << "\n"; } @@ -138,7 +140,7 @@ void Player::setVolume_exp(double volume, double base) // double base = M_E; // double base = 10.; volume_ = (pow(base, volume) - 1) / (base - 1); - LOG(DEBUG, LOG_TAG) << "setVolume exp: " << volume << " => " << volume_ << "\n"; + LOG(DEBUG, LOG_TAG) << "setVolume exp with base " << base << ": " << volume << " => " << volume_ << "\n"; } @@ -152,10 +154,22 @@ void Player::setVolume(double volume, bool mute) } else if (settings_.mixer.mode == ClientSettings::Mixer::Mode::software) { - if (settings_.mixer.parameter == "poly") - setVolume_poly(volume, 3.); + string param; + string mode = utils::string::split_left(settings_.mixer.parameter, ':', param); + double dparam; + try + { + if (!param.empty()) + dparam = cpt::stod(param); + } + catch(...) + { + throw SnapException("Invalid mixer param: " + param); + } + if (mode == "poly") + setVolume_poly(volume, param.empty() ? 3. : dparam); else - setVolume_exp(volume, 10.); + setVolume_exp(volume, param.empty() ? 10. : dparam); } else if (settings_.mixer.mode == ClientSettings::Mixer::Mode::script) { diff --git a/client/snapclient.cpp b/client/snapclient.cpp index b4a7824a..767ead87 100644 --- a/client/snapclient.cpp +++ b/client/snapclient.cpp @@ -310,8 +310,7 @@ int main(int argc, char** argv) settings.player.mixer.mode = ClientSettings::Mixer::Mode::software; if (mixer_mode->is_set()) { - string mode; - utils::string::split_left(mixer_mode->value(), ':', mode, settings.player.mixer.parameter); + string mode = utils::string::split_left(mixer_mode->value(), ':', settings.player.mixer.parameter); if (mode == "software") settings.player.mixer.mode = ClientSettings::Mixer::Mode::software; else if ((mode == "hardware") && hw_mixer_supported) diff --git a/common/utils/string_utils.hpp b/common/utils/string_utils.hpp index 03428702..d713acb6 100644 --- a/common/utils/string_utils.hpp +++ b/common/utils/string_utils.hpp @@ -114,6 +114,14 @@ static void split_left(const std::string& s, char delim, std::string& left, std: } +static std::string split_left(const std::string& s, char delim, std::string& right) +{ + std::string left; + split_left(s, delim, left, right); + return left; +} + + static std::vector& split(const std::string& s, char delim, std::vector& elems) {