Beispiel #1
0
void SoundProcessor::playMusic(boost::shared_ptr<const Music> play_music, const bool loop)
{

#ifdef _FMOD_SOUND
	BOOST_ASSERT(soundEngine);

	if(musicChannel) {
		musicChannel->stop();
	}
	soundEngine->playSound(FMOD_CHANNEL_FREE, play_music->getData(), 0, &musicChannel);

#elif _SDL_MIXER_SOUND

	bool success = false;

	// music currently playing?
	if(currentMusic != NULL)
	{
		// new music?
		if(play_music != NULL) {
			if(loop) {
				nextMusic = currentMusic;
			} else {
				nextMusic = NULL;
			}
			// transition between both music plays
			Mix_HookMusicFinished(::transitionMusic);
			success = (Mix_FadeOutMusic(MUSIC_TRANSITION_DURATION/2) == 1);
		} else 
			// empty music => Stop music, just fade out
		{
			success = (Mix_FadeOutMusic(MUSIC_TRANSITION_DURATION) == 1);
		}
	} else 
		// no music was playing
	{
		if(play_music != NULL)
		{
			currentMusic = play_music->getData();
			if(loop) {
				nextMusic = currentMusic;
			} else {
				nextMusic = NULL;
			}

			Mix_HookMusicFinished(::transitionMusic);
			success = (Mix_FadeInMusic(currentMusic, -1, MUSIC_TRANSITION_DURATION) == 0);
		} else {
			// no music played, no music to play
			success = true;
		}
	}

	if(!success) {
		std::ostringstream os;
		os << "ERROR (SoundProcessor::playMusic()): " << Mix_GetError() << "[" << play_music->getFileName() << "]";
		toErrorLog(os.str());
	}
#endif
}
Beispiel #2
0
int snd_play_mus(char *fname, int ms, int loop)
{
	if (!sound_on)
		return 0;
	if (snd_playing_mus()) {
		if (next_mus) {
			free(next_mus);
		}
		next_mus = strdup(fname);
		next_fadein = ms;
		next_loop = loop;
		if (!timer_id)
			timer_id = SDL_AddTimer(200, callback, NULL);
		return 1;
	}
	if (mus)
		snd_free_mus(mus);

	mus = snd_load_mus(fname);
	if (!mus)
		return -1;
	if (loop >= 0)
		Mix_HookMusicFinished(game_music_finished);
	else
		Mix_HookMusicFinished(NULL);
	if (ms)
		Mix_FadeInMusic(mus->mus, loop, ms);
	else
		Mix_PlayMusic(mus->mus, loop);
	snd_volume_mus(snd_volume_mus(-1)); /* SDL hack? */
	return 0;
}
Beispiel #3
0
void CMusicHandler::init()
{
	CAudioBase::init();

	if (initialized)
		Mix_HookMusicFinished(musicFinishedCallbackC);
}
Beispiel #4
0
Sound::~Sound()
{
    config.removeListeners(this);

    // Unlink the callback function.
    Mix_HookMusicFinished(nullptr);
}
Beispiel #5
0
/**
 * Play music.
 * @param file path to music file (i.e. *.ogg)
 * @param finished send this message when music is finished.
 * If finished is NULL, play music forever.
 */
