mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-21 03:41:10 +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->audioConnection = nullptr;
|
||||||
this->state = StateStopped;
|
this->state = StateStopped;
|
||||||
this->volume = 1.0f;
|
this->volume = 1.0f;
|
||||||
|
this->volumeUpdated = false;
|
||||||
this->channels = 0;
|
this->channels = 0;
|
||||||
this->rate = 0;
|
this->rate = 0;
|
||||||
}
|
}
|
||||||
@ -142,10 +143,14 @@ void PulseOut::Resume() {
|
|||||||
|
|
||||||
void PulseOut::SetVolume(double volume) {
|
void PulseOut::SetVolume(double volume) {
|
||||||
Lock lock(this->stateMutex);
|
Lock lock(this->stateMutex);
|
||||||
|
if (volume > 1.0) { volume = 1.0; }
|
||||||
|
if (volume < 0) { volume = 0; }
|
||||||
this->volume = volume;
|
this->volume = volume;
|
||||||
|
this->volumeUpdated = false;
|
||||||
if (this->audioConnection) {
|
if (this->audioConnection) {
|
||||||
int normalized = (int) round((double) PA_VOLUME_NORM * volume);
|
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;
|
return OutputInvalidState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this->volumeUpdated) {
|
||||||
|
this->SetVolume(this->volume);
|
||||||
|
}
|
||||||
|
|
||||||
pa_blocking_write(
|
pa_blocking_write(
|
||||||
this->audioConnection,
|
this->audioConnection,
|
||||||
buffer->BufferPointer(),
|
buffer->BufferPointer(),
|
||||||
|
@ -76,4 +76,5 @@ class PulseOut : public musik::core::sdk::IOutput {
|
|||||||
State state;
|
State state;
|
||||||
int channels, rate;
|
int channels, rate;
|
||||||
double volume;
|
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, 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 >= 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);
|
pa_threaded_mainloop_lock(p->mainloop);
|
||||||
CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
|
CHECK_DEAD_GOTO(p, rerror, unlock_and_fail);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user