本文整理汇总了Golang中code/google/com/p/portaudio-go/portaudio.Initialize函数的典型用法代码示例。如果您正苦于以下问题:Golang Initialize函数的具体用法?Golang Initialize怎么用?Golang Initialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Initialize函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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", socketHandler)
go func() {
if err := http.ListenAndServe(*listenAddr, nil); err != nil {
log.Println(err)
}
}()
os.Stdout.Write([]byte("Press enter to stop...\n"))
os.Stdin.Read([]byte{0})
}
开发者ID:rakyll,项目名称:sigourney,代码行数:27,代码来源:main.go
示例2: main
func main() {
flag.Parse()
sequencer := NewSequencer()
for _, file := range flag.Args() {
pattern, err := drum.DecodeFile(file)
if err != nil {
log.Fatal(err)
}
if err := sequencer.Add(pattern); err != nil {
log.Fatal(err)
}
log.Print(pattern.String())
}
portaudio.Initialize()
defer portaudio.Terminate()
stream, err := portaudio.OpenDefaultStream(0, 2, 44100, 0, func(o []int32) {
sequencer.Read(o)
})
if err != nil {
log.Fatal(err)
}
defer stream.Close()
stream.Start()
defer stream.Stop()
sequencer.Start()
for {
time.Sleep(time.Second)
}
}
开发者ID:rubyist,项目名称:tdrum,代码行数:34,代码来源:player.go
示例3: NewSequencer
// NewSequencer creates and returns a pointer to a New Sequencer.
// Returns an error if there is one encountered
// During initializing portaudio, or the default stream
func NewSequencer() (*Sequencer, error) {
err := portaudio.Initialize()
if err != nil {
return nil, err
}
s := &Sequencer{
Timer: NewTimer(),
Bar: 0,
Beat: 0,
}
stream, err := portaudio.OpenDefaultStream(
InputChannels,
OutputChannels,
float64(SampleRate),
portaudio.FramesPerBufferUnspecified,
s.ProcessAudio,
)
if err != nil {
return nil, err
}
s.Stream = stream
return s, nil
}
开发者ID:billyboar,项目名称:GCSolutions,代码行数:31,代码来源:sequencer.go
示例4: main
func main() {
portaudio.Initialize()
defer portaudio.Terminate()
hs, err := portaudio.HostApis()
chk(err)
err = tmpl.Execute(os.Stdout, hs)
chk(err)
}
开发者ID:krak3n,项目名称:portaudio-go,代码行数:8,代码来源:enumerate.go
示例5: init
func init() {
err := pa.Initialize() // seems to be needed before doing other stuff with pa
if err != nil {
fmt.Printf("Error: %s\n", err)
// os.Exit(1)
}
// defer pa.Terminate()
}
开发者ID:refola,项目名称:golang,代码行数:8,代码来源:input.go
示例6: main
func main() {
sampleRate := 44100
blockSize := 205 * sampleRate / 8000
window := blockSize / 4
dt := dtmf.NewStandard(sampleRate, blockSize)
lastKey := -1
keyCount := 0
samples := make([]float32, blockSize)
if err := portaudio.Initialize(); err != nil {
log.Fatalf("Initialize: %+v", err)
}
defer func() {
if err := portaudio.Terminate(); err != nil {
log.Fatalf("Terminate: %+v", err)
}
}()
inputBuf := make([]float32, window)
stream, err := portaudio.OpenDefaultStream(1, 0, float64(sampleRate), len(inputBuf), inputBuf)
if err != nil {
log.Fatalf("OpenDefaultStream: %+v", err)
}
defer stream.Close()
if err := stream.Start(); err != nil {
log.Fatalf("Start: %+v", err)
}
defer stream.Stop()
fmt.Printf("%+v\n", stream.Info())
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, os.Kill)
for {
if err := stream.Read(); err != nil {
log.Fatalf("Read: %+v", err)
}
copy(samples, samples[window:])
copy(samples[len(samples)-len(inputBuf):], inputBuf)
if k, t := dt.Feed(samples); k == lastKey && t > 0.0 {
keyCount++
if keyCount == 10 {
fmt.Printf("%c", dtmf.Keypad[k])
}
} else {
lastKey = k
keyCount = 0
}
select {
case <-sig:
fmt.Println()
return
default:
}
}
}
开发者ID:joerocklin,项目名称:go-dsp,代码行数:58,代码来源:dtmf_live.go
示例7: Run
// Runs the sampler, commencing output to an audio device.
func (s *Sampler) Run() error {
portaudio.Initialize()
var err error
s.stream, err = portaudio.OpenDefaultStream(0, 2, 44100, 0, s.processAudio)
if err != nil {
return err
}
return s.stream.Start()
}
开发者ID:lamproae,项目名称:audio-1,代码行数:10,代码来源:sampler.go
示例8: Play
// Play will play the given pattern.
// It will generate different sounds for each instrument
// every time it is called. For simplification, those sounds
// are just sine waves.
func (p *Pattern) Play(playingTime time.Duration) error {
// Initialize portaudio
portaudio.Initialize()
defer portaudio.Terminate()
stream, err := portaudio.OpenDefaultStream(0, 1, sampleRate, 0, processAudio)
if err != nil {
return errors.New("could not open default stream")
}
defer stream.Close()
// Create random tone map
toneMap = make(map[byte]*tone)
rand.Seed(time.Now().Unix())
for i := range p.instruments {
var err error
toneMap[i], err = newTone(rand.Float64()*600+300, sampleRate)
if err != nil {
return fmt.Errorf("could not create tone for instrument %v", i)
}
}
stream.Start()
defer stream.Stop()
// Signal for stopping
timeOut := time.After(playingTime)
timePerStep := time.Duration(60/p.header.BPM*1000) * time.Millisecond
ticker := time.NewTicker(timePerStep)
currentStep := 0
// Play!
for _ = range ticker.C {
for i, instrument := range p.instruments {
if instrument.Pattern[currentStep] == 0 {
toneMap[i].playing = false
} else {
toneMap[i].playing = true
}
}
currentStep++
if currentStep > 15 {
currentStep = 0
}
select {
case <-timeOut:
ticker.Stop()
return nil
default:
}
}
return nil
}
开发者ID:billyboar,项目名称:GCSolutions,代码行数:61,代码来源:player.go
示例9: 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:krak3n,项目名称:portaudio-go,代码行数:9,代码来源:echo.go
示例10: 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:krak3n,项目名称:portaudio-go,代码行数:9,代码来源:stereoSine.go
示例11: sineLogon
func sineLogon() {
portaudio.Initialize()
defer portaudio.Terminate()
s := newStereoSine(132, 198/2, sampleRate)
defer s.Close()
chk(s.Start())
doADSR(s, 0.4, 0.1, 0.1)
doADSR(s, 0.1, 0.8, 0.9)
// wait for buffer to drain
time.Sleep(500 * time.Millisecond)
chk(s.Stop())
}
开发者ID:cfstras,项目名称:cfmedias,代码行数:14,代码来源:sineLogon.go
示例12: sineMain
func sineMain(ch *amqp.Channel) {
go sniffy()
q, err := ch.QueueDeclare(
"", // name
false, // durable
false, // delete when usused
true, // exclusive
false, // no-wait
nil, // arguments
)
failOnError(err, "Failed to declare a queue")
err = ch.QueueBind(
q.Name, // queue name
"", // routing key
"bpm", // exchange
false,
nil)
failOnError(err, "Failed to bind a queue")
msgs, err := ch.Consume(
q.Name, // queue
"", // consumer
true, // auto-ack
false, // exclusive
false, // no-local
false, // no-wait
nil, // args
)
failOnError(err, "Failed to register a consumer")
portaudio.Initialize()
defer portaudio.Terminate()
//s := newStereoSine(256, 320, sampleRate)
s := newStereoSine(220, 220, sampleRate)
defer s.Close()
chk(s.Start())
defer s.Stop()
for m := range msgs {
var bm BpmMsg
err := json.Unmarshal(m.Body, &bm)
if err != nil {
fmt.Println("blah", err)
}
bpm = bm.Bpm
}
}
开发者ID:sideb0ard,项目名称:Craxx,代码行数:49,代码来源:sine.go
示例13: 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:krak3n,项目名称:portaudio-go,代码行数:16,代码来源:noise.go
示例14: InitAudio
// InitAudio starts up PortAudio, creates a stream and
// returns a pointer to an Audio struct, or an error.
func InitAudio() (*Audio, error) {
a := Audio{
tracks: make([]*Track, 0),
}
err := portaudio.Initialize()
if err != nil {
return nil, err
}
stream, err := portaudio.OpenDefaultStream(
0, 2, float64(44100), 0, a.playCallback,
)
if err != nil {
return nil, err
}
a.stream = stream
a.stream.Start()
return &a, nil
}
开发者ID:XQYCHJ,项目名称:termloop,代码行数:20,代码来源:audio.go
示例15: main
func main() {
flag.Usage = func() {
fmt.Fprint(os.Stderr, usage)
flag.PrintDefaults()
os.Exit(2)
}
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
}
p, err := drum.DecodeFile(flag.Arg(0))
if err != nil {
log.Fatalf("cannot decode splice file: %v", err)
}
if *showInfo {
fmt.Print(p)
return
}
patches, err := readPatches(p, *sampleDir)
if err != nil {
log.Fatalf("cannot read sample patches: %v", err)
}
drumMod, err := drummachine.New(p, patches)
if err != nil {
log.Fatalf("cannot make new drum machine: %v", err)
}
portaudio.Initialize()
defer portaudio.Terminate()
portmidi.Initialize()
defer portmidi.Terminate()
e := audio.NewEngine()
e.Input("in", drumMod)
if err := e.Start(); err != nil {
panic(err)
}
select {}
}
开发者ID:billyboar,项目名称:GCSolutions,代码行数:40,代码来源:main.go
示例16: NewPort
func NewPort(sampleRate, channels int) (Output, error) {
// todo: fix race condition
if portInitCount == 0 {
portaudio.Initialize()
}
portInitCount++
p := port{
ch: make(chan []float32),
}
var err error
p.st, err = portaudio.OpenDefaultStream(0, channels, float64(sampleRate), 1024, p.Fetch)
if err != nil {
p.Dispose()
return nil, err
}
if err := p.st.Start(); err != nil {
p.Dispose()
return nil, err
}
return &p, nil
}
开发者ID:rossipedia,项目名称:mog,代码行数:22,代码来源:port.go
示例17: 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:tiancode,项目名称:nes,代码行数:36,代码来源:run.go
示例18: 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:krak3n,项目名称:portaudio-go,代码行数:74,代码来源:play.go
示例19: NewMachine
// NewMachine creates the Machine struct and loads it with all
// available samples and sequences. it is expected that there will both a
// 'samples' directory and a 'sequences' directory within the package
func NewMachine(sequenceDir, sampleDir string) (*Machine, error) {
m := Machine{sequenceDir: sequenceDir, sampleDir: sampleDir}
m.Samples = make(map[string]Sample)
// load samples
dirs, err := ioutil.ReadDir(m.sampleDir)
if err != nil {
return nil, err
}
for _, d := range dirs {
if !d.IsDir() {
continue
}
files, err := ioutil.ReadDir(path.Join(m.sampleDir, d.Name()))
if err != nil {
return nil, err
}
m.Samples[d.Name()] = Sample{
Name: d.Name(),
sounds: make(map[soundKey]*audioData)}
for _, f := range files {
if strings.ToLower(path.Ext(f.Name())) != ".wav" {
continue
}
ss := strings.SplitN(f.Name(), " ", 2)
id, err := strconv.Atoi(ss[0])
if err != nil || len(ss) < 2 {
continue
}
nm := strings.SplitN(ss[1], ".", 2)
if len(nm) < 2 {
continue
}
s, err := decodeAudio(path.Join(m.sampleDir, d.Name(), f.Name()))
if err != nil {
return nil, err
}
m.Samples[d.Name()].sounds[soundKey{ID: uint16(id), Name: nm[0]}] = s
}
}
// load sequences
files, err := ioutil.ReadDir(m.sequenceDir)
if err != nil {
return nil, err
}
for _, f := range files {
if strings.ToLower(path.Ext(f.Name())) != ".splice" {
continue
}
fp := path.Join(m.sequenceDir, f.Name())
p, err := DecodeFile(fp)
if err != nil {
return nil, err
}
nm := strings.SplitN(f.Name(), ".", 2)
s := Sequence{Name: nm[0], Version: p.Version, Tempo: p.Tempo}
// create sections specified by pattern
for _, t := range p.Tracks {
if _, ok := m.Samples[p.Version].sounds[soundKey{ID: t.ID, Name: t.Name}]; !ok {
return nil, fmt.Errorf("failed to load sample sound: %v %v", t.ID, t.Name)
}
sec := Section{ID: t.ID, Name: t.Name, Beats: t.Beats, Enabled: true}
s.Sections = append(s.Sections, &sec)
}
// create sections for remaining audio samples
for sk := range m.Samples[p.Version].sounds {
add := true
for _, t := range p.Tracks {
if sk.ID == t.ID && sk.Name == t.Name {
add = false
break
}
}
if add {
sec := Section{ID: sk.ID, Name: sk.Name}
s.Sections = append(s.Sections, &sec)
}
}
m.Sequences = append(m.Sequences, &s)
}
if err := portaudio.Initialize(); err != nil {
return nil, err
}
stream, err := portaudio.OpenDefaultStream(0, 1, defaultSampleRate, 0, m.audioCallback)
if err != nil {
return nil, err
}
m.stream = stream
if err := stream.Start(); err != nil {
return nil, err
}
return &m, nil
}
开发者ID:billyboar,项目名称:GCSolutions,代码行数:100,代码来源:drum.go
示例20: PlayAIFF
// Play an AIFF file using PortAudio
// Base on example code from: https://code.google.com/p/portaudio-go/source/browse/portaudio/examples/play.go
func PlayAIFF(p string, sig chan int) error {
f, err := os.Open(p)
if err != nil {
return err
}
defer f.Close()
id, data, err := readChunk(f)
if err != nil {
return err
}
if id.String() != "FORM" {
return ErrBadFileFormat
}
_, err = data.Read(id[:])
if err != nil {
return err
}
if id.String() != "AIFF" {
return ErrBadFileFormat
}
var c commonChunk
var audio io.Reader
for {
id, chunk, err := readChunk(data)
if err == io.EOF {
break
}
if err != nil {
return err
}
switch id.String() {
case "COMM":
err = binary.Read(chunk, binary.BigEndian, &c)
if err != nil {
return err
}
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)
if err != nil {
return err
}
defer stream.Close()
err = stream.Start()
if err != nil {
return err
}
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
}
if err != nil {
return err
}
err = stream.Write()
if err != nil {
return err
}
select {
case <-sig:
return nil
default:
}
}
return nil
}
开发者ID:fun-alex-alex2006hw,项目名称:gopher_talkie,代码行数:93,代码来源:play.go
注:本文中的code/google/com/p/portaudio-go/portaudio.Initialize函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论