Пример #1
0
// returns (cvt, 0/1/-1) -- 0 means no conversion, 1 means filter is set up
func BuildAudioCVT(src_format AudioFormat, src_channels uint8, src_rate int,
	dst_format AudioFormat, dst_channels uint8, dst_rate int) (*AudioCVT, int) {
	var cvt C.SDL_AudioCVT
	ret := C.SDL_BuildAudioCVT(&cvt,
		C.SDL_AudioFormat(int(src_format)), C.Uint8(src_channels), C.int(src_rate),
		C.SDL_AudioFormat(int(dst_format)), C.Uint8(dst_channels), C.int(dst_rate))
	rcvt := &AudioCVT{&cvt, nil}
	return rcvt, int(ret)
}
Пример #2
0
func BuildAudioCVT(sf AudioFormat, sc uint8, sr int, df AudioFormat, dc uint8, dr int) (*AudioCVT, bool, error) {
	var cvt AudioCVT
	r := C.SDL_BuildAudioCVT(cvt.c(),
		C.SDL_AudioFormat(sf),
		C.Uint8(sc),
		C.int(sr),
		C.SDL_AudioFormat(df),
		C.Uint8(dc),
		C.int(dr),
	)
	switch r {
	case 0:
		return &cvt, false, nil
	case 1:
		return &cvt, true, nil
	}

	return nil, false, getError()
}
Пример #3
0
func MixAudioFormat(dst, src []byte, f AudioFormat, vol int) error {
	if len(dst) != len(src) {
		return errors.New("len(dst) != len(src)")
	}

	C.SDL_MixAudioFormat(
		(*C.Uint8)(unsafe.Pointer(&dst[0])),
		(*C.Uint8)(unsafe.Pointer(&src[0])),
		C.SDL_AudioFormat(f),
		C.Uint32(len(dst)),
		C.int(vol),
	)

	return nil
}
Пример #4
0
func OpenAudio(desired, obtained *AudioSpec, callback func(*byte, int)) bool {
	var cdesired C.SDL_AudioSpec
	var cobtained C.SDL_AudioSpec
	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_OpenAudio(&cdesired, &cobtained)
	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
}
Пример #5
0
func OpenAudio(desired, obtained_orNil *AudioSpec) int {
	var C_desired, C_obtained *C.SDL_AudioSpec

	C_desired = new(C.SDL_AudioSpec)
	C_desired.freq = C.int(desired.Freq)
	C_desired.format = C.SDL_AudioFormat(desired.Format)
	C_desired.channels = C.Uint8(desired.Channels)
	C_desired.samples = C.Uint16(desired.Samples)
	C_desired.callback = C.SDL_AudioCallback(C.callback_getCallback())

	if obtained_orNil != nil {
		if desired != obtained_orNil {
			C_obtained = new(C.SDL_AudioSpec)
		} else {
			C_obtained = C_desired
		}
	}

	status := C.SDL_OpenAudio(C_desired, C_obtained)

	if status == 0 {
		mutex.Lock()
		opened++
		mutex.Unlock()
	}

	if obtained_orNil != nil {
		obtained := obtained_orNil

		obtained.Freq = int(C_obtained.freq)
		obtained.Format = uint16(C_obtained.format)
		obtained.Channels = uint8(C_obtained.channels)
		obtained.Samples = uint16(C_obtained.samples)
		obtained.Out_Silence = uint8(C_obtained.silence)
		obtained.Out_Size = uint32(C_obtained.size)
	}

	return int(status)
}
Пример #6
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
}
Пример #7
0
func (fmt AudioFormat) c() C.SDL_AudioFormat {
	return C.SDL_AudioFormat(fmt)
}
Пример #8
0
func MixAudioFormat(dst, src []byte, format AudioFormat, volume int) {
	C.SDL_MixAudioFormat((*C.Uint8)(unsafe.Pointer(&dst[0])), (*C.Uint8)(unsafe.Pointer(&src[0])), C.SDL_AudioFormat(int(format)), C.Uint32(len(dst)), C.int(volume))
}