void
SDLSoundAgent::playMusic(const Path &file,
        BaseMsg *finished)
{
    // The same music is not restarted when it is not needed.
    if (m_playingPath == file.getPosixName()
            && ms_finished == NULL && finished == NULL) {
        return;
    }

    stopMusic();
    m_playingPath = file.getPosixName();

    if (finished) {
        ms_finished = finished;
        m_music = Mix_LoadMUS(file.getNative().c_str());
        if (m_music && (0 == Mix_PlayMusic(m_music, 1))) {
            Mix_HookMusicFinished(musicFinished);
        }
        else {
            LOG_WARNING(ExInfo("cannot play music")
                    .addInfo("music", file.getNative())
                    .addInfo("Mix", Mix_GetError()));
        }
    }
    else {
        m_looper = new SDLMusicLooper(file);
        m_looper->setVolume(m_musicVolume);
        m_looper->start();
    }
}
Beispiel #6
0
void SoundHandler::stopMusic()
{
	m_musicPosition = 0;

	Mix_HookMusicFinished(nullptr);
	Mix_FadeOutMusic(1000);
}
Beispiel #7
0
void handleKey(SDL_KeyboardEvent key) {
	switch(key.keysym.sym) {
  case SDLK_p:

	  if(key.type == SDL_KEYDOWN) {

		  if(phaserChannel < 0) {
			  phaserChannel = Mix_PlayChannel(-1, phaser, -1);
		  }
	  } else {
		  Mix_HaltChannel(phaserChannel);

		  phaserChannel = -1;
	  }
	  break;

  case SDLK_m:
	  if(key.state == SDL_PRESSED) {

		  if(music == NULL) {

			  music = Mix_LoadMUS("music.ogg");
			  Mix_PlayMusic(music, 0);
			  Mix_HookMusicFinished(handleKey);

		  } else {
			  Mix_HaltMusic();
			  Mix_FreeMusic(music);
			  music = NULL;
		  }
	  }
	  break;
	}
}
Beispiel #8
0
///////////////////////////////////////////////////////////
// BGM stop
///////////////////////////////////////////////////////////
void Audio::BGM_Stop() {
	if (bgm_playing) {
		Mix_HaltMusic();
		bgm_playing = false;
	}
	Mix_HookMusicFinished(NULL);
}
Beispiel #9
0
static bool Init()
{
   if (!gSDLIsInit)
   {
      ELOG("Please init Stage before creating sound.");
      return false;
   }

   if (!sChannelsInit)
   {
      sChannelsInit = true;
      for(int i=0;i<sMaxChannels;i++)
      {
         sUsedChannel[i] = false;
         sDoneChannel[i] = false;
      }
      Mix_ChannelFinished(onChannelDone);
      Mix_HookMusicFinished(onMusicDone);
      #ifndef EMSCRIPTEN
      Mix_SetPostMix(onPostMix,0);
      #endif
   }

   return sChannelsInit;
}
Beispiel #10
0
///////////////////////////////////////////////////////////
// ME finish callback
///////////////////////////////////////////////////////////
void Audio::ME_finish() {
	Mix_VolumeMusic(Audio::bgm_volume);
	Mix_FadeInMusic(Audio::bgm, -1, 1000);
	Audio::bgm_playing = true;
	Audio::me_playing = false;
	Mix_HookMusicFinished(NULL);
}
Beispiel #11
0
///////////////////////////////////////////////////////////
// BGM fade
///////////////////////////////////////////////////////////
void Audio::BGM_Fade(int fade) {
	if (bgm_playing) {
		Mix_FadeOutMusic(fade);
		bgm_playing = false;
	}
	Mix_HookMusicFinished(NULL);
}
Beispiel #12
0
/**
 *  Treiberinitialisierungsfunktion.
 *
 *  @return @p true bei Erfolg, @p false bei Fehler
 *
 *  @author FloSoft
 */
bool AudioSDL::Initialize(void)
{
	if( SDL_InitSubSystem( SDL_INIT_AUDIO ) < 0 )
	{
		fprintf(stderr, "%s\n", SDL_GetError());
		initialized = false;
		return false;
	}

	// open 44.1KHz, signed 16bit, system byte order,
	// stereo audio, using 1024 byte chunks
	if(Mix_OpenAudio(44100, AUDIO_S16LSB, 2, 4096) < 0)
	{
		fprintf(stderr, "%s\n", Mix_GetError());
		initialized = false;
		return false;
	}

	Mix_AllocateChannels(CHANNEL_COUNT);
	Mix_SetMusicCMD(NULL);
	Mix_HookMusicFinished(AudioSDL::MusicFinished);

	initialized = true;

	return initialized;
}
Beispiel #13
0
void music_thinker::process(events::pump_info &info) {
	if(preferences::music_on()) {
		if(!music_start_time && !current_track_list.empty() && !Mix_PlayingMusic()) {
			// Pick next track, add ending time to its start time.
			current_track = choose_track();
			music_start_time = info.ticks();
			no_fading=true;
			fadingout_time=0;
		}

		if(music_start_time && info.ticks(&music_refresh, music_refresh_rate) >= music_start_time - fadingout_time) {
			want_new_music=true;
		}

		if(want_new_music) {
			if(Mix_PlayingMusic()) {
				Mix_FadeOutMusic(fadingout_time);
			}

			unload_music = false;
			play_new_music();
		}
	}

	if (unload_music) {
		for (auto track : music_cache) {
			Mix_FreeMusic(track.second);
		}
		music_cache.clear();

		Mix_HookMusicFinished(nullptr);

		unload_music = false;
	}
}
void SDLSound::playMusic(const char* directory)
{
    // Part1: scan directory for music files
    char **list = filesystem::enumerateFiles(directory);
    setMusicVolume(gameconfig->sound.getMusicVol());

    musicfiles.clear();
    for (char **i = list; *i != NULL; i++) {
        std::string filename = directory;
        filename.append(*i);
        if (!filesystem::isDirectory(filename.c_str())) {
            musicfiles.push_back(filename);
        }
    }
    filesystem::freeList(list);

    if(musicfiles.size() == 0) {
        LOGGER.info("Couldn't find any music in '%s'", directory);
        return;
    }

    // Part2: play music :)
    currentsong = musicfiles.end();
    nextSong();
    Mix_HookMusicFinished(nextSong);
}
Beispiel #15
0
void init_music_subsystem(void)
{
	// set this to any of 512,1024,2048,4096 the higher it is, the more FPS shown and CPU needed
	s32b audio_buffers = 512;

	/* Should we do sounds ? */
	esettings_get_int("audio.music.enable", 1);
	esettings_get_int("audio.effects.enable", 1);
	if (!esettings_get_int("audio.enable", 1))
	{
		sound_not_available = TRUE;
		return;
	}

	// initialize SDL_net
	if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, audio_buffers) == -1)
	{
		sound_not_available = TRUE;
		return;
	}

	Mix_VolumeMusic(SDL_MIX_MAXVOLUME);
	Mix_Volume(-1, SDL_MIX_MAXVOLUME);

