func initAudio() { // Init a simple audio setup. var spec C.SDL_AudioSpec spec.freq = C.int(SamplingRate) spec.format = C.AUDIO_S8 spec.channels = 1 spec.samples = 512 spec.userdata = nil C.openAudio(&spec) }
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 }
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 }