Beispiel #1
0
// Initialize initializes internal data structures and
// prepares underlying host APIs for use. With the exception
// of Version(), VersionText(), and ErrorText(), this function
// MUST be called before using any other PortAudio API functions.
//
// If Initialize() is called multiple times, each successful call
// must be matched with a corresponding call to Terminate(). Pairs of
// calls to Initialize()/Terminate() may overlap, and are not required to be fully nested.
//
// Note that if Initialize() returns an error code, Terminate() should NOT be called.
func Initialize() error {
	paErr := C.Pa_Initialize()
	if paErr != C.paNoError {
		return newError(paErr)
	}
	initialized++
	return nil
}
Beispiel #2
0
func setupAudioOutput(rate int, nChannels int, decoder *Decoder) unsafe.Pointer {
	if err := C.Pa_Initialize(); err != C.paNoError {
		fatalPAError(err)
	}
	env = &paEnv{
		decoder: decoder,
	}
	stream := C.pa_open_stream(C.int(nChannels), C.int(rate), unsafe.Pointer(env))
	if stream == nil {
		log.Fatal("pa open stream")
	}
	env.stream = stream
	return stream
}
Beispiel #3
0
/*
Opens the default input and/or output devices.

audioProcessor must have a method
	ProcessAudio(in, out [][]SampleType)
or
	ProcessAudio(in, out []SampleType)
where SampleType is float32, int32, Int24, int16, int8, or uint8.

In the former case, channels are non-interleaved:
len(in) == numInputChannels, len(out) == numOutputChannels,
and len(in[i]) == len(out[j]) == framesPerBuffer.

In the latter case, channels are interleaved:
len(in) == numInputChannels * framesPerBuffer and len(out) == numOutputChannels * framesPerBuffer.
*/
func OpenDefaultStream(numInputChannels, numOutputChannels int,
	sampleRate float64, framesPerBuffer int,
	audioProcessor interface{}) (*Stream, error) {
	paErr := C.Pa_Initialize()
	if paErr != C.paNoError {
		return nil, newError(paErr)
	}

	s := &Stream{}
	fmt, err := s.init(audioProcessor, numInputChannels, numOutputChannels)
	if err != nil {
		return nil, err
	}
	paErr = C.Pa_OpenDefaultStream(&s.paStream, C.int(numInputChannels), C.int(numOutputChannels), fmt, C.double(sampleRate), C.ulong(framesPerBuffer), C.getPaStreamCallback(), unsafe.Pointer(s))
	if paErr != C.paNoError {
		return nil, newError(paErr)
	}
	return s, nil
}
Beispiel #4
0
func Initialize() {
	err := C.Pa_Initialize()
	if err != C.paNoError {
		panic(C.Pa_GetErrorText(err))
	}
}
Beispiel #5
0
// Initialize function as declared in portaudio/portaudio.h:132
func Initialize() Error {
	__ret := C.Pa_Initialize()
	__v := (Error)(__ret)
	return __v
}