diff --git a/src/contrib/pulseout/PulseOut.cpp b/src/contrib/pulseout/PulseOut.cpp index 6c73e5062..8596e2504 100755 --- a/src/contrib/pulseout/PulseOut.cpp +++ b/src/contrib/pulseout/PulseOut.cpp @@ -46,6 +46,7 @@ PulseOut::PulseOut() { this->audioConnection = nullptr; this->state = StateStopped; this->volume = 1.0f; + this->volumeUpdated = false; this->channels = 0; this->rate = 0; } @@ -142,10 +143,14 @@ void PulseOut::Resume() { void PulseOut::SetVolume(double volume) { Lock lock(this->stateMutex); + if (volume > 1.0) { volume = 1.0; } + if (volume < 0) { volume = 0; } this->volume = volume; + this->volumeUpdated = false; if (this->audioConnection) { int normalized = (int) round((double) PA_VOLUME_NORM * volume); - pa_blocking_set_volume(this->audioConnection, normalized, 0); + this->volumeUpdated = pa_blocking_set_volume(this->audioConnection, normalized, 0) == 0; + std::cerr << "PulseOut: volumeUpdated = " << this->volumeUpdated << "\n"; } } @@ -169,6 +174,10 @@ int PulseOut::Play(IBuffer *buffer, IBufferProvider* provider) { return OutputInvalidState; } + if (!this->volumeUpdated) { + this->SetVolume(this->volume); + } + pa_blocking_write( this->audioConnection, buffer->BufferPointer(), diff --git a/src/contrib/pulseout/PulseOut.h b/src/contrib/pulseout/PulseOut.h index 644a11993..03949b730 100755 --- a/src/contrib/pulseout/PulseOut.h +++ b/src/contrib/pulseout/PulseOut.h @@ -76,4 +76,5 @@ class PulseOut : public musik::core::sdk::IOutput { State state; int channels, rate; double volume; + bool volumeUpdated; }; diff --git a/src/contrib/pulseout/pulse_blocking_stream.c b/src/contrib/pulseout/pulse_blocking_stream.c index 151b2cc0a..91816d9dd 100644 --- a/src/contrib/pulseout/pulse_blocking_stream.c +++ b/src/contrib/pulseout/pulse_blocking_stream.c @@ -515,7 +515,7 @@ int pa_blocking_set_volume(pa_blocking *p, int volume, int *rerror) { CHECK_VALIDITY_RETURN_ANY(rerror, p->direction == PA_STREAM_PLAYBACK, PA_ERR_BADSTATE, -1); CHECK_VALIDITY_RETURN_ANY(rerror, volume >= 0, PA_ERR_INVALID, -1); - CHECK_VALIDITY_RETURN_ANY(rerror, volume <= 65535, PA_ERR_INVALID, -1); + CHECK_VALIDITY_RETURN_ANY(rerror, volume <= 65536, PA_ERR_INVALID, -1); pa_threaded_mainloop_lock(p->mainloop); CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);