Skip to content

Instantly share code, notes, and snippets.

@metakeule
Created January 20, 2015 10:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metakeule/a671c333a20f3c1ed836 to your computer and use it in GitHub Desktop.
Save metakeule/a671c333a20f3c1ed836 to your computer and use it in GitHub Desktop.
simple example how to use azul3d.org/audio
// 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