Added Split, ReplayGain filter
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2022-03-07 22:26:41 +01:00
parent 7aa672a616
commit 6729f7ef38
2 changed files with 39 additions and 0 deletions

View file

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

View file

@ -5,3 +5,27 @@ type Source struct {
Channels int
Blocks chan []float32
}
func (s Source) Split(n int) (sources []Source) {
sources = make([]Source, n)
for i := range sources {
sources[i] = s
sources[i].Blocks = make(chan []float32, cap(s.Blocks))
}
go func() {
defer func() {
for i := range sources {
close(sources[i].Blocks)
}
}()
for block := range s.Blocks {
for i := range sources {
sources[i].Blocks <- block
}
}
}()
return
}