Example #1
0
static mrb_value
mrb_sdl2_mixer_fade_out_channel(mrb_state *mrb, mrb_value self)
{
  mrb_int which, ms;
  mrb_get_args(mrb, "ii", &which, &ms);
  return mrb_fixnum_value(Mix_FadeOutChannel(which, ms));
}
Example #2
0
void cAudio :: Fadeout_Sounds( unsigned int ms, std::string filename, bool overwrite_fading /* = 0 */ )
{
	if( !m_sound_enabled || !m_initialised )
	{
		return;
	}

	// add sound directory
	if( filename.find( DATA_DIR "/" GAME_SOUNDS_DIR "/" ) == std::string::npos )
	{
		filename.insert( 0, DATA_DIR "/" GAME_SOUNDS_DIR "/" );
	}

	// get all sounds
	for( AudioSoundList::const_iterator itr = m_active_sounds.begin(); itr != m_active_sounds.end(); ++itr )
	{
		// get object pointer
		const cAudio_Sound *obj = (*itr);

		// filename does not match
		if( obj->m_data->m_filename.compare( filename ) != 0 )
		{
			continue;
		}

		// Do not fade out the sound again
		if( !overwrite_fading && Is_Sound_Fading( obj->m_channel ) == MIX_FADING_OUT )
		{
			continue;
		}

		Mix_FadeOutChannel( obj->m_channel, ms );
	}
}
Example #3
0
void MG_sprite_play_music( SPRITE * self )
{
	if( !self->anim || !self->anim->music )
		return;

	int expire = self->anim->delay*self->anim->count;

	if( self->audio_state.channel < 0 )
	{
		self->audio_state.channel = Mix_PlayChannel( -1 , self->anim->music , -1 );
		self->audio_state.played_time = 0;
		return;
	}

	self->audio_state.played_time += MG_get_system_dt();
	if( self->audio_state.played_time >= expire ){
		if( Mix_Playing( self->audio_state.channel ) ){
//			Mix_HaltChannel( self->audio_state.channel );
			Mix_FadeOutChannel( self->audio_state.channel , MG_get_system_dt()*2 );
		}

		self->audio_state.channel = -1;

		if( self->audio_state.repeat ){
			MG_sprite_play_music( self );
		}

	}

}
Example #4
0
bool Sample::FadeOut(float seconds) {
	int ret;
	if (m_Channel == -1) return false;
	ret=Mix_FadeOutChannel(m_Channel,(int)(seconds*1000.0f));
	if (ret) return false;
	return true;
}
Example #5
0
/* Fade out a channel and then stop it automatically */
int Mix_FadeOutChannel(int which, int ms)
{
	int status;

	status = 0;
	if ( audio_opened ) {
		if ( which == -1 ) {
			int i;

			for ( i=0; i<num_channels; ++i ) {
				status += Mix_FadeOutChannel(i, ms);
			}
		} else if ( which < num_channels ) {
			SDL_LockAudio();
			if ( mix_channel[which].playing && 
			    (mix_channel[which].volume > 0) &&
			    (mix_channel[which].fading != MIX_FADING_OUT) ) {
				mix_channel[which].fade_volume = mix_channel[which].volume;
				mix_channel[which].fading = MIX_FADING_OUT;
				mix_channel[which].fade_length = ms;
				mix_channel[which].ticks_fade = SDL_GetTicks();

				/* only change fade_volume_reset if we're not fading. */
				if (mix_channel[which].fading == MIX_NO_FADING) {
				    mix_channel[which].fade_volume_reset = mix_channel[which].volume;
				}
				++status;
			}
			SDL_UnlockAudio();
		}
	}
	return(status);
}
Example #6
0
d_define_method(track, stop_fade_out)(struct s_object *self, int delay) {
    d_using(track);
    if ((track_attributes->channel != d_track_auto_channel) && ((Mix_Playing(track_attributes->channel)) || (Mix_Paused(track_attributes->channel))))
        if (!Mix_FadeOutChannel(track_attributes->channel, delay))
            Mix_HaltChannel(track_attributes->channel);
    return self;
}
Example #7
0
void SoundChunk::fadeOut(int ms)
{
	if (mCurrentChanel >= 0)
	{
		Mix_FadeOutChannel(mCurrentChanel, ms);
		mCurrentChanel = -1;
	}
}
void
vsSoundSystem::StopChannel( int channel )
{
#if !TARGET_OS_IPHONE
	if ( channel != -1 )
		Mix_FadeOutChannel( channel, 500 );
#endif
}
Example #9
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);
}
Example #10
0
File: sound.c Project: wimh/instead
void snd_halt_chan(int han, int ms)
{
	if (han >= MIX_CHANNELS)
		han %= MIX_CHANNELS;
	if (ms)
		Mix_FadeOutChannel(han, ms);
	else {
		Mix_HaltChannel(han);
	}
}
Example #11
0
/* Halt playing of a particular group of channels */
int Mix_FadeOutGroup(int tag, int ms)
{
	int i;
	int status = 0;
	for ( i=0; i<num_channels; ++i ) {
		if( mix_channel[i].tag == tag ) {
			status += Mix_FadeOutChannel(i,ms);
		}
	}
	return(status);
}
Example #12
0
int Musica::fadeOutSonMus(int ms)
{

    if (esMusica)
    {
        return Mix_FadeOutMusic(ms);
    }
    else
    {
        return Mix_FadeOutChannel(-1, ms);
    }
}
Example #13
0
/**
 * @brief Updates all active channels for the current frame.
 */
void S_MixChannels(void) {

	Mix_Volume(-1, Clamp(s_volume->value, 0.0, 1.0) * MIX_MAX_VOLUME);

	s_channel_t *ch = s_env.channels;
	for (int32_t i = 0; i < MAX_CHANNELS; i++, ch++) {
		if (ch->free) {
			memset(ch, 0, sizeof(*ch));
		}
	}

	s_env.num_active_channels = 0;

	ch = s_env.channels;
	for (int32_t i = 0; i < MAX_CHANNELS; i++, ch++) {

		if (ch->sample) {

			if (ch->start_time) {
				if (ch->play.flags & S_PLAY_FRAME) {
					if (ch->frame != cl.frame.frame_num) {
						Mix_FadeOutChannel(i, 250);
						continue;
					}
				}
			}

			if (S_SpatializeChannel(ch)) {
				Mix_SetPosition(i, ch->angle, ch->dist);

				if (!ch->start_time) {
					ch->start_time = quetoo.ticks;

					if (ch->play.flags & S_PLAY_LOOP) {
						Mix_PlayChannel(i, ch->sample->chunk, -1);
					} else {
						Mix_PlayChannel(i, ch->sample->chunk, 0);
					}
				}

				s_env.num_active_channels++;
			} else {

				if (ch->start_time) {
					Mix_HaltChannel(i);
				} else {
					S_FreeChannel(i);
				}
			}
		}
	}
}
Example #14
0
	static int lua_Mix_FadeOutChannel(State & state){
		Stack * stack = state.stack;
		int channel = -1;
		int ms = 0;
		if (stack->is<LUA_TNUMBER>(1)){
			channel = stack->to<int>(1);
		}
		if (stack->is<LUA_TNUMBER>(2)){
			ms = stack->to<int>(2);
		}
		stack->push<int>(Mix_FadeOutChannel(channel, ms));
		return 1;
	}
