mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
Improved DirectSound volume ramping algorithm.
This commit is contained in:
parent
126a9c2958
commit
493da2a7bd
@ -158,14 +158,21 @@ void DirectSoundOut::SetVolume(double volume) {
|
|||||||
|
|
||||||
if (this->state != StateStopped) {
|
if (this->state != StateStopped) {
|
||||||
if (this->secondaryBuffer) {
|
if (this->secondaryBuffer) {
|
||||||
double db = (volume < 0.0001f)
|
/* normalize between 1 and 10000 (DSBVOLUME_MIN) */
|
||||||
? DSBVOLUME_MIN
|
double scaled = fabs(volume * 10000);
|
||||||
: log10(this->volume) * 6000.f;
|
scaled = scaled < 0 ? 1 : scaled;
|
||||||
|
|
||||||
|
/* found on experts-exchange (20181717) */
|
||||||
|
double db = ((log10(scaled) / 4) * 10000) - 10000;
|
||||||
|
|
||||||
if (db > DSBVOLUME_MAX) {
|
if (db > DSBVOLUME_MAX) {
|
||||||
db = DSBVOLUME_MAX;
|
db = DSBVOLUME_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (db < DSBVOLUME_MIN) {
|
||||||
|
db = DSBVOLUME_MIN;
|
||||||
|
}
|
||||||
|
|
||||||
this->secondaryBuffer->SetVolume((LONG) db);
|
this->secondaryBuffer->SetVolume((LONG) db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user