Esempio n. 1
0
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)
}
Esempio n. 2
0
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)
}
Esempio n. 3
0
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
}
Esempio n. 4
0
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)
}
Esempio n. 5
0
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
}
Esempio n. 6
0
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)
}
Esempio n. 7
0
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()))
	}
}
Esempio n. 8
0
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()))
	}
}