#ifdef USE_SDL
	if (!strcmp(ANGBAND_SYS, "sdl"))
	{
		Mix_HookMusicFinished(music_finished);
		Mix_ChannelFinished(channel_finished);
	}
#endif

	sound_not_available = FALSE;
}
Beispiel #16
0
void Audio::startTrack(const std::string &trackName)
{
    //std::cout << "startTrack()" << std::endl;
	stopTrack();	//stop any existing music

	if (_opt._bMusic && trackName.length() > 0)
	{
		printf("Play: %s\n", trackName.c_str());
		std::string newTrack = _baseTrackDir + "/" + trackName;
        Mix_FreeMusic(_musicTrack);
		_musicTrack = Mix_LoadMUS(newTrack.c_str());
		if(_musicTrack)
		{
			Mix_PlayMusic(_musicTrack, 1);
			_bPlayingTrack = isActuallyPlayingMusic();	//actualy playing?
		}
		else
			printf("Failed to start track %s (%s)\n", newTrack.c_str(), Mix_GetError());

		Mix_HookMusicFinished(AudioTrackDone);	//reiterate callback
	}
	if (!_bPlayingTrack)
	{
		//TODO: play fail sound
	}
}
void SDLSound::playMusic(const char* directory)
{
    // Part1: scan directory for music files
    char **list = FileSystem::enumerateFiles(directory);

    musicfiles.clear();
    for (char **i = list; *i != NULL; i++) {
        std::string filename = directory;
        filename.append(*i);
        if (!FileSystem::isDirectory(filename.c_str())) {
            musicfiles.push_back(filename);
        }
    }
    FileSystem::freeList(list);

    if(musicfiles.size() == 0) {
        LOG (("Not found any music in '%s'", directory));
        return;
    }

    // Part2: play music :)
    currentsong = musicfiles.end();
    nextSong();
    Mix_HookMusicFinished(nextSong);
}
void SDLSound::stopMusic()
{
    // nicely fade the music out for 1 second
    if(Mix_PlayingMusic()) {
        Mix_HookMusicFinished(0);
        Mix_FadeOutMusic(500);
    }
}
Beispiel #19
0
	void operator ()()
	{
	

		while (Flc::flc.FrameCount >= introSoundTrack[trackPosition].frameNumber)
		{
			int command = introSoundTrack[trackPosition].sound;

			if (command & 0x200)
			{
#ifndef __NO_MUSIC
				switch(command)
				{
				case 0x200:
					Log(LOG_DEBUG) << "Playing gmintro1";
					m = rp->getMusic("GMINTRO1");
					m->play(1);
					break;
				case 0x201:
					Log(LOG_DEBUG) << "Playing gmintro2";
					m = rp->getMusic("GMINTRO2");
					m->play(1);
					break;
				case 0x202:
					Log(LOG_DEBUG) << "Playing gmintro3";
					m = rp->getMusic("GMINTRO3");
					m->play(1);
					Mix_HookMusicFinished(musicDone);
					break;
				}
#endif		
			}
			else if (command & 0x400)
			{
				Flc::flc.HeaderSpeed = (1000.0/70.0) * (command & 0xff);
				Log(LOG_DEBUG) << "Frame delay now: " << Flc::flc.HeaderSpeed;
			}
			else if (command <= 0x19)
			{
				for (soundInFile **sounds = introSounds; *sounds; ++sounds) // try hybrid sound set, then intro.cat or sample3.cat alone
				{
					soundInFile *sf = (*sounds) + command;
					int channel = trackPosition % 4; // use at most four channels to play sound effects
					Log(LOG_DEBUG) << "playing: " << sf->catFile << ":" << sf->sound << " for index " << command; 
					s = rp->getSound(sf->catFile, sf->sound);
					if (s)
					{
						s->play(channel);
						Mix_Volume(channel, sf->volume);
						break;
					}
					else Log(LOG_DEBUG) << "Couldn't play " << sf->catFile << ":" << sf->sound;
				}
			}
			++trackPosition;
		}

	}
