Kirika/audio/replaygain/filter.go

16 lines
435 B
Go
Raw Permalink Normal View History

2022-03-07 21:26:41 +00:00
package replaygain
import (
"git.gammaspectra.live/S.O.N.G/Kirika/audio/filter"
2022-03-07 21:26:41 +00:00
"math"
)
// NewReplayGainFilter Creates a VolumeFilter applying calculated ReplayGain values, pre amplifying by preAmp. Values are in dB
func NewReplayGainFilter(gain, peak, preAmp float64) filter.VolumeFilter {
2022-03-07 21:26:41 +00:00
volume := math.Pow(10, (gain+preAmp)/20)
//prevent clipping
volume = math.Min(volume, 1/peak)
return filter.NewVolumeFilter(volume)
2022-03-07 21:26:41 +00:00
}