audio: add Gain effect

This commit is contained in:
faiface 2017-07-13 00:29:53 +02:00
parent cce4cccd26
commit 63ababf515
1 changed files with 26 additions and 0 deletions

26
audio/effects.go Normal file
View File

@ -0,0 +1,26 @@
package audio
// Gain amplifies the wrapped Streamer. The output of the wrapped Streamer gets multiplied by
// 1+Gain.
//
// Note that gain is not equivalent to the human perception of volume. Human perception of volume is
// roughly exponential, while gain only amplifies linearly.
type Gain struct {
Streamer Streamer
Gain float64
}
// Stream streams the wrapped Streamer amplified by Gain.
func (g *Gain) Stream(samples [][2]float64) (n int, ok bool) {
n, ok = g.Streamer.Stream(samples)
for i := range samples[:n] {
samples[i][0] *= 1 + g.Gain
samples[i][1] *= 1 + g.Gain
}
return n, ok
}
// Err propagates the wrapped Streamer's errors.
func (g *Gain) Err() error {
return g.Streamer.Err()
}