From 63ababf5154aa6871b15b9337906fc8fd3bf2191 Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Thu, 13 Jul 2017 00:29:53 +0200
Subject: [PATCH] audio: add Gain effect

---
 audio/effects.go | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 audio/effects.go

diff --git a/audio/effects.go b/audio/effects.go
new file mode 100644
index 0000000..9a86478
--- /dev/null
+++ b/audio/effects.go
@@ -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()
+}
-- 
GitLab