本文整理汇总了Golang中github.com/gordonklaus/portaudio.Initialize函数的典型用法代码示例。如果您正苦于以下问题:Golang Initialize函数的具体用法?Golang Initialize怎么用?Golang Initialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Initialize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: finishInitialisation
func (spotify *Spotify) finishInitialisation(webApiAuth bool, pa *portAudio) error {
if webApiAuth {
if spotify.client = webapi.Auth(); spotify.client != nil {
if privateUser, err := spotify.client.CurrentUser(); err == nil {
if privateUser.ID != spotify.session.LoginUsername() {
return errors.New("Username doesn't match with web-api authorization")
}
} else {
spotify.client = nil
}
}
}
// init audio could happen after initPlaylist but this logs to output therefore
// the screen isn't built properly
portaudio.Initialize()
go pa.player()
defer portaudio.Terminate()
if err := spotify.initPlaylist(); err != nil {
return err
}
spotify.waitForEvents()
return nil
}
示例2: main
func main() {
flag.Parse()
portaudio.Initialize()
defer portaudio.Terminate()
portmidi.Initialize()
defer portmidi.Terminate()
if *doDemo {
if err := demo(); err != nil {
log.Println(err)
}
return
}
http.Handle("/", http.FileServer(http.Dir("static")))
http.HandleFunc("/socket", socket.Handler)
l, err := net.Listen("tcp", *listenAddr)
if err != nil {
log.Fatal(err)
}
go http.Serve(l, nil)
u := fmt.Sprintf("http://%v/", *listenAddr)
if !*doBrowser || !openBrowser(u) {
fmt.Printf("Open your web browser to %v\n\n", u)
}
fmt.Println("Press enter to quit...")
os.Stdin.Read([]byte{0})
}
示例3: main
func main() {
w := &window{voices: map[int]*sineVoice{}}
p := audio.Params{SampleRate: 96000}
audio.Init(w, p)
portaudio.Initialize()
defer portaudio.Terminate()
s, err := portaudio.OpenDefaultStream(0, 1, p.SampleRate, 64, w.processAudio)
if err != nil {
fmt.Println(err)
return
}
if err := s.Start(); err != nil {
fmt.Println(err)
return
}
defer s.Stop()
if err := gui.Run(func() {
gui.NewWindow(w, "beep", func(win *gui.Window) {
w.Window = win
gui.SetKeyFocus(w)
})
}); err != nil {
fmt.Println(err)
}
}
示例4: main
func main() {
portaudio.Initialize()
defer portaudio.Terminate()
hs, err := portaudio.HostApis()
chk(err)
err = tmpl.Execute(os.Stdout, hs)
chk(err)
}
示例5: main
func main() {
portaudio.Initialize()
defer portaudio.Terminate()
e := newEcho(time.Second / 3)
defer e.Close()
chk(e.Start())
time.Sleep(4 * time.Second)
chk(e.Stop())
}
示例6: main
func main() {
portaudio.Initialize()
defer portaudio.Terminate()
s := newStereoSine(256, 320, sampleRate)
defer s.Close()
chk(s.Start())
time.Sleep(2 * time.Second)
chk(s.Stop())
}
示例7: record
// Slightly modified exact copy of the portaudio example
func record(f *os.File, timer <-chan time.Time) {
// form chunk
_, _ = f.WriteString("FORM")
binary.Write(f, binary.BigEndian, int32(0))
_, _ = f.WriteString("AIFF")
// common chunk
_, _ = f.WriteString("COMM")
binary.Write(f, binary.BigEndian, int32(18))
binary.Write(f, binary.BigEndian, int16(1))
binary.Write(f, binary.BigEndian, int32(0))
binary.Write(f, binary.BigEndian, int16(32))
_, _ = f.Write([]byte{0x40, 0x0e, 0xac, 0x44, 0, 0, 0, 0, 0, 0}) //80-bit sample rate 44100
// sound chunk
_, _ = f.WriteString("SSND")
binary.Write(f, binary.BigEndian, int32(0))
binary.Write(f, binary.BigEndian, int32(0))
binary.Write(f, binary.BigEndian, int32(0))
nSamples := 0
defer func() {
// fill in missing sizes
totalBytes := 4 + 8 + 18 + 8 + 8 + 4*nSamples
_, _ = f.Seek(4, 0)
binary.Write(f, binary.BigEndian, int32(totalBytes))
_, _ = f.Seek(22, 0)
binary.Write(f, binary.BigEndian, int32(nSamples))
_, _ = f.Seek(42, 0)
binary.Write(f, binary.BigEndian, int32(4*nSamples+8))
f.Close()
}()
portaudio.Initialize()
defer portaudio.Terminate()
in := make([]int32, 64)
stream, _ := portaudio.OpenDefaultStream(1, 0, 44100, len(in), in)
defer stream.Close()
stream.Start()
defer stream.Stop()
for {
stream.Read()
binary.Write(f, binary.BigEndian, in)
nSamples += len(in)
select {
case <-timer:
return
default:
}
}
}
示例8: finishInitialisation
func (spotify *Spotify) finishInitialisation(pa *portAudio) error {
// init audio could happen after initPlaylist but this logs to output therefore
// the screen isn't built properly
portaudio.Initialize()
go pa.player()
defer portaudio.Terminate()
if err := spotify.initPlaylist(); err != nil {
return err
}
spotify.waitForEvents()
return nil
}
示例9: OnInit
func (a *app) OnInit() {
var err error
a.r, err = os.Open(*in)
if err != nil {
log.Fatalf("Unable to open file '%s': %s", *in, err)
}
var wm webm.WebM
a.reader, err = webm.Parse(a.r, &wm)
if err != nil {
log.Fatal("Unable to parse file: ", err)
}
a.duration = wm.GetDuration()
var vtrack *webm.TrackEntry
if !*justaudio {
vtrack = wm.FindFirstVideoTrack()
}
var vstream *webm.Stream
if vtrack != nil {
vstream = webm.NewStream(vtrack)
a.fduration = vtrack.GetDefaultDuration()
a.vchan = vstream.VideoChannel()
}
var atrack *webm.TrackEntry
if !*justvideo {
atrack = wm.FindFirstAudioTrack()
}
var astream *webm.Stream
if atrack != nil {
astream = webm.NewStream(atrack)
}
splitter := webm.NewSplitter(a.reader.Chan)
splitter.Split(astream, vstream)
a.steps = uint(0xffffffff)
if a.vchan != nil {
a.img = <-a.vchan
a.pimg = a.img
}
if atrack != nil {
channels := int(atrack.Audio.Channels)
a.aw = &AudioWriter{ch: astream.AudioChannel(),
channels: channels, active: true}
chk(portaudio.Initialize())
a.pastream, err = portaudio.OpenDefaultStream(0, channels,
atrack.Audio.SamplingFrequency, 0, a.aw.processAudio)
chk(err)
chk(a.pastream.Start())
}
}
示例10: main
func main() {
portaudio.Initialize()
defer portaudio.Terminate()
h, err := portaudio.DefaultHostApi()
chk(err)
stream, err := portaudio.OpenStream(portaudio.HighLatencyParameters(nil, h.DefaultOutputDevice), func(out []int32) {
for i := range out {
out[i] = int32(rand.Uint32())
}
})
chk(err)
defer stream.Close()
chk(stream.Start())
time.Sleep(time.Second)
chk(stream.Stop())
}
示例11: main
func main() {
flag.Parse()
if *random {
*seed = time.Now().UnixNano()
fmt.Println("seed =", *seed)
}
if *seed != math.MinInt64 {
*random = true
}
rand.Seed(*seed)
portaudio.Initialize()
defer portaudio.Terminate()
p := audio.Params{SampleRate: 48000}
m := audio.MultiVoice{}
audio.Init(&m, p)
// for _, x := range [][2]float64{{1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {3, 2}, {4, 3}, {5, 4}, {7, 4}, {6, 5}, {7, 5}, {8, 5}, {9, 5}} {
for xy := 1; xy <= 60; xy++ {
for x := 2; x <= int(math.Sqrt(float64(xy))); x++ {
if y := xy / x; x*y == xy && relPrime(x, y) {
x, y, xy := float64(x), float64(y), float64(xy)
c := math.Exp(-xy * math.Log2(y/x) / 12)
f := y / x
phase := 0.0
if *random {
phase = rand.Float64()
}
m.Add(newSineBeat(.5*c, 128*f, 1/xy, phase, .1/f))
}
}
}
s, err := portaudio.OpenDefaultStream(0, 1, p.SampleRate, 512, func(out []float32) {
for i := range out {
out[i] = float32(audio.Saturate(m.Sing()))
}
})
if err != nil {
panic(err)
}
s.Start()
fmt.Println("Press Enter to stop.")
fmt.Scanln()
s.Stop()
}
示例12: Start
func (self *Server) Start() error {
portaudio.Initialize()
defer portaudio.Terminate()
var err error
if err = self.startAudio(); err != nil {
return err
}
if err = self.startSerial(); err != nil {
return err
}
if err = self.startHttp(); err != nil {
return err
}
return nil
}
示例13: init
func init() {
portaudio.Initialize()
go func() {
defer os.Exit(0)
sig := make(chan os.Signal, 1)
signal.Notify(sig)
if <-sig == syscall.SIGQUIT {
buf := make([]byte, 1<<10)
for runtime.Stack(buf, true) == len(buf) {
buf = make([]byte, 2*len(buf))
}
fmt.Fprintln(os.Stderr, string(buf))
}
for _, c := range playControls {
c.Stop()
<-c.Done
}
portaudio.Terminate()
}()
}
示例14: Run
func Run(paths []string) {
// initialize audio
portaudio.Initialize()
defer portaudio.Terminate()
audio := NewAudio()
if err := audio.Start(); err != nil {
log.Fatalln(err)
}
defer audio.Stop()
// initialize glfw
if err := glfw.Init(); err != nil {
log.Fatalln(err)
}
defer glfw.Terminate()
// create window
glfw.WindowHint(glfw.ContextVersionMajor, 2)
glfw.WindowHint(glfw.ContextVersionMinor, 1)
window, err := glfw.CreateWindow(width*scale, height*scale, title, nil, nil)
if err != nil {
log.Fatalln(err)
}
window.MakeContextCurrent()
// initialize gl
if err := gl.Init(); err != nil {
log.Fatalln(err)
}
gl.Enable(gl.TEXTURE_2D)
// run director
director := NewDirector(window, audio)
director.Start(paths)
}
示例15: main
func main() {
if len(os.Args) < 2 {
fmt.Println("missing required argument: output file name")
return
}
fmt.Println("Recording. Press Ctrl-C to stop.")
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, os.Kill)
fileName := os.Args[1]
if !strings.HasSuffix(fileName, ".aiff") {
fileName += ".aiff"
}
f, err := os.Create(fileName)
chk(err)
// form chunk
_, err = f.WriteString("FORM")
chk(err)
chk(binary.Write(f, binary.BigEndian, int32(0))) //total bytes
_, err = f.WriteString("AIFF")
chk(err)
// common chunk
_, err = f.WriteString("COMM")
chk(err)
chk(binary.Write(f, binary.BigEndian, int32(18))) //size
chk(binary.Write(f, binary.BigEndian, int16(1))) //channels
chk(binary.Write(f, binary.BigEndian, int32(0))) //number of samples
chk(binary.Write(f, binary.BigEndian, int16(32))) //bits per sample
_, err = f.Write([]byte{0x40, 0x0e, 0xac, 0x44, 0, 0, 0, 0, 0, 0}) //80-bit sample rate 44100
chk(err)
// sound chunk
_, err = f.WriteString("SSND")
chk(err)
chk(binary.Write(f, binary.BigEndian, int32(0))) //size
chk(binary.Write(f, binary.BigEndian, int32(0))) //offset
chk(binary.Write(f, binary.BigEndian, int32(0))) //block
nSamples := 0
defer func() {
// fill in missing sizes
totalBytes := 4 + 8 + 18 + 8 + 8 + 4*nSamples
_, err = f.Seek(4, 0)
chk(err)
chk(binary.Write(f, binary.BigEndian, int32(totalBytes)))
_, err = f.Seek(22, 0)
chk(err)
chk(binary.Write(f, binary.BigEndian, int32(nSamples)))
_, err = f.Seek(42, 0)
chk(err)
chk(binary.Write(f, binary.BigEndian, int32(4*nSamples+8)))
chk(f.Close())
}()
portaudio.Initialize()
defer portaudio.Terminate()
in := make([]int32, 64)
stream, err := portaudio.OpenDefaultStream(1, 0, 44100, len(in), in)
chk(err)
defer stream.Close()
chk(stream.Start())
for {
chk(stream.Read())
chk(binary.Write(f, binary.BigEndian, in))
nSamples += len(in)
select {
case <-sig:
return
default:
}
}
chk(stream.Stop())
}