Change volume dynamic range from 60dB to 40dB

also makes it easily configurable in future if needed
changes volume calculation algo to more precise and easy to understand (dB definition)
This commit is contained in:
JuniorJPDJ 2021-06-24 05:21:42 +02:00 committed by Georg Krause
parent f1f6a77d14
commit ffc9109a45
3 changed files with 13 additions and 27 deletions

View File

@ -0,0 +1 @@
Changed volume dynamic range from 60dB to 40dB (fixes #1544)

View File

@ -1,31 +1,25 @@
// Provides functions to convert between linear and logarithmic volume scales.
// The logarithmic volume from the UI is converted to a linear volume with a
// logarithmic function like exp(b*x)/a.
// Compare https://www.dr-lex.be/info-stuff/volumecontrols.html for how the
// values for a and b got derived.
const PARAM_A = 1000
const PARAM_B = Math.log(1000) // ~ 6.908
const DYNAMIC_RANGE = 40 // dB
function toLinearVolumeScale(v) {
// Or as approximation:
// return Math.pow(v, 4)
if (v == 0.0) {
if (v <= 0.0) {
return 0.0
}
return Math.min(Math.exp(PARAM_B * v) / PARAM_A, 1.0)
// (1.0; 0.0) -> (0; -DYNAMIC_RANGE) dB
let dB = (v-1)*DYNAMIC_RANGE
return Math.pow(10, dB / 20)
}
function toLogarithmicVolumeScale(v) {
// Or as approximation:
// return Math.exp(Math.log(v) / 4)
if (v == 0.0) {
if (v <= 0.0) {
return 0.0
}
return Math.log(v * PARAM_A) / PARAM_B
let dB = 20 * Math.log10(v)
// (0; -DYNAMIC_RANGE) [dB] -> (1.0; 0.0)
return 1 - (dB / -DYNAMIC_RANGE)
}
exports.toLinearVolumeScale = toLinearVolumeScale

View File

@ -8,10 +8,6 @@ describe('store/auth', () => {
expect(toLinearVolumeScale(0.0)).to.equal(0.0)
})
describe('it should have logarithmic scale', () => {
expect(2 * toLinearVolumeScale(0.5)).to.be.closeTo(toLinearVolumeScale(0.6), 0.001)
})
describe('it should return full volume', () => {
expect(toLogarithmicVolumeScale(1.0)).to.be.closeTo(1.0, 0.001)
})
@ -22,13 +18,8 @@ describe('store/auth', () => {
expect(toLogarithmicVolumeScale(0.0)).to.equal(0.0)
})
describe('it should have logarithmic scale', () => {
expect(toLogarithmicVolumeScale(0.6)).to.be.closeTo(0.9261, 0.001)
expect(toLogarithmicVolumeScale(0.7)).to.be.closeTo(0.9483, 0.001)
})
describe('it should return full volume', () => {
expect(toLogarithmicVolumeScale(1.0)).to.be.closeTo(1.0, 0.001)
})
})
})
})