void SDLSound::stopMusic()
{
    // nicely fade the music out for 1 second
    if(Mix_PlayingMusic()) {
        Mix_HookMusicFinished(0);
        Mix_FadeOutMusic(500);
    }
}
Exemple #2
0
//----------------------------------------------------------------------------
void Audio::turnMusicOff( void)
{
    if (_isPlaying)
    {
        Mix_FadeOutMusic(0);
        _isPlaying = false;
    }
}
Exemple #3
0
void music_stop (void)
{
#if HAVE_LIBSDL_MIXER
    if (!playlist || game_settings.music == 0)
        return;
    Mix_FadeOutMusic (500);
#endif
}
Exemple #4
0
void game_titlescreen()
{
    gamestate_over = true;
    gamestate_pause = false;
    gamestate_title = true;
    game_setstatustext("",0);
    Mix_FadeOutMusic(sound_fadetime);
    Mix_HaltChannel(-1);
}
Exemple #5
0
void quitProgram(int returnValue)
{
#ifdef SOUND_ENABLED
  Mix_FadeOutMusic(700);
#endif
  if(unpacked)
  {
    logString("Quitting\n");
    remove("textures/CRYSTAL.BMP");
    remove("textures/FLY.BMP");
    remove("textures/JOHN.BMP");
    remove("textures/MARS1.BMP");
    remove("textures/MARS2.BMP");
    remove("textures/METAL.BMP");
    remove("textures/MOON1.BMP");
    remove("textures/MOON2.BMP");
    remove("textures/SAND.BMP");
    remove("textures/STEIN1.BMP");
    remove("textures/STEIN.BMP");
    remove("textures/STONE53.BMP");
    remove("textures/STONE54.BMP");
    remove("sounds/bg.ogg");
    remove("sounds/boom.wav");
    remove("sounds/crystal.wav");
    remove("sounds/fanfare.wav");
    remove("gfx/font.bmp");
    remove("gfx/particle.bmp");
    remove("gfx/loading.bmp");
    remove("textures");
    remove("sounds");
    remove("gfx");
  }
  
  hiScores = fopen(hsFName, "w");
  if (!hiScores)
    fprintf(stderr, "Couldn't write Hall of Fame\n");
  else
  {
    int i;
    for(i=0; i<10; i++)
    {
      fprintf(hiScores, "%s = %d %d %d\n",
        scores[i].Name, scores[i].mins, scores[i].secs, scores[i].dsec);
    }
    fclose(hiScores);
  }
  
  free(camBase);
  free(shipBase);
#ifdef SOUND_ENABLED
  while(Mix_FadingMusic() == MIX_FADING_OUT){};
#endif
  SDL_Quit();
  if(!debug && unpacked)
    fclose(logfile);
  exit(returnValue);
}
void SDLInteraction::StopMusic()
{
    if (music != NULL) {
        // fade out music to finish 0,5 seconds from now
        while(!Mix_FadeOutMusic(1000) && Mix_PlayingMusic()) {
            SDL_Delay(100);
        }
    }
}
Exemple #7
0
/**
 * Play the intro.
 */
void IntroState::init()
{
	State::init();
	Options::keepAspectRatio = _wasLetterBoxed;
	if (CrossPlatform::fileExists(_introFile) && (CrossPlatform::fileExists(_introSoundFileDOS) || CrossPlatform::fileExists(_introSoundFileWin)))
	{
		audioSequence = new AudioSequence(_game->getResourcePack());
		Flc::flc.realscreen = _game->getScreen();
		Flc::FlcInit(_introFile.c_str());
		Flc::flc.dx = (Options::baseXResolution - Screen::ORIGINAL_WIDTH) / 2;
		Flc::flc.dy = (Options::baseYResolution - Screen::ORIGINAL_HEIGHT) / 2;
		Flc::flc.loop = 0; // just the one time, please
		Flc::FlcMain(&audioHandler);
		Flc::FlcDeInit();
		delete audioSequence;


#ifndef __NO_MUSIC
		// fade out!
		Mix_FadeOutChannel(-1, 45 * 20);
		if (Mix_GetMusicType(0) != MUS_MID) { Mix_FadeOutMusic(45 * 20); func_fade(); } // SDL_Mixer has trouble with native midi and volume on windows, which is the most likely use case, so f@%# it.
		else { Mix_HaltMusic(); }
#endif

		SDL_Color pal[256];
		SDL_Color pal2[256];
		memcpy(pal, _game->getScreen()->getPalette(), sizeof(SDL_Color) * 256);
		for (int i = 20; i > 0; --i)
		{
			SDL_Event event;
			if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) break;
			for (int color = 0; color < 256; ++color)
			{
				pal2[color].r = (((int)pal[color].r) * i) / 20;
				pal2[color].g = (((int)pal[color].g) * i) / 20;
				pal2[color].b = (((int)pal[color].b) * i) / 20;
				pal2[color].unused = pal[color].unused;
			}
			_game->getScreen()->setPalette(pal2, 0, 256, true);
			_game->getScreen()->flip();
			SDL_Delay(45);
		}
		_game->getScreen()->clear();
		_game->getScreen()->flip();
		Options::musicVolume = _oldMusic;
		Options::soundVolume = _oldSound;
		_game->setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume);

#ifndef __NO_MUSIC
		Sound::stop();
		Music::stop();
#endif
	}
	Screen::updateScale(Options::geoscapeScale, Options::geoscapeScale, Options::baseXGeoscape, Options::baseYGeoscape, true);
	_game->getScreen()->resetDisplay(false);
	_game->setState(new MainMenuState);
}
bool ModuleStartScreen::CleanUp()
{
	play = false;
	App->textures->Unload(graphics);
	while (!Mix_FadeOutMusic(1000) && Mix_PlayingMusic())
		SDL_Delay(1000);

	return true;
}
Exemple #9
0
void snd_stop_mus(int ms)
{
	if (!sound_on)
		return;
	Mix_HookMusicFinished(NULL);
	if (ms)
		Mix_FadeOutMusic(ms);
	else
		Mix_HaltMusic();
}
Exemple #10
0
bool MusicEntry::stop(int fade_ms)
{
	if (Mix_PlayingMusic())
	{
        logGlobal->traceStream()<<"Stoping music file "<<currentName;
		loop = 0;
		Mix_FadeOutMusic(fade_ms);
		return true;
	}
	return false;
}
// Load assets
bool ModuleWelcome::CleanUp()
{
	LOG("Unloading honda stage");
	App->textures->Unload(graphics);
	App->textures->Unload(graphics_2);
	App->textures->Unload(graphics_Balls);
	while (!Mix_FadeOutMusic(1000) && Mix_PlayingMusic())
		SDL_Delay(1000);

	return true;
}
Exemple #12
0
//BackGroundMusic, volume = between [0 - 128], 64 = neutral
void SoundBank::PlayBGM(SoundBgmType type, int volume) {
	Mix_Music* tempMusic = Mix_LoadMUS(bgmPathList.at(type));
	if (!Mix_PlayingMusic()) { //there is no music playing yet
		Mix_FadeInMusic(Mix_LoadMUS(bgmPathList.at(type)), -1, 1000);
		Mix_VolumeMusic(volume);
	}
	else if(!Mix_PausedMusic()) { //there is already music playing
		Mix_FadeOutMusic(1000);
		Mix_FadeInMusic(Mix_LoadMUS(bgmPathList.at(type)), -1, 1000);
		Mix_VolumeMusic(volume);
	}
}
void
AudioSDLMixer::stopMusic() 
{
  if( Mix_PlayingMusic() ) {
    Mix_FadeOutMusic(1500);
    SDL_Delay(1500);
  }
  if ( music ) {
    Mix_FreeMusic(music);
    music = NULL;
  }
}
int Musica::fadeOutSonMus(int ms)
{

    if (esMusica)
    {
        return Mix_FadeOutMusic(ms);
    }
    else
    {
        return Mix_FadeOutChannel(-1, ms);
    }
}
Exemple #15
0
// Play a music file
bool j1Audio::PlayMusic(const char* path, float fade_time)
{
	bool ret = true;

	if (!enabled)
		return false;

	if(music != NULL)
	{
		if(fade_time > 0.0f)
		{
			Mix_FadeOutMusic(int(fade_time * 1000.0f));
		}
		else
		{
			Mix_HaltMusic();
		}

		// this call blocks until fade out is done
		Mix_FreeMusic(music);
	}

	music = Mix_LoadMUS_RW(App->fs->Load(path), 1);

	if(music == NULL)
	{
		LOG("Cannot load music %s. Mix_GetError(): %s\n", path, Mix_GetError());
		ret = false;
	}
	else
	{
		if(fade_time > 0.0f)
		{
			if(Mix_FadeInMusic(music, -1, (int) (fade_time * 1000.0f)) < 0)
			{
				LOG("Cannot fade in music %s. Mix_GetError(): %s", path, Mix_GetError());
				ret = false;
			}
		}
		else
		{
			if(Mix_PlayMusic(music, -1) < 0)
			{
				LOG("Cannot play in music %s. Mix_GetError(): %s", path, Mix_GetError());
				ret = false;
			}
		}
	}

	LOG("Successfully playing %s", path);
	return ret;
}
Exemple #16
0
void music_stop_fade(void)
{
#ifndef NOSOUND
#ifdef ARGS
	if (sound_arg)
	{
#endif
		Mix_FadeOutMusic(3000);
#ifdef ARGS
	}
#endif
#endif
}
Exemple #17
0
bool j1Audio::PlayMusic(SDL_RWops* _music, const char* path, float fade_time)
{
	bool ret = true;

	if (_music != NULL)
	{
		if (fade_time > 0.0f)
		{
			Mix_FadeOutMusic(int(fade_time * 1000.0f));
		}
		else
		{
			Mix_HaltMusic();
		}

		// this call blocks until fade out is done

	}

	music = Load_music(_music);


	if (music == NULL)
	{
		LOG("Cannot load music %s. Mix_GetError(): %s\n", path, Mix_GetError());
		ret = false;
	}
	else
	{
		if (!fade_time > 0.0f)
		{
			if (Mix_FadeInMusic(music, -1, 10000) < 0)
			{
				LOG("Cannot fade in music %s. Mix_GetError(): %s", path, Mix_GetError());
				ret = false;
			}

		}
		else
		{
			if (Mix_PlayMusic(music, -1) < 0)
			{
				LOG("Cannot play in music %s. Mix_GetError(): %s", path, Mix_GetError());
				ret = false;
			}
		}
	}

	LOG("Successfully playing %s", path);
	return ret;
}
Exemple #18
0
int main(int argc,char *argv[])
{
if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
    fprintf(stderr, "Problem: %s\n", SDL_GetError());
    exit(1); 
}
atexit(SDL_Quit);

//frekvence 22050 Hz
//MIX_DEFAULT_FORMAT - Signed 16-bit zvuky, v systemovem bytovem poradi (little,big endian)
//mono-stereo: pro mono vlozte 1, pro stereo 2

if (Mix_OpenAudio(22050/*frekvence [Hz]*/, MIX_DEFAULT_FORMAT, 2/*mono-stereo*/,1024/*velikost bloku*/)==-1)
{
    fprintf(stderr,"Mix_OpenAudio: %s\n", Mix_GetError());
    exit(1);
}

 sounds[SND_ZVUK] = Mix_LoadWAV("zvuk.wav");
if (sounds[SND_ZVUK]==NULL) 
{
    fprintf(stderr,"zvuk [zvuk.wav] nebyl nahran\n");exit(2);}

 //kanal: -1 pro prvni volny kanal
//pocet opakovani x: zvuk se bude opakovat x+1 krat,x=-1 pro stale opakovani.
Mix_PlayChannel(-1/*kanal*/,sounds[SND_ZVUK]/*Mix_Chunk*/,0/*pocet opakovani*/);

 music=Mix_LoadMUS("music.mp3");
if (!music) {
    printf("Mix_LoadMUS(\"music.mp3\"): %s\n", Mix_GetError());
    exit(2);
}

//pocet opakovani x: hudba se bude opakovat x krat,x=-1 pro stale opakovani.
//postupne zvysuje hlasitost hudby od 0 do 100% za 2000 ms po spusteni

Mix_FadeInMusic(music, -1/*pocet opakovani*/,2000 /*cas[ms]*/);

//lze i jen provest pouhe spusteni hudby
//Mix_PlayMusic(music, -1/*pocet opakovani*/);

SDL_Delay(5000);

 //ztlumi hudbu az do ticha a vypne
Mix_FadeOutMusic(2000);

SDL_Delay(1000);

Mix_CloseAudio();
return 0;
}
Exemple #19
0
void AudioMixer::fade_out_all()
{
	cout << "fading out" << endl;
	Mix_FadeOutChannel(-1, 500);
	Mix_FadeOutMusic(500);
	
	sfx_on = false;
	music_on = false;
	
	list<AudioFile*>::iterator iter;
	for (iter = audio_files.begin() ; iter != audio_files.end() ; iter++) {
		(*iter)->toggle_mute();
	}
}
Exemple #20
0
void SdlAudio::BGM_Fade(int fade) {
#ifdef _WIN32
	// FIXME: Because of design change in Vista and higher reducing Midi volume
	// alters volume of whole application and mutes it forever when restarted.
	// Fading out midi music was disabled for Windows.
	if (Mix_GetMusicType(bgm.get()) == MUS_MID &&
		WindowsUtils::GetWindowsVersion() >= 6) {
		BGM_Stop();
		return;
	}
#endif
	Mix_FadeOutMusic(fade);
	me_stopped_bgm = false;
}
Exemple #21
0
EXPORT int op_calc_game(pdata data)
{
    if (data->step==0) //Fade In
    {
        data->fade-=(float)(*(data->gameinfo->steps))/500.0;
        if (data->fade<=0.0)
        {
            data->fade=0.0;
            data->step=1;
        }
        return 0;
    }
    if (data->step==2) //Fade Out
    {
        data->fade+=(float)(*(data->gameinfo->steps))/500.0;
        if (data->fade>=1.0)
        {
            data->fade=1.0;
            return 1;
        }
        return 0;
    }
    if (data->countdown>0) //Countdown
    {
        data->countdown-=*(data->gameinfo->steps);
        return 0;
    }

    //zeitunabhängige Bewegung:
    for (int a=0; a<data->gameinfo->playernum; a++)
        for (int b=0; b<4; b++)
            if (*(data->gameinfo->joystick[a].button[b]))
            {
                data->step=2;
                Mix_FadeOutMusic(500);
                return 0;
            }


    int steps;
    for (steps=0; steps<*(data->gameinfo->steps); steps++)
    {
        //zeitabhängige Berechnungen
    }



    return 0;
}
void ChannelInternalState::FadeOut(int milliseconds) {
  int channels_halted;
  if (IsStream()) {
#ifdef PINDROP_MULTISTREAM
    channels_halted = Mix_FadeOutMusicCh(channel_id_, milliseconds);
#else
    channels_halted = Mix_FadeOutMusic(milliseconds);
#endif  // PINDROP_MULTISTREAM
  } else {
    channels_halted = Mix_FadeOutChannel(channel_id_, milliseconds);
  }
  if (channels_halted == 0) {
    SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error halting channel %i\n");
  }
}
Exemple #23
0
void I_StopSong (int handle)
{
	if(!music_initialized)
		return;

#ifdef OSX

	MusicPlayerStop(player);

#else

	Mix_FadeOutMusic(100);
	current_track = 0;

#endif
}
Exemple #24
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;
    }
}
Exemple #25
0
void gameOver() // Tiles stacking up, music fading out, etc
{
	Mix_FadeOutMusic(1000);
	
	for(int y = FIELDY - 1; y >= 0; y--)
	{
		for(int x = 0; x < FIELDX; x++)
		{
			apply_surface( x*BLOCKSIZE + XOFFSET, y*BLOCKSIZE + YOFFSET, block, screen, &clip[(((FIELDY-y)*FIELDX+x)%7+1)] );
			SDL_Flip( screen );
			SDL_Delay(2);
		}
	}
	
	SDL_Delay(1000);
}
Exemple #26
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();
}
void
Sound::enableMusic(bool enabled)
{
    if(getConfig()->musicEnabled == enabled)
        return;
    getConfig()->musicEnabled = enabled;

    if(!audioOpen)
        return;

    if(enabled) {
        playMusic(musicFile);
    } else {
        if(Mix_PlayingMusic()) {
            Mix_FadeOutMusic(1000);
        }
    }
}
Exemple #28
0
void Mixer::playMusic( std::string name )
{
    if( soundList_.size() < 1 )
    {
        return;
    }

    AudioData* data = NULL;
    bool foundData = false;

    for ( size_t i = 0; i < soundList_.size(); ++i )
    {
    	if( soundList_[i]->friendlyname.compare( name ) == 0 )
    	{
    	    data = soundList_[i];

    	    // check if the data exists
    	    if( data->data_p == NULL ) return;
    	    foundData = true;
    	}
    }

    if( !foundData ) return;

    Mix_Music* music = (Mix_Music*)data->data_p;

    // check if there already is music playing
    // if this is the case, fade out & in
    // else just start playing
    // TODO: real crossfading needs implementation of a multi-channel music mixer
    if( Mix_PlayingMusic() )
    {
        Mix_FadeOutMusic( 500 );
        while( Mix_FadingMusic() ) {}
        Mix_FadeInMusic( music, -1, 500 );
    }
    else
    {
        Mix_PlayMusic( music, -1 );
    }

    lastPlayed = name;
}
Exemple #29
0
/* function: Mix_FadeOutMusic */
static int toluaI_sound_sound_fade_out_music00(lua_State* tolua_S)
{
 if (
 !tolua_istype(tolua_S,1,LUA_TNUMBER,0) ||
 !tolua_isnoobj(tolua_S,2)
 )
 goto tolua_lerror;
 else
 {
  s32b fade_out_time = ((s32b)  tolua_getnumber(tolua_S,1,0));
 {
  Mix_FadeOutMusic(fade_out_time);
 }
 }
 return 0;
tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'fade_out_music'.");
 return 0;
}
Exemple #30
0
void DigiFadeoutMusic (void)
{
#if USE_SDL_MIXER
extern Mix_Music *mixMusic;
if (!gameStates.sound.digi.bAvailable) 
	return;
if (gameOpts->sound.bUseSDLMixer) {
	if (gameOpts->sound.bFadeMusic) {
		while (!Mix_FadeOutMusic (250) && Mix_PlayingMusic ())
			SDL_Delay (50);		
		while (Mix_PlayingMusic ())
			SDL_Delay (1);		
		}
	Mix_HaltMusic ();
	Mix_FreeMusic (mixMusic);
	mixMusic = NULL;
	}
#endif
}