-
-
Save faiface/d9bdd46a5bea69c47f23a0a0192e8c26 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" | |
"time" | |
"github.com/faiface/pixel/audio" | |
"github.com/faiface/pixel/audio/speaker" | |
) | |
func sin(freq, volume float64) audio.Streamer { | |
t := 0.0 | |
dt := 1.0 / audio.SampleRate | |
return audio.StreamerFunc(func(samples [][2]float64) (n int, ok bool) { | |
for i := range samples { | |
val := math.Sin(math.Pi*freq*t) * volume | |
samples[i][0] = val | |
samples[i][1] = val | |
t += dt | |
} | |
return len(samples), true | |
}) | |
} | |
func main() { | |
speaker.Init(time.Second / 15) | |
speaker.Play(audio.Seq( | |
audio.Take(time.Second, sin(440, 0.3)), | |
audio.Take(time.Second, sin(550, 0.3)), | |
audio.Take(time.Second, sin(880, 0.3)), | |
)) | |
for { | |
speaker.Update() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment