示例#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)))
		}
	}
}
示例#2
0
func (strm *Stream) WriteSound(sound []float32) error {
	cerr := C.Pa_WriteStream(strm.cee, unsafe.Pointer(&sound[0]),
		C.ulong(len(sound)/strm.outopts.ChannelCnt))
	if cerr != C.paNoError {
		return errors.New(C.GoString(C.Pa_GetErrorText(cerr)))
	}
	return nil
}
示例#3
0
// WriteStream function as declared in portaudio/portaudio.h:1122
func WriteStream(stream *Stream, buffer unsafe.Pointer, frames uint) Error {
	cstream, _ := (unsafe.Pointer)(unsafe.Pointer(stream)), cgoAllocsUnknown
	cbuffer, _ := (unsafe.Pointer)(unsafe.Pointer(buffer)), cgoAllocsUnknown
	cframes, _ := (C.ulong)(frames), cgoAllocsUnknown
	__ret := C.Pa_WriteStream(cstream, cbuffer, cframes)
	__v := (Error)(__ret)
	return __v
}
示例#4
0
// Write uses the buffer provided to OpenStream.
// The number of samples to write is determined by the size of the buffer.
func (s *Stream) Write() error {
	if s.callback.IsValid() {
		return CanNotWriteToACallbackStream
	}
	if s.out == nil {
		return CanNotWriteToAnInputOnlyStream
	}
	buf, frames, err := getBuffer(s.out, s.outParams)
	if err != nil {
		return err
	}
	return newError(C.Pa_WriteStream(s.paStream, buf, C.ulong(frames)))
}