本文整理汇总了Golang中code/google/com/p/portaudio-go/portaudio.OpenDefaultStream函数的典型用法代码示例。如果您正苦于以下问题:Golang OpenDefaultStream函数的具体用法?Golang OpenDefaultStream怎么用?Golang OpenDefaultStream使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OpenDefaultStream函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: newStereoSine
func newStereoSine(freqL, freqR, sampleRate float64) *stereoSine {
s := &stereoSine{nil, freqL / sampleRate, 0, freqR / sampleRate, 0}
var err error
s.Stream, err = portaudio.OpenDefaultStream(0, 2, sampleRate, 0, s.processAudio)
chk(err)
return s
}
开发者ID:sideb0ard,项目名称:Craxx,代码行数:7,代码来源:ortaudz.go
示例2: 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
示例3: Start
func (o *PortAudioOutput) Start(op OutputParams) error {
var err error
o.start.Do(func() {
o.op = op
MakeRecycleChannel(op)
if o.stream == nil {
o.stream, err = portaudio.OpenDefaultStream(0, o.channels, op.SampleRate, op.BufferSize, o)
if err != nil {
logger.Println("portaudio output creation failed", err)
return
}
}
err = o.stream.Start()
if err != nil {
logger.Println("portaudio output start failed", err)
return
}
err = o.inputs[0].Start(op)
if err != nil {
logger.Println("input 0 start failed", err)
o.stream.Stop()
return
}
logger.Printf("portaudio Start %T %p", o.inputs[0], o.inputs[0])
o.stop = new(sync.Once)
})
return err
}
开发者ID:mkb218,项目名称:ugen,代码行数:28,代码来源:portaudio.go
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例8: newStereoSine
func newStereoSine(freqL, freqR, sampleRate float64) *stereoSine {
s := &stereoSine{nil,
// timestep, phase, pan
freqL / sampleRate, 0, -1,
freqR / sampleRate, 0, 1,
0, 0, make(chan bool)}
var err error
s.Stream, err = portaudio.OpenDefaultStream(0, 2, sampleRate, 0, s.processAudio)
chk(err)
return s
}
开发者ID:cfstras,项目名称:cfmedias,代码行数:11,代码来源:sineLogon.go
示例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)
a.img = <-a.vchan
a.pimg = a.img
chk := func(err error) {
if err != nil {
panic(err)
}
}
if atrack != nil {
channels := int(atrack.Audio.Channels)
a.aw = &AudioWriter{ch: astream.AudioChannel(),
channels: channels, active: true}
a.pastream, err = portaudio.OpenDefaultStream(0, channels,
atrack.Audio.SamplingFrequency, 0, a.aw)
chk(err)
chk(a.pastream.Start())
}
}
开发者ID:ebml-go,项目名称:ebml-go,代码行数:52,代码来源:webmplay.go
示例10: main
func main() {
chk := func(err error) {
if err != nil {
panic(err)
}
}
stream, err := portaudio.OpenDefaultStream(0, 2, sampleRate, 0, newStereoSine(256, 320, sampleRate))
chk(err)
defer stream.Close()
chk(stream.Start())
time.Sleep(2 * time.Second)
chk(stream.Stop())
}
开发者ID:xushiwei,项目名称:portaudio-go,代码行数:13,代码来源:stereoSine.go
示例11: main
func main() {
chk := func(err error) {
if err != nil {
panic(err)
}
}
stream, err := portaudio.OpenDefaultStream(0, 1, 44100, 128, noiseGenerator{})
chk(err)
defer stream.Close()
chk(stream.Start())
time.Sleep(1e9)
chk(stream.Stop())
}
开发者ID:xushiwei,项目名称:portaudio-go,代码行数:13,代码来源:noise.go
示例12: main
func main() {
chk := func(err error) {
if err != nil {
panic(err)
}
}
bufferSize := 4096
stream, err := portaudio.OpenDefaultStream(1, 1, 44100, bufferSize, &echoer{make([]float32, bufferSize)})
chk(err)
defer stream.Close()
chk(stream.Start())
time.Sleep(4e9)
chk(stream.Stop())
}
开发者ID:xushiwei,项目名称:portaudio-go,代码行数:14,代码来源:echo.go
示例13: Play
func (s *sound) Play() error {
chans := len(s.sample())
str, err := portaudio.OpenDefaultStream(0, chans, s.sampleRate, 0, s.processAudio)
if err != nil {
return err
}
if err = str.Start(); err != nil {
return err
}
<-s.quit
if err := str.Stop(); err != nil {
return err
}
return str.Close()
}
开发者ID:lamproae,项目名称:audio,代码行数:16,代码来源:sampler.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: mix
func (m *mixer) mix(signalChan chan SoundGen) {
var err error
m.Stream, err = portaudio.OpenDefaultStream(0, 2, sampleRate, 0, m.processAudio)
chk(err)
defer m.Close()
chk(m.Start())
defer m.Stop()
for s := range signalChan {
if len(m.signals) > 5 {
//go func() { fmt.Println("yar!") }() // s m.signals[0]) { s.SilentStop() }
go func(m *mixer) {
fmt.Println("SILENCIO!")
// m.signals[0].SilentStop()
m.signals = m.signals[1:]
}(m) // s m.signals[0]) { s.SilentStop() }
}
m.signals = append(m.signals, s)
}
}
开发者ID:sideb0ard,项目名称:CMDSine,代码行数:19,代码来源:mixer.go
示例16: Start
func (e *Engine) Start() error {
stream, err := portaudio.OpenDefaultStream(0, 1, waveHz, nSamples, e.processAudio)
if err != nil {
return err
}
errc := make(chan error)
go func() {
err = stream.Start()
errc <- err
if err != nil {
return
}
<-e.done
err = stream.Stop()
if err == nil {
err = stream.Close()
}
e.done <- err
}()
return <-errc
}
开发者ID:nilslice,项目名称:sigourney,代码行数:21,代码来源:engine_cgo.go
示例17: player
func (pa *portAudio) player() {
out := make([]int16, 2048*2)
stream, err := portaudio.OpenDefaultStream(
0,
2, // audio.format.Channels,
44100, // float64(audio.format.SampleRate),
len(out),
&out,
)
if err != nil {
panic(err)
}
defer stream.Close()
stream.Start()
defer stream.Stop()
for {
// Decode the incoming data which is expected to be 2 channels and
// delivered as int16 in []byte, hence we need to convert it.
select {
case audio := <-pa.buffer:
if len(audio.frames) != 2048*2*2 {
// panic("unexpected")
// don't know if it's a panic or track just ended
break
}
j := 0
for i := 0; i < len(audio.frames); i += 2 {
out[j] = int16(audio.frames[i]) | int16(audio.frames[i+1])<<8
j++
}
stream.Write()
}
}
}
开发者ID:simonwoerpel,项目名称:sconsify,代码行数:40,代码来源:portaudio.go
示例18: 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
示例19: newMixer
func newMixer() (*mixer, error) {
m := &mixer{
stream: nil,
gain: 0.1, // TODO make mutable
incoming: make(chan (<-chan []float32)),
audio: make(chan chan []float32),
quit: make(chan chan struct{}),
}
stream, err := portaudio.OpenDefaultStream(iChan, oChan, sRate, bufSz, m)
if err != nil {
return nil, err
}
if err := stream.Start(); err != nil {
return nil, err
}
log.Printf("mixer: stream started")
m.stream = stream
go m.loop()
return m, nil
}
开发者ID:pablomelo,项目名称:gmd,代码行数:22,代码来源:mixer.go
示例20: Play
// Play is a blocking call which initializes the audio subsystem. It should
// be called on a separate goroutine. Calling Stop will trigger Play to
// return.
func (m *Mixer) Play() {
const (
ICHAN = 1
OCHAN = 1
)
m.mtx.Lock()
defer m.mtx.Unlock()
m.on = true
stream, err := portaudio.OpenDefaultStream(ICHAN, OCHAN, SRATE, BUFSZ, m)
if err != nil {
panic(fmt.Sprintf("open: %s", err))
}
defer stream.Close()
if err = stream.Start(); err != nil {
panic(fmt.Sprintf("start: %s", err))
}
m.cnd.Wait()
if err = stream.Stop(); err != nil {
panic(fmt.Sprintf("stop: %s", err))
}
m.on = false
m.cnd.Broadcast()
}
开发者ID:CrossTheStreams,项目名称:goop,代码行数:26,代码来源:mixer.go
注:本文中的code/google/com/p/portaudio-go/portaudio.OpenDefaultStream函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论