Skip to content

Instantly share code, notes, and snippets.

@jspc
Last active October 17, 2017 16:37
Show Gist options
  • Save jspc/9a3fb52ebc9a7fe723bc92cac94b64f0 to your computer and use it in GitHub Desktop.
Save jspc/9a3fb52ebc9a7fe723bc92cac94b64f0 to your computer and use it in GitHub Desktop.
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