Exemple #1
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 #2
0
func hostsAndDevices() ([]*HostApiInfo, []*DeviceInfo, error) {
	if !cached {
		nhosts := C.Pa_GetHostApiCount()
		ndevs := C.Pa_GetDeviceCount()
		if nhosts < 0 {
			return nil, nil, newError(C.PaError(nhosts))
		}
		if ndevs < 0 {
			return nil, nil, newError(C.PaError(ndevs))
		}
		devices = make([]*DeviceInfo, ndevs)
		hosti := make([]C.PaHostApiIndex, ndevs)
		for i := range devices {
			i := C.PaDeviceIndex(i)
			paDev := C.Pa_GetDeviceInfo(i)
			devices[i] = &DeviceInfo{
				index:                    i,
				Name:                     C.GoString(paDev.name),
				MaxInputChannels:         int(paDev.maxInputChannels),
				MaxOutputChannels:        int(paDev.maxOutputChannels),
				DefaultLowInputLatency:   duration(paDev.defaultLowInputLatency),
				DefaultLowOutputLatency:  duration(paDev.defaultLowOutputLatency),
				DefaultHighInputLatency:  duration(paDev.defaultHighInputLatency),
				DefaultHighOutputLatency: duration(paDev.defaultHighOutputLatency),
				DefaultSampleRate:        float64(paDev.defaultSampleRate),
			}
			hosti[i] = paDev.hostApi
		}
		hostApis = make([]*HostApiInfo, nhosts)
		for i := range hostApis {
			i := C.PaHostApiIndex(i)
			paHost := C.Pa_GetHostApiInfo(i)
			devs := make([]*DeviceInfo, paHost.deviceCount)
			for j := range devs {
				devs[j] = devices[C.Pa_HostApiDeviceIndexToDeviceIndex(i, C.int(j))]
			}
			hostApis[i] = &HostApiInfo{
				Type:                HostApiType(paHost._type),
				Name:                C.GoString(paHost.name),
				DefaultInputDevice:  lookupDevice(devices, paHost.defaultInputDevice),
				DefaultOutputDevice: lookupDevice(devices, paHost.defaultOutputDevice),
				Devices:             devs,
			}
		}
		for i := range devices {
			devices[i].HostApi = hostApis[hosti[i]]
		}
		cached = true
	}
	return hostApis, devices, nil
}
Exemple #3
0
// GetDeviceInfo function as declared in portaudio/portaudio.h:482
func GetDeviceInfo(device DeviceIndex) *DeviceInfo {
	cdevice, _ := (C.PaDeviceIndex)(device), cgoAllocsUnknown
	__ret := C.Pa_GetDeviceInfo(cdevice)
	__v := NewDeviceInfoRef(unsafe.Pointer(__ret))
	return __v
}