コード例 #1
0
ファイル: lolwut.go プロジェクト: quantum1423/tavla
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)))
		}
	}
}
コード例 #2
0
ファイル: portaudio.go プロジェクト: xlab/portaudio-go
// OpenDefaultStream function as declared in portaudio/portaudio.h:881
func OpenDefaultStream(stream **Stream, numInputChannels int32, numOutputChannels int32, sampleFormat SampleFormat, sampleRate float64, framesPerBuffer uint, streamCallback StreamCallback, userData unsafe.Pointer) Error {
	cstream, _ := (*unsafe.Pointer)(unsafe.Pointer(stream)), cgoAllocsUnknown
	cnumInputChannels, _ := (C.int)(numInputChannels), cgoAllocsUnknown
	cnumOutputChannels, _ := (C.int)(numOutputChannels), cgoAllocsUnknown
	csampleFormat, _ := (C.PaSampleFormat)(sampleFormat), cgoAllocsUnknown
	csampleRate, _ := (C.double)(sampleRate), cgoAllocsUnknown
	cframesPerBuffer, _ := (C.ulong)(framesPerBuffer), cgoAllocsUnknown
	cstreamCallback, _ := streamCallback.PassRef()
	cuserData, _ := (unsafe.Pointer)(unsafe.Pointer(userData)), cgoAllocsUnknown
	__ret := C.Pa_OpenDefaultStream(cstream, cnumInputChannels, cnumOutputChannels, csampleFormat, csampleRate, cframesPerBuffer, cstreamCallback, cuserData)
	__v := (Error)(__ret)
	return __v
}
コード例 #3
0
ファイル: portaudio.go プロジェクト: ptrr/portaudio-go
/*
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
}