Exemple #1
0
// ConvertAudio (https://wiki.libsdl.org/SDL_ConvertAudio)
func ConvertAudio(cvt *AudioCVT) error {
	_cvt := (*C.SDL_AudioCVT)(unsafe.Pointer(cvt))
	if C.SDL_ConvertAudio(_cvt) != 0 {
		return GetError()
	}
	return nil
}
Exemple #2
0
func (cvt *AudioCVT) ConvertAudio() error {
	if C.SDL_ConvertAudio(cvt.c()) != 0 {
		return getError()
	}

	return nil
}
Exemple #3
0
func ConvertAudio(cvt *AudioCVT) bool {
	//var buf2 [uint(cvt.cAudioCVT.len) * uint(cvt.cAudioCVT.len_mult)]byte
	//cvt.Buf = buf2
	//cvt.cAudioCVT.buf = (*C.Uint8)(unsafe.Pointer(&cvt.Buf[0]))
	//	cvt.cAudioCVT.len = C.int(len(buf))
	ret := C.SDL_ConvertAudio(cvt.cAudioCVT)
	return int(ret) == 0
}
Exemple #4
0
// 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
}
Exemple #5
0
// ConvertAudio (https://wiki.libsdl.org/SDL_ConvertAudio)
func ConvertAudio(cvt *AudioCVT) int {
	_cvt := (*C.SDL_AudioCVT)(unsafe.Pointer(cvt))
	return int(C.SDL_ConvertAudio(_cvt))
}
Exemple #6
0
// Once you have initialized the 'cvt' structure using SDL_BuildAudioCVT(),
// created an audio buffer cvt->buf, and filled it with cvt->len bytes of
// audio data in the source format, this function will convert it in-place
// to the desired format.
// The data conversion may expand the size of the audio data, so the buffer
// cvt->buf should be allocated after the cvt structure is initialized by
// SDL_BuildAudioCVT(), and should be cvt->len*cvt->len_mult bytes long.
///
func ConvertAudio(cvt *C.SDL_AudioCVT) C.int {
	return C.SDL_ConvertAudio(cvt)
}