Example #1
1
func LoadWAV_RW(rw *RWops, free bool) (*AudioSpec, []byte, error) {
	var cfree C.int
	if free {
		cfree = 1
	}

	var a AudioSpec
	var h reflect.SliceHeader
	var l C.Uint32
	if C.SDL_LoadWAV_RW(rw.c, cfree, a.c(), (**C.Uint8)(unsafe.Pointer(&h.Data)), &l) == nil {
		return nil, nil, getError()
	}
	h.Len = int(l)
	h.Cap = int(l)

	return &a, *(*[]byte)(unsafe.Pointer(&h)), nil
}
Example #2
0
func LoadWAV(file string, spec *AudioSpec, audio_buf **uint8, audio_len *uint32) *AudioSpec {
	_file := (C.CString)(file)
	_spec := (*C.SDL_AudioSpec)(unsafe.Pointer(spec))
	_audio_buf := (**C.Uint8)(unsafe.Pointer(audio_buf))
	_audio_len := (*C.Uint32)(unsafe.Pointer(audio_len))
	return (*AudioSpec)(unsafe.Pointer(C.SDL_LoadWAV_RW(C.SDL_RWFromFile(_file, C.CString("rb")),
		1, _spec, _audio_buf, _audio_len)))
}
Example #3
0
func LoadWAV_RW(src *RWops, freesrc int, spec *AudioSpec, audio_buf **uint8, audio_len *uint32) *AudioSpec {
	_src := (*C.SDL_RWops)(unsafe.Pointer(src))
	_freesrc := (C.int)(freesrc)
	_spec := (*C.SDL_AudioSpec)(unsafe.Pointer(spec))
	_audio_buf := (**C.Uint8)(unsafe.Pointer(audio_buf))
	_audio_len := (*C.Uint32)(unsafe.Pointer(audio_len))
	return (*AudioSpec)(unsafe.Pointer(C.SDL_LoadWAV_RW(_src, _freesrc, _spec, _audio_buf, _audio_len)))
}
Example #4
0
// This function loads a WAVE from the data source, automatically freeing
// that source if 'freesrc' is non-zero.  For example, to load a WAVE file,
// you could do:
//	sdl.LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...);
//
// If this function succeeds, it returns the given SDL_AudioSpec,
// filled with the audio data format of the wave data, and sets
// 'audio_buf' to a malloc()'d buffer containing the audio data,
// and sets 'audio_len' to the length of that audio buffer, in bytes.
// You need to free the audio buffer with SDL_FreeWAV() when you are
// done with it.
//
// This function returns NULL and sets the SDL error message if the
// wave file cannot be opened, uses an unknown data format, or is
// corrupt.  Currently raw and MS-ADPCM WAVE files are supported.
func LoadWAVE_RW(src *C.SDL_RWops, freesrc bool, spec *C.SDL_AudioSpec,
	audio_buf **C.Uint8, audio_len *C.Uint32) *C.SDL_AudioSpec {
	free_src := C.int(0)
	if freesrc {
		free_src = C.int(1)
	}
	return C.SDL_LoadWAV_RW(src, free_src, spec, audio_buf, audio_len)
}
Example #5
0
// LoadWAV (https://wiki.libsdl.org/SDL_LoadWAV)
func LoadWAV(file string, spec *AudioSpec, audioBuf **uint8, audioLen *uint32) *AudioSpec {
	_file := C.CString(file)
	_rb := C.CString("rb")
	defer C.free(unsafe.Pointer(_file))
	defer C.free(unsafe.Pointer(_rb))
	_audioBuf := (**C.Uint8)(unsafe.Pointer(audioBuf))
	_audioLen := (*C.Uint32)(unsafe.Pointer(audioLen))
	return (*AudioSpec)(unsafe.Pointer(C.SDL_LoadWAV_RW(C.SDL_RWFromFile(_file, _rb), 1, spec.cptr(), _audioBuf, _audioLen)))
}
Example #6
0
// LoadWAV_RW (https://wiki.libsdl.org/SDL_LoadWAV_RW)
func LoadWAV_RW(src *RWops, freeSrc int, spec *AudioSpec) ([]byte, *AudioSpec) {
	var _audioBuf *C.Uint8
	var _audioLen C.Uint32
	audioSpec := (*AudioSpec)(unsafe.Pointer(C.SDL_LoadWAV_RW(src.cptr(), C.int(freeSrc), spec.cptr(), &_audioBuf, &_audioLen)))

	var b []byte
	sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
	sliceHeader.Len = (int)(_audioLen)
	sliceHeader.Cap = (int)(_audioLen)
	sliceHeader.Data = uintptr(unsafe.Pointer(_audioBuf))
	return b, audioSpec
}
Example #7
0
// LoadWAV (https://wiki.libsdl.org/SDL_LoadWAV)
func LoadWAV(file string, spec *AudioSpec) ([]byte, *AudioSpec) {
	_file := C.CString(file)
	_rb := C.CString("rb")
	defer C.free(unsafe.Pointer(_file))
	defer C.free(unsafe.Pointer(_rb))

	var _audioBuf *C.Uint8
	var _audioLen C.Uint32
	audioSpec := (*AudioSpec)(unsafe.Pointer(C.SDL_LoadWAV_RW(C.SDL_RWFromFile(_file, _rb), 1, spec.cptr(), &_audioBuf, &_audioLen)))

	var b []byte
	sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
	sliceHeader.Len = (int)(_audioLen)
	sliceHeader.Cap = (int)(_audioLen)
	sliceHeader.Data = uintptr(unsafe.Pointer(_audioBuf))
	return b, audioSpec
}
Example #8
0
File: audio.go Project: velour/ui
func loadWAV(path string) (*audioData, error) {
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	var data *C.Uint8
	var len C.Uint32
	var s C.SDL_AudioSpec // Apparently just a buffer?  SDL just zeroes it, fills it, and returns it.
	spec := C.SDL_LoadWAV_RW(C.SDL_RWFromFile(cpath, rb), 1, &s, &data, &len)
	if spec == nil {
		return nil, sdlError()
	}

	var err error
	data, len, err = convert(spec, data, len)
	if err != nil {
		return nil, err
	}

	return &audioData{
		path: path,
		data: unsafe.Pointer(data),
		len:  uintptr(len),
	}, nil
}
Example #9
0
// LoadWAV_RW (https://wiki.libsdl.org/SDL_LoadWAV_RW)
func LoadWAV_RW(src *RWops, freeSrc int, spec *AudioSpec, audioBuf **uint8, audioLen *uint32) *AudioSpec {
	_audioBuf := (**C.Uint8)(unsafe.Pointer(audioBuf))
	_audioLen := (*C.Uint32)(unsafe.Pointer(audioLen))
	return (*AudioSpec)(unsafe.Pointer(C.SDL_LoadWAV_RW(src.cptr(), C.int(freeSrc), spec.cptr(), _audioBuf, _audioLen)))
}