本文整理汇总了Golang中github.com/gordonklaus/portaudio.Terminate函数的典型用法代码示例。如果您正苦于以下问题:Golang Terminate函数的具体用法?Golang Terminate怎么用?Golang Terminate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Terminate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var m Meter
m.Initialize()
defer portaudio.Terminate()
var FLAGS_list = false
flag.BoolVar(&FLAGS_list, "l", false, "List all devices")
flag.Parse()
if FLAGS_list {
m.LogDevices()
return
}
s := m.OpenStream()
defer s.Close()
select {
// Wait forever.
}
if err := s.Stop(); err != nil {
fmt.Printf("portaudio.Stream.Stop failed: ", err)
return
}
}
开发者ID:davidhubbard,项目名称:gosphinx,代码行数:25,代码来源:2filter.go
示例2: 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
}
开发者ID:rdbrdd,项目名称:sconsify,代码行数:25,代码来源:spotify.go
示例3: 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})
}
开发者ID:lamproae,项目名称:sigourney,代码行数:33,代码来源:main.go
示例4: 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)
}
}
开发者ID:gordonklaus,项目名称:songs,代码行数:27,代码来源:beep.go
示例5: main
func main() {
portaudio.Initialize()
defer portaudio.Terminate()
hs, err := portaudio.HostApis()
chk(err)
err = tmpl.Execute(os.Stdout, hs)
chk(err)
}
开发者ID:charneykaye,项目名称:portaudio,代码行数:8,代码来源:enumerate.go
示例6: OnTerm
func (a *app) OnTerm() {
if a.pastream != nil {
a.pastream.Stop()
a.pastream.Close()
chk(portaudio.Terminate())
}
a.r.Close()
}
开发者ID:jacereda,项目名称:webmplay,代码行数:8,代码来源:webmplay.go
示例7: 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())
}
开发者ID:charneykaye,项目名称:portaudio,代码行数:9,代码来源:stereoSine.go
示例8: 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())
}
开发者ID:charneykaye,项目名称:portaudio,代码行数:9,代码来源:echo.go
示例9: 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:
}
}
}
开发者ID:kladd,项目名称:stt,代码行数:53,代码来源:stt.go
示例10: 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
}
开发者ID:KoehlerClem,项目名称:sconsify,代码行数:14,代码来源:spotify.go
示例11: 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())
}
开发者ID:charneykaye,项目名称:portaudio,代码行数:16,代码来源:noise.go
示例12: 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()
}
开发者ID:gordonklaus,项目名称:songs,代码行数:47,代码来源:boop.go
示例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()
}()
}
开发者ID:gordonklaus,项目名称:audio,代码行数:20,代码来源:play_other.go
示例14: 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
}
开发者ID:tescalada,项目名称:go-KX3-panadapter,代码行数:20,代码来源:main.go
示例15: 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)
}
开发者ID:jxwufan,项目名称:nes,代码行数:36,代码来源:run.go
示例16: 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())
}
开发者ID:charneykaye,项目名称:portaudio,代码行数:76,代码来源:record.go
示例17: main
func main() {
if len(os.Args) < 2 {
fmt.Println("missing required argument: input file name")
return
}
fmt.Println("Playing. Press Ctrl-C to stop.")
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, os.Kill)
fileName := os.Args[1]
f, err := os.Open(fileName)
chk(err)
defer f.Close()
id, data, err := readChunk(f)
chk(err)
if id.String() != "FORM" {
fmt.Println("bad file format")
return
}
_, err = data.Read(id[:])
chk(err)
if id.String() != "AIFF" {
fmt.Println("bad file format")
return
}
var c commonChunk
var audio io.Reader
for {
id, chunk, err := readChunk(data)
if err == io.EOF {
break
}
chk(err)
switch id.String() {
case "COMM":
chk(binary.Read(chunk, binary.BigEndian, &c))
case "SSND":
chunk.Seek(8, 1) //ignore offset and block
audio = chunk
default:
fmt.Printf("ignoring unknown chunk '%s'\n", id)
}
}
//assume 44100 sample rate, mono, 32 bit
portaudio.Initialize()
defer portaudio.Terminate()
out := make([]int32, 8192)
stream, err := portaudio.OpenDefaultStream(0, 1, 44100, len(out), &out)
chk(err)
defer stream.Close()
chk(stream.Start())
defer stream.Stop()
for remaining := int(c.NumSamples); remaining > 0; remaining -= len(out) {
if len(out) > remaining {
out = out[:remaining]
}
err := binary.Read(audio, binary.BigEndian, out)
if err == io.EOF {
break
}
chk(err)
chk(stream.Write())
select {
case <-sig:
return
default:
}
}
}
开发者ID:charneykaye,项目名称:portaudio,代码行数:74,代码来源:play.go
示例18: main
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage:", os.Args[0], "hostname:port [buffer-duration]")
os.Exit(1)
return
}
portaudio.Initialize()
defer portaudio.Terminate()
addr := os.Args[1]
bufferStr := "100ms"
if len(os.Args) > 2 {
bufferStr = os.Args[2]
}
bufferLen, err := time.ParseDuration(bufferStr)
if err != nil {
fmt.Printf("Invalid buffer length: %v\n", err)
return
}
conn, err := net.Dial("tcp", addr)
if err != nil {
fmt.Println("Error connecting to server:", err)
return
}
defer conn.Close()
buf := make([]byte, 8)
_, err = io.ReadFull(conn, buf)
if err != nil {
fmt.Println("Error reading headers:", err)
return
}
if buf[0] != 'R' {
fmt.Printf("Invalid header start: %x\n", buf[0])
return
} else if buf[1] == 0 {
fmt.Println("Server is full")
return
} else if buf[1] != 1 {
fmt.Printf("Unsupported protocol version: %d\n", buf[1])
return
}
flags := buf[2]
if flags&rawstreamer.EncodingLittleEndian != 0 {
Endianness = binary.LittleEndian
} else if flags&rawstreamer.EncodingBigEndian != 0 {
Endianness = binary.BigEndian
} else {
fmt.Println("Encoding endianness not specified!")
return
}
encoding := flags & rawstreamer.EncodingMask
numBytes := int(buf[3])
bits := numBytes * 8
if numBytes < 1 || numBytes > 4 {
fmt.Printf("Unsupported number of bits: %d\n", bits)
return
}
if encoding == rawstreamer.EncodingFloatingPoint {
numBytes = 4
bits = 32
}
sampleRate := Endianness.Uint32(buf[4:])
fmt.Printf("Streaming info: %dHz, ", sampleRate)
fmt.Printf("%dbit %s, ", bits, rawstreamer.EncodingString[encoding])
fmt.Printf("%s, %v buffer\n", Endianness.String(), bufferLen)
bufferSize := sampleRate / 50 // 20ms buffer size
Buffers = []chan float32{
make(chan float32, getChannelBufferSize(bufferLen, bufferSize, sampleRate)),
make(chan float32, getChannelBufferSize(bufferLen, bufferSize, sampleRate)),
}
Buffering = int32(getChannelBufferSize(bufferLen, bufferSize, sampleRate))
LastLeft = 0
LastRight = 0
printStatus()
Stream, err = portaudio.OpenDefaultStream(0, 2, float64(sampleRate), int(bufferSize), processAudio)
defer Stream.Close()
err = Stream.Start()
if err != nil {
fmt.Println("Failed to start stream:", err)
return
}
defer func() {
Stream.Stop()
close(Buffers[0])
close(Buffers[1])
}()
//.........这里部分代码省略.........
开发者ID:xthexder,项目名称:rawstreamer,代码行数:101,代码来源:rawplayer.go
示例19: Init
// Init starts the audio system, loads sound assets, and starts the sound loop.
func Init() error {
if err := portaudio.Initialize(); err != nil {
return err
}
log.Printf("PortAudio version: %d %s", portaudio.Version(), portaudio.VersionText())
var err error
makeBuffer := func(name string) []int16 {
if err != nil {
return nil
}
var r io.Reader
if r, err = asset.Reader(name); err != nil {
return nil
}
var w *wav
if w, err = decodeWAV(r); err != nil {
return nil
}
log.Printf("%s: %+v", name, w)
buf := make([]int16, len(w.data)/2)
for i := 0; i < len(buf); i++ {
buf[i] = int16(w.data[i*2])
buf[i] += int16(w.data[i*2+1]) << 8
}
return buf
}
var soundBuffers [][]int16
for _, a := range soundAssets {
soundBuffers = append(soundBuffers, makeBuffer(a))
}
if err != nil {
return err
}
soundQueue := make(chan Sound, soundQueueSize)
Play = func(s Sound) {
soundQueue <- s
}
done := make(chan bool)
Terminate = func() {
done <- true
<-done
close(done)
logFatalIfErr("portaudio.Terminate", portaudio.Terminate())
}
go func() {
const (
numInputChannels = 0 /* zero input - no recording */
numOutputChannels = 2 /* stereo output */
sampleRate = 44100 /* samples per second */
intervalMs = 100
framesPerBuffer = sampleRate / 1000.0 * intervalMs /* len(buf) == numChannels * framesPerBuffer */
outputBufferSize = numOutputChannels * framesPerBuffer
)
// Temporary buffers to read and write the next audio batch.
tmpIn := make([]int16, outputBufferSize)
tmpOut := make([]int16, outputBufferSize)
// outputRingBuffer is a buffer that the PortAudio callback will read data from,
// and that we will periodically wake up to write new data to.
outputRingBuffer := newRingBuffer(outputBufferSize * 10)
// process is the callback that PortAudio will call when it needs audio data.
process := func(out []int16) {
outputRingBuffer.pop(tmpIn)
for i := 0; i < len(out); i++ {
out[i] = tmpIn[i]
}
}
stream, err := portaudio.OpenDefaultStream(numInputChannels, numOutputChannels, sampleRate, framesPerBuffer, process)
logFatalIfErr("portaudio.OpenDefaultStream", err)
defer func() {
logFatalIfErr("stream.Close", stream.Close())
}()
logFatalIfErr("stream.Start()", stream.Start())
defer func() {
// stream.Stop blocks until all samples have been played.
logFatalIfErr("stream.Stop", stream.Stop())
done <- true
}()
var active [][]int16
quit := false
loop:
for {
select {
case <-time.After(intervalMs * time.Millisecond):
//.........这里部分代码省略.........
开发者ID:btmura,项目名称:blockcillin,代码行数:101,代码来源:audio.go
示例20: Run
func Run() {
chk(LoadUgen("./inst/spread.so", "spread"))
chk(LoadUgen("./inst/reverb.so", "reverb"))
chk(LoadUgen("./inst/lead2.so", "midi"))
chk(LoadUgen("./inst/lead.so", "lead"))
chk(LoadUgen("./inst/bass.so", "bass"))
chk(LoadUgen("./inst/snare.so", "snare"))
chk(LoadUgen("./inst/lopass.so", "lopass"))
shouldRecord := flag.Bool("record", false, "whether to record")
addr := flag.String("addr", "localhost:8080", "http service address")
flag.Parse()
portaudio.Initialize()
defer portaudio.Terminate()
if *shouldRecord {
var err error
f, err = os.Create("/tmp/recording.f32")
// # to play:
// $ play -x -r 44100 -c 1 /tmp/recording.f32
// # to convert to wav:
// $ sox -x -r 44100 -c 1 /tmp/recording.f32 recording.wav
chk(err)
}
s, err := openStream(processAudio)
fmt.Println("%+v\n", s.Info())
chk(err)
defer s.Close()
if true {
service.Initialize(*addr, cmdHandle)
}
if true {
client, err := coremidi.NewClient("midi client")
chk(err)
port, err := coremidi.NewInputPort(client, "test",
func(source coremidi.Source, event []byte) {
handleMidiEvent(event, bleeps)
})
chk(err)
sources, err := coremidi.AllSources()
chk(err)
for _, source := range sources {
// func(source coremidi.Source) {
fmt.Printf("Listening to midi source %s [%s]\n", source.Name(), source.Manufacturer())
port.Connect(source)
// }(source)
}
}
filterOn("reverb", 80.0, []*float64{getBus(0)})
filterOn("lopass", 90.0, []*float64{getBus(0), &resFreq, &Q})
filterOn("spread", 100.0, []*float64{getBus(0), getBus(1)})
go func() {
for {
fmt.Printf("inner loop taking avg ~%f samples\n", inner.Seconds()*sampleRate/float64(innerCount))
inner = 0
innerCount = 0
time.Sleep(1 * time.Second)
}
}()
chk(s.Start())
select {}
defer chk(s.Stop())
}
开发者ID:jcreedcmu,项目名称:gosynth,代码行数:71,代码来源:run.go
注:本文中的github.com/gordonklaus/portaudio.Terminate函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论