Beispiel #20
0
void SoundManager::shutdown()
{
    config.removeListeners(this);

    // Unlink the callback function.
    Mix_HookMusicFinished(nullptr);

    CHECKLISTENERS
}
Beispiel #21
0
		SCSerror SCSmixer::Init (const SCSint iSampleLimit, const SCSint iPlaybackQuality)
		{
			if (Mix_OpenAudio(iPlaybackQuality, AUDIO_DEFAULT_FORMAT, 2, 1024) < 0) return scsHandleError(SCS_ERROR_AUDIO | SCS_ERROR_OPEN | SCS_ERROR_MIXER);
			if (iSampleLimit < 0) return scsHandleError(SCS_ERROR_AUDIO | SCS_ERROR_CREATE | SCS_ERROR_MIXER | SCS_ERROR_INVALID);
			m_iSampleLimit = iSampleLimit;
			Mix_AllocateChannels(iSampleLimit);
			Mix_HookMusicFinished(SetTrackFinished);

			return SCS_ERROR_NONE;
		}
Beispiel #22
0
void snd_stop_mus(int ms)
{
	if (!sound_on)
		return;
	Mix_HookMusicFinished(NULL);
	if (ms)
		Mix_FadeOutMusic(ms);
	else
		Mix_HaltMusic();
}
Beispiel #23
0
///////////////////////////////////////////////////////////
// BGM play
///////////////////////////////////////////////////////////
void Audio::BGM_Play(std::string file, int volume, int pitch) {
	std::string path = FileFinder::FindMusic(file);
	if (path.empty()) ARGSS::AError::FileNotFound(file);

	if (bgm != NULL) Mix_FreeMusic(bgm);

	bgm = Mix_LoadMUS(path.c_str());
	if (!bgm) ARGSS::AError::AudioNotLoad("BGM", file, Mix_GetError());

	bgm_volume = volume * MIX_MAX_VOLUME / 100;
	if (me_playing) {
		Mix_HookMusicFinished(ME_finish);
	} else {
		bgm_playing = true;
		Mix_VolumeMusic(bgm_volume);
		if (Mix_PlayMusic(bgm, -1) == -1) ARGSS::AError::AudioNotPlay("BGM", file, Mix_GetError());

		Mix_HookMusicFinished(NULL);
	}
}
Beispiel #24
0
/**
 * @brief Frees the current playing music.
 */
void music_mix_free (void)
{
   if (music_music != NULL) {
      Mix_HookMusicFinished(NULL);
      Mix_HaltMusic();
      Mix_FreeMusic(music_music);
      /*SDL_FreeRW(music_rw);*/ /* FreeMusic frees it itself */
      music_music = NULL;
      music_rw    = NULL;
   }
}
	void action(const gcn::ActionEvent& actionEvent)
	{
		g_bPlayEnd = false;
		Mix_HookMusicFinished(0);
		std::string str;


		// Here we use the widget pointer to check which widget the action
		// originated from.
		if (actionEvent.getSource() == m_pWidgetsContainer->m_pListBoxScrollArea)
		{
			
		}
		if (actionEvent.getSource() == m_pWidgetsContainer->m_pListBox)
		{
			int selected = m_pWidgetsContainer->m_pListBox->getSelected();
			m_selected = selected;
			std::string szMidFile = "assets/";
			szMidFile += m_pWidgetsContainer->m_pListBox->getListModel()->getElementAt(selected);

			if (m_pMusic)
			{
				Mix_HaltMusic();
				Mix_FreeMusic(m_pMusic);
				m_pMusic = 0;
			}
			
			m_pMusic = Mix_LoadMUS(szMidFile.c_str());

			if (m_pMusic == 0)
			{				
				return;
			}			

			Mix_PlayMusic(m_pMusic, 1); //Music loop=1
			Mix_HookMusicFinished(musicDone);
			m_bMusicPlaying = true;
			
			
		}
	}
Beispiel #26
0
void loopbackMusic()
{
	if (current != NULL) {
		nowPlaying = Mix_LoadMUS(current);
		
		if (nowPlaying == NULL) {
			printf("Mix_LoadMUS(\"%s\"): %s\n", current, Mix_GetError());
		} else {
			Mix_PlayMusic(nowPlaying, 1);
			Mix_HookMusicFinished(loopbackMusic);
		}
	}
}
Beispiel #27
0
/**
 * @brief Loads the music by name.
 *
 *    @param name Name of the file to load.
 */
int music_mix_load( const char* name, SDL_RWops *rw )
{
   (void) name;

   /* Load the data */
   music_rw = rw;
#if SDL_VERSION_ATLEAST(2,0,0)
   music_music = Mix_LoadMUS_RW(music_rw, 1);
#else /* SDL_VERSION_ATLEAST(2,0,0) */
   music_music = Mix_LoadMUS_RW(music_rw);
#endif /* SDL_VERSION_ATLEAST(2,0,0) */
   if (music_music == NULL) {
      WARN("SDL_Mixer: %s", Mix_GetError());
      Mix_HookMusicFinished(music_rechoose);
      return -1;
   }

   /* Rechoose music on finish. */
   Mix_HookMusicFinished(music_rechoose);

   return 0;
}
bool AudioManagerSDL::Init()
{
	// we'll use SDL_Mixer to do all our sound playback. 
	// It's a simple system that's easy to use. The most 
	// complicated part about using SLD_Mixer is initting it. So 
	// let's talk about that. 
	// this is the function definition:
	// Mix_OpenAudio(int frequency, Uint16 format, int channels, int chunksize);
	// here's what it wants:
	// 
	// frequency: this is the sample rate you want the audio to
	// play at. On the Palm, things are optimized for 44100 samples per
	// second (CD quality). Though you can send in whatever sample rate you like.
	// 
	// format: For the Palm, you should use AUDIO_S16
	// 
	// channels: 1 for mono. 2 for stereo
	// 
	// chunksize: How big one audio buffer is, in bytes.
	// 
	// this example has the recommended settings for initting the mixer:

	int rate = 44100;
	Uint16 format = AUDIO_S16;
	int channels = 2;
	int bufferSize = 1024;
	
	if ( Mix_OpenAudio(rate, format, channels, bufferSize) )
	{
		// we had an error opening the audio
		LogMsg("unable to open Audio! Reason: %s\n", Mix_GetError());
		return false;

	}

	// SDL mixer requires that you specify the maximum number of simultaneous
	// sounds you will have. This is done through the function Mix_AllocateChannels. 
	// We'll need an answer for that. A channel has very little overhead,
	// so we'll arbitrarily allocate 16 channels (even though we're only using
	// 1 actual sound channel). Among other things, we need a channel per unique
	// simultaneous sound playback. So if we play the same sound 4 times, and have
	// 4 copies of the sound playing from different start times, we need four channels.
	// Note - streamed music does not consume a channel. Only sound playback does.
	// So why allocate more than we need? Because it's such a small overhead, and
	// later we don't need to come and revisit this every time we add a new sound. 
	Mix_AllocateChannels(NUM_CHANNELS);

	Mix_HookMusicFinished(musicFinishedCallback);

	return true;
}
Beispiel #29
0
void CMusicHandler::release()
{
	if (initialized)
	{
		boost::mutex::scoped_lock guard(musicMutex);

		Mix_HookMusicFinished(nullptr);

		current.reset();
		next.reset();
	}

	CAudioBase::release();
}
Beispiel #30
0
Sound::Sound():
    mInstalled(false),
    mSfxVolume(100),
    mMusicVolume(60),
    mMusic(nullptr),
    mPlayBattle(false),
    mPlayGui(false),
    mPlayMusic(false),
    mGuiChannel(-1)
{
    // This set up our callback function used to
    // handle fade outs endings.
    sFadingOutEnded = false;
    Mix_HookMusicFinished(fadeOutCallBack);
}