コード例 #1
0
/*
For an input- or output-only stream, p.Output.Device or p.Input.Device must be nil, respectively.

The args may consist of either a single StreamCallback or, for a blocking stream, two Buffers or pointers to Buffers.  For an input- or output-only stream, one of the Buffer args may be omitted.
*/
func OpenStream(p StreamParameters, args ...interface{}) (*Stream, error) {
	if initialized <= 0 {
		return nil, NotInitialized
	}

	s := NewStream()
	err := s.init(p, args...)
	if err != nil {
		return nil, err
	}
	cb := C.paStreamCallback
	if !s.callback.IsValid() {
		cb = nil
	}

	mu.Lock()
	id := s.id
	idToStream[s.id] = s
	mu.Unlock()
	paErr := C.Pa_OpenStream(&s.paStream, s.inParams, s.outParams, C.double(p.SampleRate), C.ulong(p.FramesPerBuffer), C.PaStreamFlags(p.Flags), cb, unsafe.Pointer(id))
	if paErr != C.paNoError {
		return nil, newError(paErr)
	}
	return s, nil
}
コード例 #2
0
ファイル: Stream.go プロジェクト: quantum1423/tavla
func OpenStream(inOpts *InputOptions,
	outOpts *OutputOptions,
	sampleRate float64) (strm *Stream, err error) {
	// initialize return value first
	strm = new(Stream)
	strm.inopts = inOpts
	strm.outopts = outOpts
	// initialize in and out
	var _inopts *C.PaStreamParameters
	var _outopts *C.PaStreamParameters
	if inOpts != nil {
		_inopts = new(C.PaStreamParameters)
		_inopts.device = C.Pa_GetDefaultInputDevice()
		if inOpts.DeviceID != DefaultDevice {
			_inopts.device = C.PaDeviceIndex(inOpts.DeviceID)
		}
		_inopts.channelCount = C.int(inOpts.ChannelCnt)
		_inopts.sampleFormat = C.paFloat32
		_inopts.suggestedLatency = C.Pa_GetDeviceInfo(_inopts.device).defaultHighInputLatency
		_inopts.hostApiSpecificStreamInfo = nil
	}
	if outOpts != nil {
		_outopts = new(C.PaStreamParameters)
		_outopts.device = C.Pa_GetDefaultOutputDevice()
		if outOpts.DeviceID != DefaultDevice {
			_outopts.device = C.PaDeviceIndex(outOpts.DeviceID)
		}
		_outopts.channelCount = C.int(outOpts.ChannelCnt)
		_outopts.sampleFormat = C.paFloat32
		_outopts.suggestedLatency = C.Pa_GetDeviceInfo(_outopts.device).defaultHighOutputLatency
		_outopts.hostApiSpecificStreamInfo = nil
	}
	cerr := C.Pa_OpenStream(
		&strm.cee,
		_inopts,
		_outopts,
		C.double(sampleRate),
		C.paClipOff,
		0,
		nil,
		nil,
	)
	if cerr != C.paNoError {
		err = errors.New(C.GoString(C.Pa_GetErrorText(cerr)))
		return
	}
	cerr = C.Pa_StartStream(strm.cee)
	if cerr != C.paNoError {
		err = errors.New(C.GoString(C.Pa_GetErrorText(cerr)))
		return
	}
	return
}
コード例 #3
0
ファイル: portaudio.go プロジェクト: xlab/portaudio-go
// OpenStream function as declared in portaudio/portaudio.h:841
func OpenStream(stream **Stream, inputParameters *StreamParameters, outputParameters *StreamParameters, sampleRate float64, framesPerBuffer uint, streamFlags StreamFlags, streamCallback StreamCallback, userData unsafe.Pointer) Error {
	cstream, _ := (*unsafe.Pointer)(unsafe.Pointer(stream)), cgoAllocsUnknown
	cinputParameters, _ := inputParameters.PassRef()
	coutputParameters, _ := outputParameters.PassRef()
	csampleRate, _ := (C.double)(sampleRate), cgoAllocsUnknown
	cframesPerBuffer, _ := (C.ulong)(framesPerBuffer), cgoAllocsUnknown
	cstreamFlags, _ := (C.PaStreamFlags)(streamFlags), cgoAllocsUnknown
	cstreamCallback, _ := streamCallback.PassRef()
	cuserData, _ := (unsafe.Pointer)(unsafe.Pointer(userData)), cgoAllocsUnknown
	__ret := C.Pa_OpenStream(cstream, cinputParameters, coutputParameters, csampleRate, cframesPerBuffer, cstreamFlags, cstreamCallback, cuserData)
	__v := (Error)(__ret)
	return __v
}
コード例 #4
0
ファイル: portaudio.go プロジェクト: Orion90/portaudio
/*
For an input- or output-only stream, p.Output.Device or p.Input.Device must be nil, respectively.

The args may consist of either a single StreamCallback or, for a blocking stream, two Buffers or pointers to Buffers.  For an input- or output-only stream, one of the Buffer args may be omitted.
*/
func OpenStream(p StreamParameters, args ...interface{}) (*Stream, error) {
	if initialized <= 0 {
		return nil, NotInitialized
	}

	stream_size := (C.size_t)(unsafe.Sizeof(Stream{}))
	s := (*Stream)(C.malloc(stream_size))
	*s = Stream{}
	err := s.init(p, args...)
	if err != nil {
		return nil, err
	}
	cb := C.paStreamCallback
	if !s.callback.IsValid() {
		cb = nil
	}
	paErr := C.Pa_OpenStream(&s.paStream, s.inParams, s.outParams, C.double(p.SampleRate), C.ulong(p.FramesPerBuffer), C.PaStreamFlags(p.Flags), cb, unsafe.Pointer(s))
	if paErr != C.paNoError {
		return nil, newError(paErr)
	}
	return s, nil
}