mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-19 06:40:34 +00:00
An attempt to work around an impossible-to-reproduce bug in PulseOut. It seems that sometimes setting the stream volume doesn't work immediately, maybe because the stream isn't ready. Or maybe due a floating point rounding error.
This commit is contained in:
parent
bf18797b26
commit
3c75ab2a3d
@ -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(),
|
||||
|
@ -76,4 +76,5 @@ class PulseOut : public musik::core::sdk::IOutput {
|
||||
State state;
|
||||
int channels, rate;
|
||||
double volume;
|
||||
bool volumeUpdated;
|
||||
};
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user