Exemplo n.º 1
0
// OpenStream creates an instance of a Stream.
//
// 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 {
		delStream(s)
		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.id))
	if paErr != C.paNoError {
		delStream(s)
		return nil, newError(paErr)
	}
	return s, nil
}
Exemplo n.º 2
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
	}

	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
}