Exemplo n.º 1
0
func lolwut() {
	runtime.LockOSThread()
	var stream unsafe.Pointer
	err := C.Pa_OpenDefaultStream(&stream,
		0,           // no input
		1,           // mono
		C.paFloat32, // 32-bit floating point
		48000,
		C.paFramesPerBufferUnspecified,
		nil,
		nil)
	if err != C.paNoError {
		panic(C.GoString(C.Pa_GetErrorText(err)))
	}
	err = C.Pa_StartStream(stream)
	if err != C.paNoError {
		panic(C.GoString(C.Pa_GetErrorText(err)))
	}
	for {
		err := C.Pa_WriteStream(stream, unsafe.Pointer(&genSine(440)[0]), 48000)
		if err != C.paNoError {
			panic(C.GoString(C.Pa_GetErrorText(err)))
		}
	}
}
Exemplo n.º 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
}
Exemplo n.º 3
0
func (strm *Stream) ReadSound(sound []float32) error {
	cerr := C.Pa_ReadStream(strm.cee, unsafe.Pointer(&sound[0]),
		C.ulong(len(sound)/strm.inopts.ChannelCnt))
	if cerr != C.paNoError {
		return errors.New(C.GoString(C.Pa_GetErrorText(cerr)))
	}
	return nil
}
Exemplo n.º 4
0
func (err Error) Error() string {
	return C.GoString(C.Pa_GetErrorText(C.PaError(err)))
}
Exemplo n.º 5
0
func Initialize() {
	err := C.Pa_Initialize()
	if err != C.paNoError {
		panic(C.Pa_GetErrorText(err))
	}
}
Exemplo n.º 6
0
Arquivo: ao.go Projeto: reusee/player
func fatalPAError(err C.PaError) {
	log.Fatal(C.GoString(C.Pa_GetErrorText(err)))
}
Exemplo n.º 7
0
func newError(err C.PaError) error {
	return errors.New(C.GoString(C.Pa_GetErrorText(err)))
}
Exemplo n.º 8
0
// GetErrorText function as declared in portaudio/portaudio.h:110
func GetErrorText(errorCode Error) string {
	cerrorCode, _ := (C.PaError)(errorCode), cgoAllocsUnknown
	__ret := C.Pa_GetErrorText(cerrorCode)
	__v := packPCharString(__ret)
	return __v
}