Exemple #1
0
// DefaultInputDevice returns information for the default
// input device on the system.
func DefaultInputDevice() (*DeviceInfo, error) {
	devs, err := Devices()
	if err != nil {
		return nil, err
	}
	i := C.Pa_GetDefaultInputDevice()
	if i < 0 {
		return nil, newError(C.PaError(i))
	}
	return devs[i], nil
}
Exemple #2
0
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
}
Exemple #3
0
// GetDefaultInputDevice function as declared in portaudio/portaudio.h:380
func GetDefaultInputDevice() DeviceIndex {
	__ret := C.Pa_GetDefaultInputDevice()
	__v := (DeviceIndex)(__ret)
	return __v
}