本文整理汇总了Golang中code/google/com/p/portaudio-go/portaudio.Initialize函数的典型用法代码示例。如果您正苦于以下问题:Golang Initialize函数的具体用法?Golang Initialize怎么用?Golang Initialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Initialize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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})
}
示例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)
}
}
示例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
}
示例4: main
func main() {
portaudio.Initialize()
defer portaudio.Terminate()
hs, err := portaudio.HostApis()
chk(err)
err = tmpl.Execute(os.Stdout, hs)
chk(err)
}
示例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()
}
示例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:
}
}
}
示例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()
}
示例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
}
示例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())
}
示例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())
}
示例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())
}
示例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
}
}
示例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())
}
示例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
}
示例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 {}
}