func (t *Sound) Play(loops int) { t.channel = int(C.Mix_PlayChannelTimed(C.int(-1), t.chunk, C.int(loops), C.int(-1))) if t.channel == -1 { panic(fmt.Sprintf("Unable to play Sound file (%v): %v", t.name, util.GetMixError())) } t.SetVolume(GDefaultVolume) }
func (t *Sound) FadeIn(duration Double, loops int) { t.channel = int(C.Mix_FadeInChannelTimed(C.int(-1), t.chunk, C.int(loops), C.int(duration*1000.0), C.int(-1))) if t.channel == -1 { panic(fmt.Sprintf("Unable to FadeIn Sound file (%v): %v", t.name, util.GetMixError())) } t.SetVolume(GDefaultVolume) }
func loadSoundFromData(data []Double, sps int) *C.Mix_Chunk { bytes := util.CreateWavBytes(data, sps) rwop := C.SDL_RWFromConstMem(unsafe.Pointer(&bytes[0]), C.int(len(bytes))) chunk := C.Mix_LoadWAV_RW(rwop, 1) if chunk == nil { panic(fmt.Sprintf("Unable to load Sound data: %v", util.GetMixError())) } return chunk }
func loadMusic(name string) *Music { cname := C.CString(name) music := C.Mix_LoadMUS(cname) C.free(unsafe.Pointer(cname)) if music == nil { panic(fmt.Sprintf("Unable to load Music file (%v): %v", name, util.GetMixError())) } return New(name, music) }
func loadSound(name string) *C.Mix_Chunk { cfile, rb := C.CString(name), C.CString("rb") rwop := C.SDL_RWFromFile(cfile, rb) C.free(unsafe.Pointer(cfile)) C.free(unsafe.Pointer(rb)) chunk := C.Mix_LoadWAV_RW(rwop, 1) if chunk == nil { panic(fmt.Sprintf("Unable to load Sound file (%v): %v", name, util.GetMixError())) } return chunk }
func Init(initSDL, stereo bool, rate, nchannels, nbuffers int) { if initSDL { GSDLWasInitHere = true if C.SDL_Init(C.SDL_INIT_AUDIO) != 0 { panic(fmt.Sprintf("Unable to initialize SDL: %v\n", util.GetSdlError())) } } //initFlags := C.MIX_INIT_FLAC | C.MIX_INIT_MP3 | C.MIX_INIT_OGG //C.Mix_Init(initFlags) audio_format := C.AUDIO_S16SYS nstereo := 1 if stereo { nstereo = 2 } if C.Mix_OpenAudio(C.int(rate), C.Uint16(audio_format), C.int(nstereo), C.int(nbuffers)) != 0 { panic(fmt.Sprintf("Unable to initialize audio: %v\n", util.GetMixError())) } channel.Allocate(nchannels) }
func (t *Music) FadeInLoopsPos(duration float64, loops int, pos float64) { if C.Mix_FadeInMusicPos(t.mus, C.int(loops), C.int(duration*1000.0), C.double(pos)) == -1 { panic(fmt.Sprintf("Unable to FadeIn Music file (%v): %v", t.name, util.GetMixError())) } }
func (t *Music) PlayLoops(loops int) { if C.Mix_PlayMusic(t.mus, C.int(loops)) == -1 { panic(fmt.Sprintf("Unable to play Music file (%v): %v", t.name, util.GetMixError())) } }