From b30703eb00d6cc25e4a627b8a10d548c1c8d6df1 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 8 Jan 2018 22:18:19 +0900 Subject: [PATCH] examples/piano: Refactoring --- examples/piano/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/piano/main.go b/examples/piano/main.go index 2d0c64845..89791b388 100644 --- a/examples/piano/main.go +++ b/examples/piano/main.go @@ -49,12 +49,13 @@ var pcm = make([]float64, 4*sampleRate) const baseFreq = 220 func init() { + const twoPiF = 2.0 * math.Pi * baseFreq + s := float64(sampleRate) amp := []float64{1.0, 0.8, 0.6, 0.4, 0.2} x := []float64{4.0, 2.0, 1.0, 0.5, 0.25} for i := 0; i < len(pcm); i++ { v := 0.0 - twoPiF := 2.0 * math.Pi * baseFreq for j := 0; j < len(amp); j++ { a := amp[j] * math.Exp(-5*float64(i)/(x[j]*s)) v += a * math.Sin(float64(i)*twoPiF*float64(j+1)/s)