Example #15
0
void stop_thrust(void)
{
#ifndef NOSOUND
#ifdef ARGS
	if (sound_arg)
	{
#endif
	Mix_FadeOutChannel(1,1000);
#ifdef ARGS
	}
#endif
#endif
}
  void SoundManager::launchBackGroundMusic(const std::string & filename){
    //If a background music is running
    if(m_BackgroundMusic != NULL){
      Mix_FadeOutChannel(0, 1000);
    }
    Mix_HaltChannel(0);
    destroySound(&m_BackgroundMusic);
    loadSound(&m_BackgroundMusic, filename);
    if(m_BackgroundMusic != NULL){
      	if(Mix_FadeInChannel(0, m_BackgroundMusic, -1, 1000) == -1){
	  std::cout << "SOUNDMANAGER : Impossible to play : " << filename << std::endl;
	} 
    } 
  }
Example #17
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();
	}
}
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");
  }
}
Example #19
0
/*
 *  call-seq:
 *    fade_out( fade_time )  ->  self
 *
 *  Fade out to silence over the given number of seconds. Once the sound
 *  is silent, it is automatically stopped.
 *
 *  Returns::     The receiver (self).
 *
 *  **NOTE**: If the sound is currently paused, the fade will start,
 *  but you won't be able to hear it happening unless you #unpause during
 *  the fade. Does nothing if the sound is currently stopped.
 *
 */
static VALUE rg_sound_fadeout( VALUE self, VALUE fade_time )
{
	RG_Sound *sound;
	Data_Get_Struct(self,  RG_Sound, sound);

	int channel = sound->channel;
	int fade_ms = (int)(1000 * NUM2DBL(fade_time));

	/* Make sure the sound actually belongs to the channel */
	if( _rg_sound_channel_check(sound) )
	{
		Mix_FadeOutChannel( channel, fade_ms );
	}

	return self;
}
Example #20
0
void cAudio :: FadeOutSounds( unsigned int ms /* = 200 */, int channel /* = -1 */, bool overwrite_fading /* = 0  */ )
{
	if( !bSounds || !bInitialised )
	{
		return;
	}

	if( Mix_Playing( channel ) ) // Check the Channels
	{
		if( !overwrite_fading && isSoundFading( - 1 ) == 2 )
		{
			return; // Do not fade the Sound out again
		}

		Mix_FadeOutChannel( channel, ms );
	}
}
Example #21
0
void cAudio :: Fadeout_Sounds( unsigned int ms /* = 200 */, int channel /* = -1 */, bool overwrite_fading /* = 0 */ ) const
{
	if( !m_sound_enabled || !m_initialised )
	{
		return;
	}

	// if not playing
	if( Mix_Playing( channel ) <= 0 )
	{
		return;
	}

	// Do not fade-out the sound again
	if( channel >= 0 && !overwrite_fading && Is_Sound_Fading( channel ) == MIX_FADING_OUT )
	{
		return;
	}

	Mix_FadeOutChannel( channel, ms );
}
Example #22
0
int BEE::Sound::fade_out(int ticks) {
	if (!is_loaded) {
		if (!has_play_failed) {
			game->messenger_send({"engine", "sound"}, BEE_MESSAGE_WARNING, "Failed to fade out sound \"" + name + "\" because it is not loaded");
			has_play_failed = true;
		}
		return 1;
	}

	is_playing = false;
	is_looping = false;

	if (is_music) {
		Mix_FadeOutMusic(ticks);
	} else {
		std::list<int> tmp_channels = current_channels;
		for (auto i=tmp_channels.begin(); i != tmp_channels.end(); ++i) {
			Mix_FadeOutChannel(*i, ticks);
		}
	}
	return 0;
}
Example #23
0
void reposition_sound(int id, unsigned int distance)
{
	audio_lock lock;
	for (unsigned ch = 0; ch < channel_ids.size(); ++ch)
	{
		if (channel_ids[ch] != id) continue;
		if (distance >= DISTANCE_SILENT) {
			// Don't call Mix_FadeOutChannel if the channel's volume is set to
			// zero. It doesn't do anything in that case and the channel will
			// resume playing as soon as its volume is reset to a non-zero
			// value, which results in issues like sound sources deleted while
			// their volume is zero coming back to life and escaping Wesnoth's
			// sound source management code.
			if (Mix_Volume(ch, -1) == 0) {
				Mix_HaltChannel(ch);
			} else {
				Mix_FadeOutChannel(ch, 100);
			}
		} else {
			Mix_SetDistance(ch, distance);
		}
	}
}
Example #24
0
void SdlAudio::ME_Fade(int fade) {
	Mix_FadeOutChannel(me_channel, fade);
}
Example #25
0
void SdlAudio::BGS_Fade(int fade) {
	Mix_FadeOutChannel(bgs_channel, fade);
}
Example #26
0
void VideoState::init()
{
	State::init();

	bool wasLetterboxed = CutsceneState::initDisplay();

	bool ufoIntroSoundFileDosExists = false;
	bool ufoIntroSoundFileWinExists = false;
	int prevMusicVol = Options::musicVolume;
	int prevSoundVol = Options::soundVolume;
	if (_useUfoAudioSequence)
	{
		const std::set<std::string> &soundDir = FileMap::getVFolderContents("SOUND");
		ufoIntroSoundFileDosExists = soundDir.end() != soundDir.find("intro.cat");
		ufoIntroSoundFileWinExists = soundDir.end() != soundDir.find("sample3.cat");

		if (!ufoIntroSoundFileDosExists && !ufoIntroSoundFileWinExists)
		{
			_useUfoAudioSequence = false;
		}
		else
		{
			// ensure user can hear both music and sound effects for the
			// vanilla intro sequence
			Options::musicVolume = Options::soundVolume = std::max(prevMusicVol, prevSoundVol);
			_game->setVolume(Options::soundVolume, Options::musicVolume, -1);
		}
	}
	_game->getCursor()->setVisible(false);

	int dx = (Options::baseXResolution - Screen::ORIGINAL_WIDTH) / 2;
	int dy = (Options::baseYResolution - Screen::ORIGINAL_HEIGHT) / 2;

	FlcPlayer *flcPlayer = NULL;
	for (std::vector<std::string>::const_iterator it = _videos->begin(); it != _videos->end(); ++it)
	{
		std::string videoFileName = FileMap::getFilePath(*it);

		if (!CrossPlatform::fileExists(videoFileName))
		{
			continue;
		}

		if (!flcPlayer)
		{
			flcPlayer = new FlcPlayer();
		}

		if (_useUfoAudioSequence)
		{
			audioSequence = new AudioSequence(_game->getMod(), flcPlayer);
		}

		flcPlayer->init(videoFileName.c_str(),
			 _useUfoAudioSequence ? &audioHandler : NULL,
			 _game, dx, dy);
		flcPlayer->play(_useUfoAudioSequence);
		if (_useUfoAudioSequence)
		{
			flcPlayer->delay(10000);
			delete audioSequence;
			audioSequence = NULL;
		}
		flcPlayer->deInit();

		if (flcPlayer->wasSkipped())
		{
			break;
		}
	}

	if (flcPlayer)
	{
		delete flcPlayer;
	}

	// We can only do a fade out in 8bpp, otherwise instantly end it
	bool fade = (_game->getScreen()->getSurface()->getSurface()->format->BitsPerPixel == 8);
	const int FADE_DELAY = 45;
	const int FADE_STEPS = 20;

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

	if (fade)
	{
		SDL_Color pal[256];
		SDL_Color pal2[256];
		memcpy(pal, _game->getScreen()->getPalette(), sizeof(SDL_Color) * 256);
		for (int i = FADE_STEPS; 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(FADE_DELAY);
		}
	}
	_game->getScreen()->clear();
	_game->getScreen()->flip();

	if (_useUfoAudioSequence)
	{
		Options::musicVolume = prevMusicVol;
		Options::soundVolume = prevSoundVol;
		_game->setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume);
	}

#ifndef __NO_MUSIC
	Sound::stop();
	Music::stop();
