Created
January 20, 2015 10:10
-
-
Save metakeule/a671c333a20f3c1ed836 to your computer and use it in GitHub Desktop.
simple example how to use azul3d.org/audio
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
// simple example how to use azul3d.org/audio | |
// | |
// run it with SoX | |
// go run main.go | play - | |
// | |
// or save it to a file | |
// go run main.go > test.wav | |
// | |
package main | |
import ( | |
"azul3d.org/audio.v1" | |
"azul3d.org/audio/wav.v1" | |
"math" | |
"os" | |
) | |
var ( | |
amp = 0.5 | |
freq1 = 220.0 | |
freq2 = 880.0 | |
dur = 1.5 | |
) | |
func main() { | |
bf := audio.NewBuffer(audio.PCM16Samples{}) | |
enc, err := wav.NewEncoder(os.Stdout, audio.Config{44100, 2}) | |
if err != nil { | |
panic(err) | |
} | |
defer enc.Close() | |
q := 2 * math.Pi / 22050 | |
for i := 0.0; i < dur*44100.0; i++ { | |
bf.WriteSample(audio.F64(math.Sin(i*freq1*q) * amp)) | |
bf.WriteSample(audio.F64(math.Sin(i*freq2*q) * amp)) | |
} | |
bf.WriteTo(enc) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment