Ejemplo n.º 1
0
func OpenAudioDevice(device string, iscapture int, desired, obtained *AudioSpec, allowed_changes int) int {
	_device := (C.CString)(device)
	_iscapture := (C.int)(iscapture)
	_desired := (*C.SDL_AudioSpec)(unsafe.Pointer(desired))
	_obtained := (*C.SDL_AudioSpec)(unsafe.Pointer(obtained))
	_allowed_changes := (C.int)(allowed_changes)
	return (int)(C.SDL_OpenAudioDevice(_device, _iscapture, _desired, _obtained, _allowed_changes))
}
Ejemplo n.º 2
0
// OpenAudioDevice (https://wiki.libsdl.org/SDL_OpenAudioDevice)
func OpenAudioDevice(device string, isCapture bool, desired, obtained *AudioSpec, allowedChanges int) (AudioDeviceID, error) {
	_device := C.CString(device)
	if device == "" {
		_device = nil
	}
	defer C.free(unsafe.Pointer(_device))
	if id := AudioDeviceID(C.SDL_OpenAudioDevice(_device, C.int(Btoi(isCapture)), desired.cptr(), obtained.cptr(), C.int(allowedChanges))); id > 0 {
		return id, nil
	}
	return 0, GetError()
}
Ejemplo n.º 3
0
func Init() {
	if ok := C.SDL_InitSubSystem(C.SDL_INIT_AUDIO); ok < 0 {
		panic(ok)
	}
	var want C.SDL_AudioSpec
	want.freq = 48000
	want.format = C.AUDIO_S16
	want.channels = 2
	want.callback = (C.SDL_AudioCallback)(unsafe.Pointer(C.audio_callback_go_cgo))
	var have C.SDL_AudioSpec
	if dev = C.SDL_OpenAudioDevice(nil, 0, &want, &have, 0); dev == 0 {
		panic("dev=0")
	}
}
Ejemplo n.º 4
0
func OpenAudioDevice(dev string, ic bool, des *AudioSpec, ac bool) (AudioDeviceID, *AudioSpec, error) {
	cdev := C.CString(dev)
	defer C.free(unsafe.Pointer(cdev))

	var cic C.int
	if ic {
		cic = 1
	}

	var cac C.int
	if ac {
		cac = 1
	}

	var o AudioSpec
	id := C.SDL_OpenAudioDevice(cdev, cic, des.c(), o.c(), cac)
	if id == 0 {
		return 0, nil, getError()
	}

	return AudioDeviceID(id), &o, nil
}
Ejemplo n.º 5
0
func OpenAudioDevice(device string, iscapture bool, desired, obtained *AudioSpec, allowed_changes bool, callback func(*byte, int)) bool {
	var cdesired C.SDL_AudioSpec
	var cobtained C.SDL_AudioSpec
	cdevice := C.CString(device)
	defer C.free(unsafe.Pointer(cdevice))
	cdesired.freq = C.int(desired.Freq)
	cdesired.format = C.SDL_AudioFormat(int(desired.Format))
	cdesired.channels = C.Uint8(desired.Channels)
	cdesired.samples = C.Uint16(desired.Samples)
	cdesired.size = C.Uint32(0)
	cdesired.callback = C.go_sdl2_get_callback()
	cdesired.userdata = unsafe.Pointer(&callback)
	ret := C.SDL_OpenAudioDevice(cdevice, C.int(bool2int(iscapture)), &cdesired, &cobtained, C.int(bool2int(allowed_changes)))
	if obtained != nil {
		obtained.Freq = int32(cobtained.freq)
		obtained.Format = AudioFormat(int(cobtained.format))
		obtained.Channels = uint8(cobtained.channels)
		obtained.Silence = uint8(cobtained.silence)
		obtained.Samples = uint16(cobtained.samples)
		obtained.Size = uint32(cobtained.size)
	}
	return int(ret) == 0
}
Ejemplo n.º 6
0
// OpenAudioDevice (https://wiki.libsdl.org/SDL_OpenAudioDevice)
func OpenAudioDevice(device string, isCapture int, desired, obtained *AudioSpec, allowedChanges int) int {
	_device := C.CString(device)
	defer C.free(unsafe.Pointer(_device))
	return int(C.SDL_OpenAudioDevice(_device, C.int(isCapture), desired.cptr(), obtained.cptr(), C.int(allowedChanges)))
}