Added Split, ReplayGain filter
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
7aa672a616
commit
6729f7ef38
15
audio/replaygain/filter.go
Normal file
15
audio/replaygain/filter.go
Normal 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))
|
||||||
|
}
|
|
@ -5,3 +5,27 @@ type Source struct {
|
||||||
Channels int
|
Channels int
|
||||||
Blocks chan []float32
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue