Beispiel #1
0
// 終了処理を行う
void Game::Finalize(void) {
    // 解放する
    SDL_FreeSurface(block_image);
    SDL_FreeSurface(section_image);
    SDL_FreeSurface(section_image_02);
    SDL_FreeSurface(particle_image);
    TTF_CloseFont(font);
    TTF_CloseFont(big_font);
    Mix_FreeMusic(music_main);
    
    // 終了する
    TTF_Quit();
    Mix_CloseAudio();
    SDL_Quit();
}
Beispiel #2
0
bool Music::load()
{
    if (!SDLManager::hasAudio()) return false;

	if (this->music) Mix_FreeMusic(this->music);

    this->music = Mix_LoadMUS(this->filepath.c_str());
    if (!this->music)
    {
        SDLManager::errorLog("Music::load: Couldn't load music on " + this->filepath);
        return false;
    }

    return true;
}
Beispiel #3
0
void noegnud_sound_done() {
    noegnud_tcollection *sound;

    if (!noegnud_sound_initialised) return;

    sound=noegnud_sounds;
    while (sound) {
	if (((noegnud_sound_tsound *)(sound->data))->chunk) Mix_FreeChunk(((noegnud_sound_tsound *)(sound->data))->chunk);
	if (((noegnud_sound_tsound *)(sound->data))->music) Mix_FreeMusic(((noegnud_sound_tsound *)(sound->data))->music);
	noegnud_mem_free(sound->data);
	sound=sound->next;
    }
    noegnud_collection_destroy(&noegnud_sounds);
    noegnud_sounds=NULL;
}
Beispiel #4
0
        void Tela::clean_up() {
            
            //Libera todas as superficies da memoria
            SDL_FreeSurface( telaInicial );
            SDL_FreeSurface( telaIdentificacao );
            SDL_FreeSurface( telaInstrucoes );
            SDL_FreeSurface( telaConfigSound_ON );
            SDL_FreeSurface( telaConfigSound_OFF );
            SDL_FreeSurface( telaLevelUp );
            SDL_FreeSurface( telaGameOver );
            SDL_FreeSurface( gems );
            SDL_FreeSurface( gems_dica );
            SDL_FreeSurface( screen );
            SDL_FreeSurface( fundo );
            SDL_FreeSurface( nomeJogador );
            SDL_FreeSurface( pontosJogador );
            SDL_FreeSurface( gemYellow );
            SDL_FreeSurface( gemWhite );
            SDL_FreeSurface( gemBlue );
            SDL_FreeSurface( gemRed );
            SDL_FreeSurface( gemPurple );
            SDL_FreeSurface( gemOrange );
            SDL_FreeSurface( gemGreen );
            SDL_FreeSurface( fase1 );
            SDL_FreeSurface( fase2 );
            SDL_FreeSurface( fase3 );
            SDL_FreeSurface( fase4 );
            SDL_FreeSurface( hint );

            //Libera ficheiro de audio da memoria
            Mix_FreeMusic(music);

            //Encerra SDL_mixer
            Mix_CloseAudio();

            //Fecha a fonte que foi usada
            TTF_CloseFont( font );

            //Encerra SDL_ttf
            TTF_Quit();

            //Encerra SDL
            SDL_Quit();

            //Libera objetos que foram alocados dinamicamente anteriormente
            delete pontos;
            delete user;
        }
