-
-
Save faiface/ce6fcac6fa89cc71dcc3a10f2dde2149 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Mix( | |
audio.Seq( | |
audio.Take(time.Second*3, sin(440, 0.3)), | |
audio.Take(time.Second*3, sin(550, 0.3)), | |
audio.Take(time.Second*3, sin(880, 0.3)), | |
), | |
audio.Seq( | |
audio.Take(time.Second, sin(440, 0.1)), | |
audio.Take(time.Second, sin(550, 0.1)), | |
audio.Take(time.Second, sin(880, 0.1)), | |
audio.Take(time.Second, sin(440, 0.1)), | |
audio.Take(time.Second, sin(550, 0.1)), | |
audio.Take(time.Second, sin(880, 0.1)), | |
audio.Take(time.Second, sin(440, 0.1)), | |
audio.Take(time.Second, sin(550, 0.1)), | |
audio.Take(time.Second, sin(880, 0.1)), | |
), | |
)) | |
time.Sleep(time.Second * 10) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment