diff --git a/client/player/alsaPlayer.cpp b/client/player/alsaPlayer.cpp index 40754572..a7f67a9e 100644 --- a/client/player/alsaPlayer.cpp +++ b/client/player/alsaPlayer.cpp @@ -177,22 +177,10 @@ void AlsaPlayer::worker() snd_pcm_delay(handle_, &framesDelay); chronos::usec delay((chronos::usec::rep) (1000 * (double) framesDelay / stream_->getFormat().msRate())); // logO << "delay: " << framesDelay << ", delay[ms]: " << delay.count() / 1000 << "\n"; - double volume = volume_; - if (muted_) - volume = 0.; - const msg::SampleFormat& sampleFormat = stream_->getFormat(); if (stream_->getPlayerChunk(buff_, delay, frames_)) { - if (volume < 1.0) - { - if (sampleFormat.bits == 8) - adjustVolume(buff_, frames_*sampleFormat.channels, volume); - else if (sampleFormat.bits == 16) - adjustVolume(buff_, frames_*sampleFormat.channels, volume); - else if (sampleFormat.bits == 32) - adjustVolume(buff_, frames_*sampleFormat.channels, volume); - } + adjustVolume(buff_, frames_); if ((pcm = snd_pcm_writei(handle_, buff_, frames_)) == -EPIPE) { logE << "XRUN\n"; diff --git a/client/player/alsaPlayer.h b/client/player/alsaPlayer.h index 45e35e2f..bb8fa981 100644 --- a/client/player/alsaPlayer.h +++ b/client/player/alsaPlayer.h @@ -47,17 +47,8 @@ private: void initAlsa(); void uninitAlsa(); - template - void adjustVolume(char *buffer, size_t count, double volume) - { - T* bufferT = (T*)buffer; - for (size_t n=0; nEnqueue(bq, buffer[curBuffer], buff_size); diff --git a/client/player/player.cpp b/client/player/player.cpp index a67ca7ff..0973e34b 100644 --- a/client/player/player.cpp +++ b/client/player/player.cpp @@ -61,6 +61,25 @@ void Player::stop() } +void Player::adjustVolume(char* buffer, size_t frames) +{ + double volume = volume_; + if (muted_) + volume = 0.; + + const msg::SampleFormat& sampleFormat = stream_->getFormat(); + + if (volume < 1.0) + { + if (sampleFormat.bits == 8) + adjustVolume(buffer, frames*sampleFormat.channels, volume); + else if (sampleFormat.bits == 16) + adjustVolume(buffer, frames*sampleFormat.channels, volume); + else if (sampleFormat.bits == 32) + adjustVolume(buffer, frames*sampleFormat.channels, volume); + } +} + void Player::setVolume(double volume) { diff --git a/client/player/player.h b/client/player/player.h index fa1dae79..2f1488a5 100644 --- a/client/player/player.h +++ b/client/player/player.h @@ -46,6 +46,16 @@ public: protected: virtual void worker() = 0; + template + void adjustVolume(char *buffer, size_t count, double volume) + { + T* bufferT = (T*)buffer; + for (size_t n=0; n active_; Stream* stream_; std::thread playerThread_;