#endif

	_game->getCursor()->setVisible(true);
	CutsceneState::resetDisplay(wasLetterboxed);
	_game->popState();
}
Example #27
0
void sfx::stop_sound_effect_fade( int channel, int duration ) {
    if( Mix_FadeOutChannel( channel, duration ) == -1 ) {
        dbg( D_ERROR ) << "Failed to stop sound effect: " << Mix_GetError();
    }
}
Example #28
0
void sfx::fade_audio_channel( int tag, int duration ) {
    Mix_FadeOutChannel( tag, duration );
}
Example #29
0
/**
 * Waits a cycle to load the resources so the screen is blitted first.
 * If the loading fails, it shows an error, otherwise moves on to the game.
 */
void StartState::think()
{
	State::think();

	switch (_load)
	{
	case LOADING_STARTED:
		try
		{
			Log(LOG_INFO) << "Loading ruleset...";
			_game->loadRuleset();
			Log(LOG_INFO) << "Ruleset loaded successfully.";
			Log(LOG_INFO) << "Loading resources...";
			_game->setResourcePack(new XcomResourcePack(_game->getRuleset()->getExtraSprites(), _game->getRuleset()->getExtraSounds()));
			Log(LOG_INFO) << "Resources loaded successfully.";
			std::vector<std::string> langs = Language::getList(0);
			if (langs.empty())
			{
				throw Exception("No languages available");
			}
			_load = LOADING_SUCCESSFUL;

			// loading done? let's play intro!
			std::string introFile = CrossPlatform::getDataFile("UFOINTRO/UFOINT.FLI");
			if (Options::getBool("playIntro") && CrossPlatform::fileExists(introFile))
			{
				audioSequence = new AudioSequence(_game->getResourcePack());
				Flc::flc.realscreen = _game->getScreen();
				Flc::FlcInit(introFile.c_str());
				Flc::flc.dx = (Options::getInt("baseXResolution") - 320) / 2;
				Flc::flc.dy = (Options::getInt("baseYResolution") - 200) / 2;
				Flc::flc.loop = 0; // just the one time, please
				Flc::FlcMain(&audioHandler);
				Flc::FlcDeInit();
				delete audioSequence;


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

				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;
					}
					_game->getScreen()->setPalette(pal2, 0, 256, true);
					_game->getScreen()->flip();
					SDL_Delay(45);
				}
				_game->getScreen()->clear();
				_game->getScreen()->flip();

				_game->setVolume(Options::getInt("soundVolume"), Options::getInt("musicVolume"));

				Mix_HaltChannel(-1);
			}
		}
		catch (Exception &e)
		{
			_load = LOADING_FAILED;
			_surface->clear();
			_surface->drawString(1, 9, "ERROR:", 2);
			_surface->drawString(1, 17, e.what(), 2);
			_surface->drawString(1, 49, "Make sure you installed OpenXcom", 1);
			_surface->drawString(1, 57, "correctly.", 1);
			_surface->drawString(1, 73, "Check the requirements and", 1);
			_surface->drawString(1, 81, "documentation for more details.", 1);
			_surface->drawString(75, 183, "Press any key to quit", 1);
			Log(LOG_ERROR) << e.what();
		}
		break;
	case LOADING_NONE:
		_load = LOADING_STARTED;
		break;
	case LOADING_SUCCESSFUL:
		Log(LOG_INFO) << "OpenXcom started successfully!";
		if (Options::getString("language").empty())
		{
			_game->setState(new LanguageState(_game));
		}
		else
		{
			try
			{
				_game->loadLanguage(Options::getString("language"));
				_game->setState(new MainMenuState(_game));
			}
			catch (Exception)
			{
				_game->setState(new LanguageState(_game));
			}
		}
		break;
	default:
		break;
	}
}
Example #30
0
void Sound::fadeOutAllSound(int ms)
{
    Mix_FadeOutChannel(-1, ms);
}