Sub LevelToDecibel(volume As Float) As Float
' purpose: returns dBA equivalent for given normalized volume
' input: normalized volume between 0(=silent) and 1(=max volume)
' ( inputs >1 will result in positive dBA values )
' output: -99dBA to 0dbA
Dim Decibel As Float=Logarithm(volume*volume,10)*10
Return Decibel
End Sub
Sub SampleValueToDecibel(Value As Int, BitDepth As Int) As Float
' purpose: returns dBA equuivalant for given SampleValue based volume
' input: Value between 0=silent and BitDepth/2
' output: -99dBA to 0dbA
Dim SamplingRate As Int=Power(2,BitDepth-1)
Dim Level As Float=Value/SamplingRate
Return LevelToDecibel(Level)
End Sub
Sub DecibelToLevel(Decibel As Float) As Float
' purpose: returns a normalized volume for given dBA value
' input: -99dBA to 0dbA
' (input>0 will result in volume>1)
' output: normalized volume between 0(=silent) and 1(=max volume)
Dim level As Double=Power(10,(Decibel/10))
Return Sqrt(level)
End Sub
Sub DecibelToSampleValue(Decibel As Float, BitDepth As Int) As Float
' purpose: returns a SampleValue based volume for given dBA value
' input: -99dBA to 0dbA
' output: SampleValue based volume between between 0=silent and BitDepth/2
Dim level As Double=Power(10,(Decibel/10))
level=Sqrt(level)
Dim Value As Float=level*Power(2,BitDepth-1)
Return Value
End Sub