當前位置: 首頁>>代碼示例>>Golang>>正文


Golang portaudio.Initialize函數代碼示例

本文整理匯總了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})
}
開發者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


注:本文中的code/google/com/p/portaudio-go/portaudio.Initialize函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。