Last active
October 17, 2017 16:37
-
-
Save jspc/9a3fb52ebc9a7fe723bc92cac94b64f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"math" | |
) | |
type Sine struct { | |
freqPerSample float64 | |
phase float64 | |
multiplier float64 | |
} | |
func NewSine(frequency, sampleRate, multiplier float64) *Sine { | |
return &Sine{ | |
freqPerSample: 2 * math.Pi * frequency / sampleRate, | |
multiplier: multiplier, | |
phase: 0.0, | |
} | |
} | |
func (s *Sine) Next() int64 { | |
s.phase = s.phase + s.freqPerSample | |
return int64(math.Sin(s.phase) * s.multiplier) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment