func (m Meter) OpenStream() *Stream { var p portaudio.StreamParameters p = portaudio.LowLatencyParameters(m.Fast["i"].Dev[0].DevInfo, m.Fast["o"].Dev[0].DevInfo) numSamples := 256 p.FramesPerBuffer = numSamples // It *might* be better to leave this unspecified. p.Input.Channels = 1 p.Output.Channels = 1 osxWarningText := `OS X 10.11 portaudio known issue (you can safely ignore the following WARNING): https://www.assembla.com/spaces/portaudio/tickets/243-portaudio-support-for-os-x-10-11-el-capitan https://lists.columbia.edu/pipermail/portaudio/2015-October/000092.html ` if runtime.GOOS == "darwin" { out, err := exec.Command("sw_vers", "-productVersion").Output() if err != nil { fmt.Printf("sw_vers -productVersion failed to get OS X version: %v\n", err) } else { ver := strings.Split(string(out), ".") if ver[0] == "10" && ver[1] == "11" { fmt.Printf("%s", osxWarningText) } } } s := &Stream{} var err error if s.Stream, err = portaudio.OpenStream(p, s.process); err != nil { fmt.Printf("portaudio.OpenStream failed: ", err) panic(err) } if err = s.Start(); err != nil { fmt.Printf("portaudio.Stream.Start failed: ", err) panic(err) } return s }
func newEcho(delay time.Duration) *echo { h, err := portaudio.DefaultHostApi() chk(err) p := portaudio.LowLatencyParameters(h.DefaultInputDevice, h.DefaultOutputDevice) p.Input.Channels = 1 p.Output.Channels = 1 e := &echo{buffer: make([]float32, int(p.SampleRate*delay.Seconds()))} e.Stream, err = portaudio.OpenStream(p, e.processAudio) chk(err) return e }
func (m Meter) OpenStream() *Stream { var p portaudio.StreamParameters p = portaudio.LowLatencyParameters(m.Fast["i"].Dev[0].DevInfo, m.Fast["o"].Dev[0].DevInfo) numSamples := SAMPLES p.FramesPerBuffer = numSamples // It *might* be better to leave this unspecified. p.Input.Channels = 1 p.Output.Channels = 1 osxWarningText := `OS X 10.11 portaudio known issue (you can safely ignore the following WARNING): https://www.assembla.com/spaces/portaudio/tickets/243-portaudio-support-for-os-x-10-11-el-capitan https://lists.columbia.edu/pipermail/portaudio/2015-October/000092.html ` if runtime.GOOS == "darwin" { out, err := exec.Command("sw_vers", "-productVersion").Output() if err != nil { fmt.Printf("sw_vers -productVersion failed to get OS X version: %v\n", err) } else { ver := strings.Split(string(out), ".") if ver[0] == "10" && ver[1] == "11" { fmt.Printf("%s", osxWarningText) } } } s := &Stream{} var err error if s.Stream, err = portaudio.OpenStream(p, s.process); err != nil { fmt.Printf("portaudio.OpenStream failed: %v", err) panic(err) } fmt.Printf("sample rate: %g Hz\n", s.Stream.Info().SampleRate) var noiseprev int32 for i := range s.noise { v := int32(rand.Uint32()) >> 1 noiseprev = noiseprev - noiseprev>>FILTER_FREQ_BITS + v>>FILTER_FREQ_BITS s.noise[i] = v - noiseprev } for i := range s.fir { sinci := float64(i-len(s.fir)/2) * math.Pi / (FILTER_FREQ * 4) sinc := float64(1) if sinci != 0 { sinc = math.Sin(sinci) / sinci } wingain := 4.0 / FILTER_FREQ hammingwin := math.Sin(float64(i+len(s.fir)/2) * math.Pi / (FIR_NUM_TAPS * 2)) s.fir[i] = int32(wingain * hammingwin * sinc * float64(1<<32)) } if err = s.Start(); err != nil { fmt.Printf("portaudio.Stream.Start failed: %v", err) panic(err) } return s }
func openStream(cbk interface{}) (*portaudio.Stream, error) { outDev, err := portaudio.DefaultOutputDevice() if err != nil { return nil, err } p := portaudio.LowLatencyParameters(nil, outDev) p.Input.Channels = 0 p.Output.Channels = 2 p.SampleRate = sampleRate p.FramesPerBuffer = 0 return portaudio.OpenStream(p, cbk) }