Beispiel #5
0
Graphics::~Graphics() {
	Mix_FreeMusic(backgroundMusic);
	Mix_FreeChunk(soundEffect1);
	Mix_FreeChunk(soundEffect2);
	this->backgroundMusic = NULL;
	this->soundEffect1 = NULL;
	this->soundEffect2 = NULL;


	SDL_DestroyWindow(window);
	SDL_DestroyTexture(backgroundImage);
	SDL_DestroyTexture(border);
	SDL_DestroyTexture(snakeBody);
	SDL_DestroyTexture(snakeHeadDown);
	SDL_DestroyTexture(snakeHeadLeft);
	SDL_DestroyTexture(snakeHeadRight);
	SDL_DestroyTexture(snakeHeadUp);
	SDL_DestroyTexture(snakeTail);
	SDL_DestroyTexture(apple);
	SDL_DestroyTexture(banana);
	SDL_DestroyTexture(bomb);
	SDL_DestroyTexture(text);
	SDL_DestroyTexture(playerNameText);
	SDL_DestroyTexture(scoreText);
	SDL_DestroyTexture(currentScore);
	SDL_DestroyRenderer(renderTarget);
	this->window = NULL;
	this->backgroundImage = NULL;
	this->border = NULL;
	this->snakeBody = NULL;
	this->snakeHeadDown = NULL;
	this->snakeHeadLeft = NULL;
	this->snakeHeadRight = NULL;
	this->snakeHeadUp = NULL;
	this->snakeTail = NULL;
	this->apple = NULL;
	this->banana = NULL;
	this->bomb = NULL;
	this->text = NULL;
	this->playerNameText = NULL;
	this->scoreText = NULL;
	this->currentScore = NULL;
	this->renderTarget = NULL;
	Mix_CloseAudio();
	Mix_Quit();
	IMG_Quit();
	SDL_Quit();
}
void SoundManager::releaseMusic(const std::string& fileName)
{
	std::string absFileName = RESOURCE_DIR + AUDIO_DIR + fileName;
	// If the resource already exists, check its tracker count.
	// If it is currently 1, we are removing the last handle to it
	// so we need to free the resource and remove it from our map.
	//
	// Otherwise, just decrease the count in the tracker
	MusicIterator musicElement = musics.find(absFileName);
	if (musicElement != musics.end())
	{
		Mix_FreeMusic(musicElement->second);
		musics.erase(musicElement);
	}

}
static void I_SDL_UnRegisterSong(void *handle)
{
    Mix_Music *music = (Mix_Music *) handle;

    if (!music_initialized)
    {
        return;
    }

    if (handle == NULL)
    {
        return;
    }

    Mix_FreeMusic(music);
}
Beispiel #8
0
void CleanUp(void)
{
	if( Mix_PlayingMusic() ) {
		Mix_FadeOutMusic(1500);
		SDL_Delay(1500);
	}
	if ( music ) {
		Mix_FreeMusic(music);
		music = NULL;
	}
	if ( audio_open ) {
		Mix_CloseAudio();
		audio_open = 0;
	}
	SDL_Quit();
}
Beispiel #9
0
void close()
{
    
    //Free the sound effects
    Mix_FreeChunk( sample );
    sample = NULL;
    
    //Free the music
    Mix_FreeMusic( music );
    music = NULL;

    
    //Quit SDL subsystems
    Mix_Quit();
    SDL_Quit();
}
void AudioManager::destroy()
{
	if (isInitialized_)
	{
		isInitialized_ = false;
		//Cleanup
		for (auto& it : musicMap_)
		{
			Mix_FreeMusic(it.second);
		}

		musicMap_.clear();
		Mix_CloseAudio();
		Mix_Quit();
	}
}
Beispiel #11
0
void soundLib::load_boss_music(string music_file) {
	string filename;

	if (boss_music != NULL) {
		Mix_HaltMusic();
		Mix_FreeMusic(boss_music);
        boss_music = NULL;
	}
    filename = FILEPATH + "music/" + music_file;
	//std::cout << "soundLib::load_boss_music - filename: " << filename << std::endl;
	boss_music = Mix_LoadMUS(filename.c_str());
	if (!boss_music) {
        std::cout << "Error in soundLib::load_boss_music::Mix_LoadMUS('" << filename << "': '" << Mix_GetError() << "'\n";
		exit(-1);
	}
}
void BGMusic::closeMedia()
{
    Mix_FreeMusic( bgmusic );
    bgmusic = NULL;
    Mix_FreeChunk( start_sound );
    start_sound = NULL;
    Mix_FreeChunk( victory_sound );
    victory_sound = NULL;
    Mix_FreeChunk( lose_sound );
    lose_sound = NULL;
    Mix_FreeChunk( aggro_sound );
    aggro_sound = NULL;
    //Quit SDL subsystems
    Mix_Quit();
    SDL_Quit();
}
Beispiel #13
0
SDLInteraction::~SDLInteraction()
{
    stopMusic();
    if (m_audioInitialized)
    {
        if (m_music != NULL)
        {
            Mix_HaltMusic();
            Mix_FreeMusic(m_music);
        }
        Mix_CloseAudio();
    }
    SDL_Quit();

    delete m_soundMap;
}
Beispiel #14
0
void ResourceManager::Clear()
{
    // (Properly) delete all shaders	
    for (auto iter : Shaders)
        glDeleteProgram(iter.second.ID);
    // (Properly) delete all textures
    for (auto iter : Textures)
        glDeleteTextures(1, &iter.second.ID);
    // (Properly) delete all cubemaps
    for (auto iter : Cubemaps)
        glDeleteTextures(1, &iter.second.ID);
    for(auto iterator : Musics)
        Mix_FreeMusic(iterator.second);
    for(auto iterator : Sons)
        Mix_FreeChunk(iterator.second);
}
Beispiel #15
0
void Sound::fadeOutMusic(int ms)
{
    mCurrentMusicFile.clear();

    if (!mInstalled)
        return;

    logger->log("Sound::fadeOutMusic() Fading-out (%i ms)", ms);

    if (mMusic)
    {
        Mix_FadeOutMusic(ms);
        Mix_FreeMusic(mMusic);
        mMusic = NULL;
    }
}
Beispiel #16
0
///////////////////////////////////////////////////////////
// ME play
///////////////////////////////////////////////////////////
void Audio::ME_Play(std::string file, int volume, int pitch) {
	std::string path = FileFinder::FindMusic(file);
	if (path.empty()) ARGSS::AError::FileNotFound(file);

	if (me != NULL) Mix_FreeMusic(me);
	me = Mix_LoadMUS(path.c_str());
	if (!me) ARGSS::AError::AudioNotLoad("ME", file, Mix_GetError());

	Mix_VolumeMusic(volume * MIX_MAX_VOLUME / 100);
	if (Mix_PlayMusic(me, 1) == -1) ARGSS::AError::AudioNotPlay("ME", file, Mix_GetError());

	me_playing = true;
	if (bgm_playing) {
		bgm_playing = false;
		Mix_HookMusicFinished(ME_finish);
	}
}
Beispiel #17
0
void LoadSongList(struct SongDef **songList, const char *dirPath)
{
	tinydir_dir dir;
	int errsv;
	if (tinydir_open(&dir, dirPath) == -1)
	{
		errsv = errno;
		printf("Cannot open music dir: %s\n", strerror(errsv));
		goto bail;
	}

	for (; dir.has_next; tinydir_next(&dir))
	{
		Mix_Music *m;
		tinydir_file file;
		if (tinydir_readfile(&dir, &file) == -1)
		{
			errsv = errno;
			debug(D_VERBOSE, "cannot read file: %s\n", strerror(errsv));
			goto bail;
		}
		if (!file.is_reg)
		{
			debug(D_VERBOSE, "not a regular file %s\n", file.name);
			continue;
		}
		if (strcmp(file.extension, "txt") == 0 ||
			strcmp(file.extension, "TXT") == 0)
		{
			debug(D_VERBOSE, "Skipping text file %s\n", file.name);
			continue;
		}

		m = Mix_LoadMUS(file.path);
		if (m == NULL)
		{
			debug(D_VERBOSE, "not a music file %s\n", file.name);
			continue;
		}
		Mix_FreeMusic(m);
		AddSong(songList, file.path);
	}

bail:
	tinydir_close(&dir);
}
Beispiel #18
0
void Bola::closeMedia(){
    //Free the sound effects
    Mix_FreeChunk( gGol );
    Mix_FreeChunk( gColision );
    Mix_FreeChunk( gNewPj );
    gGol = NULL;
    gColision = NULL;
    gNewPj = NULL;

    //Free the music
    Mix_FreeMusic( gMusic );
    gMusic = NULL;

    //Quit SDL subsystems
    Mix_Quit();
    SDL_Quit();
}
Beispiel #19
0
Resource::~Resource(){
	
	for( musicMap::iterator i = musicList->begin(); i != musicList->end(); i++ ){
		Mix_FreeMusic( i->second );
	}
	delete musicList;

	for( soundMap::iterator i = soundList->begin(); i != soundList->end(); i++ ){
		Mix_FreeChunk( i->second );
	}
	delete soundList;

	for( imageMap::iterator i = imageList->begin(); i != imageList->end(); i++ ){
		SDL_DestroyTexture(i->second);
	}
	delete imageList;
}
Beispiel #20
0
 ~music_t()
 {
     if(pMusic)
     {
         Mix_FreeMusic(pMusic);
         pMusic = NULL;
     }
     if(pRWop)
     {
         // Some SDL_Mixer backends will free this for you, and some will
         // not. As we do not know what the backend will do, we have to do
         // the same in every case, and a minor memory leak is less serious
         // (see http://code.google.com/p/corsix-th/issues/detail?id=3).
         //SDL_FreeRW(pRWop);
         pRWop = NULL;
     }
 }
