void killGame(void) { fadeOut(); NOGBA("KILLING IT"); freePlayer(); freeEnergyBalls(); freeBigButtons(); freeCubes(); freeDoors(); freeElevators(); freeEmancipation(); freePlatforms(); freeTimedButtons(); freeTurrets(); freeWallDoors(); freeSludge(); freeRoom(&gameRoom); freePortals(); freeState(NULL); freeSound(); freePause(); resetAllPI(); NOGBA("END mem free : %dko (%do)",getMemFree()/1024,getMemFree()); }
int initMovieSound(int f, ALenum format, int audioChannels, ALuint samplerate, ALuint (*callback)(void *userdata, ALubyte *data, ALuint bytes)) { if (! soundOK) return 0; int retval; int a = findEmptySoundSlot (); freeSound (a); soundCache[a].looping = false; // audioChannel * sampleRate gives us a buffer of half a second. Not much, but it should be enough. soundCache[a].stream = alureCreateStreamFromCallback( callback, &intpointers[a], format, samplerate, audioChannels*samplerate, 0, NULL); if (soundCache[a].stream != NULL) { soundCache[a].fileLoaded = f; soundCache[a].vol = defSoundVol; retval = a; } else { debugOut("Failed to create stream from sound: %s\n", alureGetErrorString()); warning (ERROR_SOUND_ODDNESS); soundCache[a].stream = NULL; soundCache[a].playing = false; soundCache[a].playingOnSource = 0; soundCache[a].fileLoaded = -1; retval = -1; } //fprintf (stderr, "Stream %d created. Sample rate: %d Channels: %d\n", retval, samplerate, audioChannels); return retval; }
void update() { for (int i = 0; i < kMixChannels; ++i) { if (_sounds[i] && !Mix_Playing(i)) { freeSound(i); } } }
void killSoundStuff () { if (soundOK) { int a; for (a = 0; a < MAX_MODS; a ++) stopMOD (a); for (a = 0; a < MAX_SAMPLES; a ++) freeSound (a); BASS_Free(); } }
/* fonction qui permet de libérer les ressources allouées */ void cleanup() { int i; if (map.background != NULL) { SDL_FreeSurface(map.background); } if (hero.sprite != NULL) { SDL_FreeSurface(hero.sprite); } for(i = 0 ; i < ENNEMIS_MAX ; i++) { time_t t2; t2=time(0); int t=t2-hero.t1; if (ennemi[i].sprite != NULL&& t>3) { SDL_FreeSurface(ennemi[i].sprite); } } if (map.tileSet != NULL) { SDL_FreeSurface(map.tileSet); } if (jeu.Score_Icone != NULL) { SDL_FreeSurface(jeu.Score_Icone); } if (jeu.Icone_vie != NULL) { SDL_FreeSurface(jeu.Icone_vie); } if (jeu.bouleFeu_image != NULL) { SDL_FreeSurface(jeu.bouleFeu_image); } Mix_CloseAudio(); Mix_Quit(); if ( jeu.musique != NULL ) Mix_FreeMusic(jeu.musique); freeSound(); closeFont(font); TTF_Quit(); SDL_Quit(); }
bool forceRemoveSound () { for (int a = 0; a < 8; a ++) { if (soundCache[a].fileLoaded != -1 && ! stillPlayingSound (a)) { // soundWarning ("Deleting silent sound", a); freeSound (a); return 1; } } for (int a = 0; a < 8; a ++) { if (soundCache[a].fileLoaded != -1) { // soundWarning ("Deleting playing sound", a); freeSound (a); return 1; } } // soundWarning ("Cache is empty!", 0); return 0; }
void loadSounds (FILE * fp) { for (int i = 0; i < MAX_SAMPLES; i ++) freeSound (i); while (fgetc (fp)) { int fileLoaded = get2bytes (fp); defSoundVol = get2bytes (fp); startSound (fileLoaded, 1); } defSoundVol = get2bytes (fp); defVol = get2bytes (fp); }
int cacheSound (int f) { setResourceForFatal (f); if (! soundOK) return 0; int a = findInSoundCache (f); if (a != -1) return a; if (f == -2) return -1; a = findEmptySoundSlot (); freeSound (a); uint32_t length = openFileFromNum (f); if (! length) return -1; char * memImage; bool tryAgain = true; while (tryAgain) { memImage = loadEntireFileToMemory (bigDataFile, length); tryAgain = memImage == NULL; if (tryAgain) { if (! forceRemoveSound ()) { fatal (ERROR_SOUND_MEMORY_LOW); return -1; } } } for (;;) { // soundWarning (" Trying to load sound into slot", a); soundCache[a].sample = BASS_SampleLoad(true, memImage, 0, length, 65535, 0); if (soundCache[a].sample) { soundCache[a].fileLoaded = f; delete memImage; setResourceForFatal (-1); return a; } warning (ERROR_SOUND_ODDNESS); soundCache[a].sample = NULL; soundCache[a].fileLoaded = -1; soundCache[a].looping = false; return -1; } }
void huntKillFreeSound (int filenum) { int gotSlot = findInSoundCache (filenum); if (gotSlot != -1) freeSound (gotSlot); }
int cacheSound (int f) { if (! soundOK) return -1; unsigned int chunkLength; int retval; bool loopy; loopy = cacheLoopySound; cacheLoopySound = false; setResourceForFatal (f); if (! soundOK) return 0; int a = findInSoundCache (f); if (a != -1) { if (soundCache[a].playing) { if (! alureStopSource(soundCache[a].playingOnSource, AL_TRUE)) { debugOut( "Failed to stop source: %s\n", alureGetErrorString()); } } if (! alureRewindStream (soundCache[a].stream)) { debugOut( "Failed to rewind stream: %s\n", alureGetErrorString()); } return a; } if (f == -2) return -1; a = findEmptySoundSlot (); freeSound (a); uint32_t length = openFileFromNum (f); if (! length) return -1; unsigned char * memImage; bool tryAgain = true; while (tryAgain) { memImage = (unsigned char*)loadEntireFileToMemory (bigDataFile, length); tryAgain = memImage == NULL; if (tryAgain) { if (! forceRemoveSound ()) { fatal (ERROR_SOUND_MEMORY_LOW); return -1; } } } chunkLength = 19200; // Small looping sounds need small chunklengths. if (loopy) { if (length < NUM_BUFS * chunkLength) { chunkLength = length / NUM_BUFS; } } else if (length < chunkLength) { chunkLength = length; } soundCache[a].stream = alureCreateStreamFromMemory(memImage, length, chunkLength, 0, NULL); delete memImage; if (soundCache[a].stream != NULL) { soundCache[a].fileLoaded = f; setResourceForFatal (-1); retval = a; } else { debugOut("Failed to create stream from sound: %s\n", alureGetErrorString()); warning (ERROR_SOUND_ODDNESS); soundCache[a].stream = NULL; soundCache[a].playing = false; soundCache[a].playingOnSource = 0; soundCache[a].fileLoaded = -1; soundCache[a].looping = false; retval = -1; } return retval; }
void huntKillFreeSound (int filenum) { if (! soundOK) return; int gotSlot = findInSoundCache (filenum); if (gotSlot == -1) return; freeSound (gotSlot); }
Sound::~Sound() { freeSound(); free(_description); delete _handle; }
void stopSound(uint8_t channel) { Mix_HaltChannel(channel); freeSound(channel); }
/** *\fn int main(int argc, char *argv[]) * Main *\param[in,out] argc argc *\param[in,out] argv argv */ int main(int argc, char *argv[]) { SDL_Surface *screen = NULL; int go = 1; int ret,ret1, ret2 = 0, ret3, ret4; char level_name[MAX_SIZE_FILE_NAME]; char player_name[MAX_SIZE_FILE_NAME]; int nb_lvl; /*sound*/ Sound *sound_system; sound_system = createSound(); /*keyboard config*/ SDLKey kc[NB_KEY-1]; /*input*/ Input in; SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK); Player *current_player; current_player = (Player *)malloc(sizeof(Player)); /*screen initialization*/ screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); initInput(&in); /*configurations loading */ loadSoundOptions("configuration/sound.conf",sound_system); SDL_WM_SetCaption("Super Martin", NULL); //window name SDL_ShowCursor(SDL_DISABLE); //delete the mouse while (go) //main loop { if(titleMenu(screen,&go,sound_system, &in)) { while( (ret3 = menuPlayers(screen, player_name, &go, sound_system, &in)) != -1 && go) { switch(ret3) { case -1: break; case 2 : ret2 = newPlayer(screen, player_name, sound_system, &go); if(ret2 == 1) { current_player->levelMax = 1; current_player->nbCoins = 0; current_player->nbLifes = 3; current_player->nbProjectile = 5; savePlayer("save/.save", player_name, current_player); loadInputOptions("default",kc,&in); saveInputOptions(player_name, kc, &in); } else break; case 1 : loadPlayer("save/.save", player_name, current_player); loadInputOptions(player_name,kc,&in); while(go && (ret1 = mainMenu(screen,&go,sound_system, player_name, &in)) != -1) { switch(ret1) { case -1: break; case 0: while( (ret4 = menuLevel(screen,level_name,sound_system, player_name, current_player, &go, &nb_lvl, &in)) != -1 && go) { while(play(screen,level_name,sound_system,&go,kc, &in, current_player, player_name, ret4+1, nb_lvl) && go); } break; case 1 : save(screen, "save/.save", player_name, current_player, &go); loadPlayer("save/.save", player_name, current_player); break; case 2 : while((ret = optionMenu(screen,&go,sound_system,kc, &in)) != -1 && go) { switch(ret) { case -1: break; case 0: soundOptions(screen,&go,sound_system, &in); break; case 1: keyBoardOptions(screen,&go,kc,&in,player_name); break; default:; } } break; case 3 : deletePlayer(screen, "save/players", player_name); go = 0; break; default: ; } } go = 1; break; default : ; } } } SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,255,255,255)); //clear screen SDL_Flip(screen); } freeSound(sound_system); free((void*)current_player); freeInput(&in); SDL_Quit(); return EXIT_SUCCESS; }