Esempio n. 1
0
// This function takes a source format and rate and a destination format
// and rate, and initializes the 'cvt' structure with information needed
// by SDL_ConvertAudio() to convert a buffer of audio data from one format
// to the other.
// This function returns 0, or -1 if there was an error.
func BuildAudioCVT(cvt *C.SDL_AudioCVT,
	src_format C.Uint16, src_channels C.Uint8, src_rate C.int,
	dst_format C.Uint16, dst_channels C.Uint8, dst_rate C.int) C.int {
	return C.SDL_BuildAudioCVT(cvt, src_format, src_channels, src_rate,
		dst_format, dst_channels, dst_rate)

}
Esempio n. 2
0
// BuildAudioCVT (https://wiki.libsdl.org/SDL_BuildAudioCVT)
func BuildAudioCVT(cvt *AudioCVT, srcFormat AudioFormat, srcChannels uint8, srcRate int, dstFormat AudioFormat, dstChannels uint8, dstRate int) (converted bool, err error) {
	switch int(C.SDL_BuildAudioCVT(cvt.cptr(), srcFormat.c(), C.Uint8(srcChannels), C.int(srcRate), dstFormat.c(), C.Uint8(dstChannels), C.int(dstRate))) {
	case 1:
		return true, nil
	case 0:
		return false, nil
	}
	return false, GetError()
}
Esempio n. 3
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)
}
Esempio n. 4
0
func BuildAudioCVT(cvt *AudioCVT, src_format AudioFormat, src_channels uint8, src_rate int,
	dst_format AudioFormat, dst_channels uint8, dst_rate int) int {
	_cvt := (*C.SDL_AudioCVT)(unsafe.Pointer(cvt))
	_src_format := (C.SDL_AudioFormat)(src_format)
	_src_channels := (C.Uint8)(src_channels)
	_src_rate := (C.int)(src_rate)
	_dst_format := (C.SDL_AudioFormat)(dst_format)
	_dst_channels := (C.Uint8)(dst_channels)
	_dst_rate := (C.int)(dst_rate)
	return (int)(C.SDL_BuildAudioCVT(_cvt, _src_format, _src_channels, _src_rate,
		_dst_format, _dst_channels, _dst_rate))
}
Esempio n. 5
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()
}
Esempio n. 6
0
File: audio.go Progetto: velour/ui
// Convert converts audio to the opened audio spec, returning the data and it's length.
func convert(s *C.SDL_AudioSpec, data *C.Uint8, len C.Uint32) (*C.Uint8, C.Uint32, error) {
	var cvt C.SDL_AudioCVT
	o := openedSpec
	switch C.SDL_BuildAudioCVT(&cvt, s.format, s.channels, s.freq, o.format, o.channels, o.freq) {
	case -1:
		return nil, 0, errors.New("Cannot convert audio")
	case 0:
		return data, len, nil
	}

	buf := C.malloc(C.size_t(len) * C.size_t(cvt.len_mult))
	cvt.buf = (*C.Uint8)(buf)
	cvt.len = C.int(len)
	C.memcpy(buf, unsafe.Pointer(data), C.size_t(len))
	C.free(unsafe.Pointer(data))

	if C.SDL_ConvertAudio(&cvt) < 0 {
		return nil, 0, sdlError()
	}
	return cvt.buf, C.Uint32(cvt.len), nil
}
Esempio n. 7
0
// BuildAudioCVT (https://wiki.libsdl.org/SDL_BuildAudioCVT)
func BuildAudioCVT(cvt *AudioCVT, srcFormat AudioFormat, srcChannels uint8, srcRate int, dstFormat AudioFormat, dstChannels uint8, dstRate int) int {
	return int(C.SDL_BuildAudioCVT(cvt.cptr(), srcFormat.c(), C.Uint8(srcChannels), C.int(srcRate), dstFormat.c(), C.Uint8(dstChannels), C.int(dstRate)))
}