Beispiel #21
0
//*************************************************************************************************
Game::~Game()
{
    delete m_ai;

    delete m_distX;
    delete m_distY;

    if (m_background) SDL_FreeSurface(m_background);
    if (m_bricks) SDL_FreeSurface(m_bricks);
    if (m_backbuffer) SDL_FreeSurface(m_backbuffer);
    if (m_font) SDL_FreeSurface(m_font);
    if (m_music) Mix_FreeMusic(m_music);
    if (m_sfxEat) Mix_FreeChunk(m_sfxEat);
    if (m_sfxGameover) Mix_FreeChunk(m_sfxGameover);
    Mix_CloseAudio();
    SDL_Quit();
}
void SoundManager::clearSoundMap() {
	for(auto i=m_music.begin();i!=m_music.end();i++){
		if(i->second!=nullptr){
			Mix_FreeMusic(i->second);
			i->second=nullptr;
		}
	}
	m_music.clear();

	for(auto j=m_sfxs.begin();j!=m_sfxs.end();j++){
		if(j->second!=nullptr){
			Mix_FreeChunk(j->second);
			j->second=nullptr;			
		}
	}
	m_sfxs.clear();
}
Beispiel #23
0
void destroySounds(void)
{
	int i;

	for (i = 0 ; i < SND_MAX ; i++)
	{
		if (sounds[i])
		{
			Mix_FreeChunk(sounds[i]);
		}
	}

	if (music != NULL)
	{
		Mix_FreeMusic(music);
	}
}
void AudioManagerSDL::Kill()
{
	Mix_HaltMusic();
	if ( m_pMusicChannel != NULL )
	{
		// free up any memore in use by the music track
		Mix_FreeMusic(m_pMusicChannel);

		// set it to null for safety (ensuring that 
		// if we acidentally refer to this variable after
		// deletion, at least it will be null)
		m_pMusicChannel = NULL; 
	}

	// close out the audio
	Mix_CloseAudio();
}
Beispiel #25
0
void MapIso::loadMusic() {

	if (music != NULL) {
		Mix_HaltMusic();
		Mix_FreeMusic(music);
		music = NULL;
	}
	music = Mix_LoadMUS(("music/" + this->music_filename).c_str());
	if (!music) {
	  printf("Mix_LoadMUS: %s\n", Mix_GetError());
	  SDL_Quit();
	}

	Mix_VolumeMusic(MUSIC_VOLUME);
	Mix_PlayMusic(music, -1);
	
}
int main(int argc, char *argv[]) {
SDL_Surface *screen;
SDL_Event event;
Mix_Music *musica;
int done = 0;
int canal;
atexit(SDL_Quit);
// Iniciar SDL
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) {
printf("No se pudo iniciar SDL: %s\n",SDL_GetError());
exit(1);
}
// Activamos modo de video
screen = SDL_SetVideoMode(640,480,24,SDL_HWSURFACE);
if (screen == NULL) {
printf("No se puede inicializar el modo gráfico: %s \n",SDL_GetError());
exit(1);
}
// Inicializamos SDL_mixer
if(Mix_OpenAudio(22050, AUDIO_S16, 2, 4096)) {
printf("No se puede inicializar SDL_mixer %s\n",Mix_GetError());
exit(1);
}
atexit(Mix_CloseAudio);
// Cargamos la música
musica = Mix_LoadMUS("C:/Documents and Settings/Owner/Desktop/Musica/Rose - La liste.mp3");
if ( musica == NULL ) {
printf("No pude cargar musica: %s\n", Mix_GetError());
exit(1);
}
// Reproducción la música.
// Esta función devuelve el canal por el que se reproduce la música
canal = Mix_PlayMusic(musica, -1);
// Esperamos la pulsación de una tecla para salir
while(done == 0) {
while ( SDL_PollEvent(&event) ) {
if ( event.type == SDL_KEYDOWN )
done = 1;
}
}
// paramos la música
Mix_HaltMusic();
// liberamos recursos
Mix_FreeMusic(musica);
return 0;
}
void violetland::MusicManager::play(std::string name, bool now) {
	if (m_currentPlaying == name)
		return;
	
	if (m_currentPlaying != "null")
		Mix_FreeMusic(m_current);
	
	m_currentPlaying = name;
	m_current = Mix_LoadMUS(m_fileUtility->getFullPath(FileUtility::music, name).string().c_str());
	if(m_current) 
	{
		if(Mix_PlayMusic(m_current, -1) == -1)
			cout << "Mix_PlayMusic: " << Mix_GetError() << endl;
	}
	else
		cout << "Mix_LoadMUS: " << Mix_GetError() << endl;
}
Beispiel #28
0
	void Audio::destroy()
	{
		if (!m_Initialized) return;
		m_Initialized = false;
		for (auto it = m_soundsMap.begin(); it != m_soundsMap.end(); it++) 
		{
			Mix_FreeChunk(it->second.m_chunk);
		}
		m_soundsMap.clear();
		//New C++11 iteration mode (foreach)
		for (auto &it : m_musicMap) { //as long as there is a begin and end you can iterate
			Mix_FreeMusic(it.second);
		}
		m_musicMap.clear();
		Mix_CloseAudio();
		Mix_Quit();
	}
Beispiel #29
0
/**
 * @sa M_Start
 */
void M_Stop (void)
{
	/* we should not even have a buffer nor data set - but ... just to be sure */
	if (music.playingStream)
		return;

	if (music.data != nullptr) {
		Mix_HaltMusic();
		Mix_FreeMusic(music.data);
	}

	if (music.buffer)
		FS_FreeFile(music.buffer);

	music.data = nullptr;
	music.buffer = nullptr;
}
Beispiel #30
0
void SDLInteraction::setMusicTrack(const QString & musicFile)
{
    bool wasPlayingMusic = m_isPlayingMusic;

    stopMusic();

    if (m_music != NULL)
    {
        Mix_FreeMusic(m_music);
        m_music = NULL;
    }

    m_musicTrack = musicFile;

    if (wasPlayingMusic)
        startMusic();
}