本文整理匯總了Golang中code/google/com/p/portaudio-go/portaudio.OpenDefaultStream函數的典型用法代碼示例。如果您正苦於以下問題:Golang OpenDefaultStream函數的具體用法?Golang OpenDefaultStream怎麽用?Golang OpenDefaultStream使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了OpenDefaultStream函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例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
}
示例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
}
示例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)
}
}
示例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:
}
}
}
示例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()
}
示例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
}
示例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
}
示例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())
}
}
示例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())
}
示例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())
}
示例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())
}
示例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()
}
示例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: 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)
}
}