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 }
// AvailableToWrite returns the number of frames that // can be written from the stream without waiting. func (s *Stream) AvailableToWrite() (int, error) { n := C.Pa_GetStreamWriteAvailable(s.paStream) if n < 0 { return 0, newError(C.PaError(n)) } return int(n), nil }
// DefaultOutputDevice returns information for the default // output device on the system. func DefaultOutputDevice() (*DeviceInfo, error) { devs, err := Devices() if err != nil { return nil, err } i := C.Pa_GetDefaultOutputDevice() if i < 0 { return nil, newError(C.PaError(i)) } return devs[i], nil }
// DefaultHostApi returns information of the default HostApi available on the system. // // The default host API will be the lowest common denominator host API // on the current platform and is unlikely to provide the best performance. func DefaultHostApi() (*HostApiInfo, error) { hosts, err := HostApis() if err != nil { return nil, err } i := C.Pa_GetDefaultHostApi() if i < 0 { return nil, newError(C.PaError(i)) } return hosts[i], nil }
// HostApi returns information for a requested HostApiType. func HostApi(apiType HostApiType) (*HostApiInfo, error) { hosts, err := HostApis() if err != nil { return nil, err } i := C.Pa_HostApiTypeIdToHostApiIndex(C.PaHostApiTypeId(apiType)) if i < 0 { return nil, newError(C.PaError(i)) } return hosts[i], nil }
func (err Error) Error() string { return C.GoString(C.Pa_GetErrorText(C.PaError(err))) }