Exemplo n.º 1
0
bool SDLMusic::play(const int loops, const int fadeIn)
{
    if (fadeIn > 0)
        return Mix_FadeInMusicPos(mMusic, loops, fadeIn, 0.0);
    else
        return Mix_FadeInMusicPos(mMusic, loops, 0, 0.0);
}
Exemplo n.º 2
0
bool SDLMusic::play(const int loops,
                    const int fadeIn) const
{
    if (fadeIn > 0)
        return Mix_FadeInMusicPos(mMusic, loops, fadeIn, 0.0) != 0;
    return Mix_FadeInMusicPos(mMusic, loops, 0, 0.0) != 0;
}
Exemplo n.º 3
0
void loadSamples(const char* sndDir, const char* musicFile)
{
  loadSample( packGetFile(sndDir,"click.ogg"), SND_CLICK );
  loadSample( packGetFile(sndDir,"brickmove.ogg"), SND_BRICKMOVE );
  loadSample( packGetFile(sndDir,"brickgrab.ogg"), SND_BRICKGRAB );
  loadSample( packGetFile(sndDir,"brickbreak.ogg"), SND_BRICKBREAK );
  loadSample( packGetFile(sndDir,"scoretick.ogg"), SND_SCORECOUNT );
  loadSample( packGetFile(sndDir,"countdown.ogg"), SND_COUNTDOWNTOSTART );
  loadSample( packGetFile(sndDir,"start.ogg"), SND_START );
  loadSample( packGetFile(sndDir,"timeout.ogg"), SND_TIMEOUT );
  loadSample( packGetFile(sndDir,"victory.ogg"), SND_VICTORY );
  loadSample( packGetFile(sndDir,"timeout.ogg"), SND_TIMEOUT );
  loadSample( packGetFile(sndDir,"onewaymove.ogg"), SND_ONEWAY_MOVE );
  loadSample( packGetFile(sndDir,"teleported.ogg"), SND_TELEPORTED );
  loadSample( packGetFile(sndDir,"switchactivate.ogg"), SND_SWITCH_ACTIVATED );
  loadSample( packGetFile(sndDir,"switchinactive.ogg"), SND_SWITCH_DEACTIVATED );
  loadSample( packGetFile(sndDir,"brickswap.ogg"), SND_BRICKSWAP );
  loadSample( packGetFile(sndDir,"brickcopy.ogg"), SND_BRICKCOPY );
  loadSample( packGetFile(sndDir,"brickswapdenied.ogg"), SND_BRICKSWAP );
  loadSample( packGetFile(sndDir,"brickcopydenied.ogg"), SND_BRICKCOPY );
  loadSample( packGetFile(sndDir, "winner.ogg"), SND_WINNER);
  loadSample( packGetFile(sndDir, "loser.ogg"), SND_LOSER);

  //Music load code
  if(setting()->disableMusic) return;
  if( !musicFile ) return;

  //Load ingame song if not allready loaded.
  if(strcmp(lastLoadedSongFn, packGetFile("./",musicFile))!=0 && !setting()->userMusic)
  {
    //Free old song if loaded.
    if(mus[1])
    {
      Mix_FreeMusic(mus[1]);
    }
    strcpy(lastLoadedSongFn, packGetFile("./",musicFile));
    mus[1]=Mix_LoadMUS( lastLoadedSongFn );
    if(!mus[1])
      printf("Couldn't load music: '%s'\n",packGetFile("./",musicFile));

    mPos[1] = 0.0f;

    if( !Mix_PlayingMusic() )
    {
      Mix_FadeInMusicPos(mus[1], -1, MUSIC_FADETIME,mPos[1]);
    }
  }

}
Exemplo n.º 4
0
void
sndMusic::GoToTime(float time)
{
	UNUSED(time);
	if ( m_playing )
	{
		Stop();
		//bool isMp3 = (Mix_GetMusicType(m_music) == MUS_MP3);
		//if ( isMp3 )
		//	Rewind();
		//Mix_SetMusicPosition(time);
		int loops = (m_looping)?-1:1;
		Mix_FadeInMusicPos( m_music, loops, 0, time );
		m_playing = true;
	}
}
Exemplo n.º 5
0
void soundPlayUserSongNum(int num, char* songName)
{
  if(!setting()->musicVol) return;
  listItem* it=&fileList()->begin;
  fileListItem_t* file;
  int i=0;
  while( LISTFWD(fileList(),it) )
  {
    file=(fileListItem_t*)it->data;
    if(!file->dir)
    {
      if(i==num)
      {
        //Unload current song.
        Mix_HaltMusic();
        if(mus[1])
        {
          Mix_FreeMusic(mus[1]);
          mus[1]=0;
        }
        //Load new song
        mus[1]=Mix_LoadMUS( file->fullName );
        if(!mus[1])
        {
          printf("Couldn't load music: '%s'\n",file->fullName);
        }
        else
        {
          printf("Now Playing: '%s'\n",file->fullName);
          if(songName)
          {
            showSNCD=SHOW_SONG_TIME;
            strcpy(songName,file->name);
          }
        }

        Mix_FadeInMusicPos(mus[1], 0, MUSIC_FADETIME,mPos[1]);


        //return; We don't return, instead we let it run, to count number of usertracks.
      }
      i++;
    }
  }
  numUserSongs=i;
}
Exemplo n.º 6
0
void SoundHandler::playMusic(Music::Value music)
{
	m_music = music;

	// Check that the music is loaded
	if(m_tracks.find(music) == m_tracks.end())
	{
		std::cout << "Music track " << music << " not loaded." << std::endl;
		return;
	}

	Mix_FadeInMusicPos(m_tracks[music], 0, 100, m_musicPosition);
	Mix_PauseMusic();
	Mix_HookMusicFinished([]()
	{
		m_musicPosition = 0;

		playMusic(m_music);
	});
}
Exemplo n.º 7
0
void music_play (const char *file,
                 const char *alias,
                 uint32_t rate)
{
    int audio_format = MIX_DEFAULT_FORMAT;
    int audio_channels = 2;
    int audio_buffers = 4096;

    if (!music_init_done) {
        if (Mix_OpenAudio(rate,
                          audio_format,
                          audio_channels,
                          audio_buffers) != 0) {

            MSG_BOX("Mix_OpenAudio fail: %s %s",
                    Mix_GetError(), SDL_GetError());
            SDL_ClearError();
        }

        music_init_done = true;
    }

    musicp music = music_load(file, alias);

    music_update_volume();

    static int sound_loaded;
    if (!sound_loaded) {
        sound_loaded = true;
        sound_load_all();
    }

    if (HEADLESS) {
        return;
    }

    if (Mix_FadeInMusicPos(music->music, -1, 2000, 0) == -1) {
//    if (Mix_PlayMusic(music->music, -1) == -1) {
        WARN("cannot play music %s: %s", music->tree.key, Mix_GetError());
    }
}
Exemplo n.º 8
0
	void Music::play(const int loops, const double dFadeIn, const double dPos) {
		Mix_VolumeMusic(MIX_MAX_VOLUME * getStdVolume() * m_fVolume);
		Mix_FadeInMusicPos(getMusic(), loops,
			static_cast<int> ( (dFadeIn + getStdFadeIn() ) * 1000) , dPos + getStdPos() );
	}
Exemplo n.º 9
0
/**
 * @brief Sets the music to a position in seconds.
 *
 *    @param sec Position to go to in seconds.
 */
void music_mix_setPos( double sec )
{
   if (music_music == NULL) return;

   Mix_FadeInMusicPos( music_music, 1, MUSIC_FADEIN_DELAY, sec );
}
Exemplo n.º 10
0
int Mix_PlayMusic(Mix_Music *music, int loops)
{
	return Mix_FadeInMusicPos(music, loops, 0, 0.0);
}
Exemplo n.º 11
0
int Mix_FadeInMusic(Mix_Music *music, int loops, int ms)
{
	return Mix_FadeInMusicPos(music, loops, ms, 0.0);
}
Exemplo n.º 12
0
Arquivo: midi.cpp Projeto: paud/d2x-xl
int DigiPlayMidiSong (char *pszSong, char *melodic_bank, char *drum_bank, int bLoop, int bD1Song)
{
	int	bCustom;
#if 0
if (!gameStates.sound.digi.bInitialized)
	return 0;
#endif
PrintLog ("DigiPlayMidiSong (%s)\n", pszSong);
DigiStopCurrentSong ();
if (!(pszSong && *pszSong))
	return 0;
if (midiVolume < 1)
	return 0;
bCustom = ((strstr (pszSong, ".mp3") != NULL) || (strstr (pszSong, ".ogg") != NULL));
if (!(bCustom || (hmp = hmp_open (pszSong, bD1Song))))
	return 0;
#if USE_SDL_MIXER
if (gameOpts->sound.bUseSDLMixer) {
	char	fnSong [FILENAME_LEN], *pfnSong;

	if (bCustom) {
		pfnSong = pszSong;
		if (strstr (pszSong, ".mp3") && !gameData.songs.user.bMP3) {
			DigiExit ();
			gameData.songs.user.bMP3 = 1;
			DigiInit (1);
			}
		}
	else {
		if (!strstr (pszSong, ".mp3") && gameData.songs.user.bMP3) {
			DigiExit ();
			gameData.songs.user.bMP3 = 0;
			DigiInit (1);
			}
		sprintf (fnSong, "%s/d2x-temp.mid", *gameFolders.szTempDir ? gameFolders.szTempDir : gameFolders.szHomeDir);
		if (!hmp_to_midi (hmp, fnSong)) {
			PrintLog ("SDL_mixer failed to load %s\n(%s)\n", fnSong, Mix_GetError ());
			return 0;
			}
		pfnSong = fnSong;
		}
	if (!(mixMusic = Mix_LoadMUS (pfnSong))) {
		PrintLog ("SDL_mixer failed to load %s\n(%s)\n", fnSong, Mix_GetError ());
		return 0;
		}
	if (-1 == Mix_FadeInMusicPos (mixMusic, bLoop ? -1 : 1, gameData.songs.tPos ? 1000 : 1500, (double) gameData.songs.tPos / 1000.0)) {
		PrintLog ("SDL_mixer cannot play %s\n(%s)\n", pszSong, Mix_GetError ());
		gameData.songs.tPos = 0;
		return 0;
		}
	PrintLog ("SDL_mixer playing %s\n", pszSong);
	if (gameData.songs.tPos)
		gameData.songs.tPos = 0;
	else
		gameData.songs.tStart = SDL_GetTicks ();
	
	gameData.songs.bPlaying = 1;
	DigiSetMidiVolume (midiVolume);
	return 1;
	}
#endif
#if defined (_WIN32)
if (bCustom) {
	PrintLog ("Cannot play %s - enable SDL_mixer\n", pszSong);
	return 0;
	}
hmp_play (hmp, bLoop);
gameData.songs.bPlaying = 1;
DigiSetMidiVolume (midiVolume);
#endif
return 1;
}
Exemplo n.º 13
0
void soundRun(SDL_Surface* screen,int state)
{
  //Wiz-Volume control
  #if defined (GP2X) || defined (WIZ)
  if(getButton( C_BTNVOLUP ) )
  {
    resetBtn( C_BTNVOLUP );
    WIZ_AdjustVolume(VOLUME_UP);
  } else if(getButton( C_BTNVOLDOWN ) )
  {
    resetBtn( C_BTNVOLDOWN );
    WIZ_AdjustVolume(VOLUME_DOWN);
  }
  WIZ_ShowVolume(screen);
  #endif

  //Rest of code controls music, we return now if music is not playing.
  if( !setting()->musicVol || setting()->disableMusic ) return;

  if(setting()->userMusic && numUserSongs)
  {
    //Check if we should change track because the track stopped
    if(!Mix_PlayingMusic())
    {
      userSong++;
      if(userSong==numUserSongs)
        userSong=0;

      soundPlayUserSongNum(userSong, lastLoadedSongFn);
    }

    //Change track because player wants to
    if(getButton(C_SHOULDERA))
    {
      resetBtn(C_SHOULDERA);
      userSong++;
      if(userSong==numUserSongs)
        userSong=0;
      soundPlayUserSongNum(userSong, lastLoadedSongFn);
    }
    if(getButton(C_SHOULDERB))
    {
      resetBtn(C_SHOULDERB);
      userSong--;
      if(userSong<0)
        userSong=numUserSongs-1;
      soundPlayUserSongNum(userSong, lastLoadedSongFn);
    }

    //Should we show the song title?
    if(showSNCD>0)
    {
      showSNCD-=getTicks();
      txtWriteCenter(screen, FONTSMALL, lastLoadedSongFn, HSCREENW, HSCREENH+80);
    }

  } else {
    if(showSNCD>0)
    {
      showSNCD-=getTicks();
      txtWriteCenter(screen, FONTSMALL, "Select Music Directory in Options", HSCREENW, HSCREENH+80);
    } else if(getButton(C_SHOULDERA) || getButton(C_SHOULDERB))
    {
      resetBtn(C_SHOULDERA);
      resetBtn(C_SHOULDERB);
      showSNCD=3000;
    }

    if(fadeOut > 0)
    {
      fadeOut -= getTicks();
      if(fadeOut < 0)
      {
        fadeOut=0,
        lastState=state;

        switch(state)
        {
          case STATEPLAY:
            cmState=CMSTATE_GAME;
            Mix_FadeInMusicPos(mus[1], -1, MUSIC_FADETIME,mPos[1]);
          break;
          case STATEMENU:
            cmState=CMSTATE_MENU;
            Mix_FadeInMusicPos(mus[0], -1, MUSIC_FADETIME,mPos[0]);
          break;
        }
      }
    }

    if(lastState!=state && fadeOut == 0 )
    {
        //We won't change the music the menuparts which are logically "ingame".
        if( !( getMenuState() == menuStateFinishedLevel || (getMenuState() == menuStateNextLevel && cmState==CMSTATE_GAME) ) )
        {
          fadeOut = MUSIC_FADETIME+20; //We add an extra frames time to make sure the previous fade was completed.
          Mix_FadeOutMusic(MUSIC_FADETIME);
        }
    }

    switch(lastState)
    {
      case STATEPLAY:
        mPos[1] += (double)getTicks() / 1000.0f;
      break;
      case STATEMENU:
        mPos[0] += (double)getTicks() / 1000.0f;
      break;
    }
  }//In-Game music

}
Exemplo n.º 14
-1
Arquivo: midi.cpp Projeto: paud/d2x-xl
int CMidi::PlaySong (char* pszSong, char* melodicBank, char* drumBank, int bLoop, int bD1Song)
{
#if (defined (_WIN32) || USE_SDL_MIXER)
	int	bCustom;

PrintLog ("DigiPlayMidiSong (%s)\n", pszSong);
audio.StopCurrentSong ();
if (!(pszSong && *pszSong))
	return 0;
if (m_nVolume < 1)
	return 0;

bCustom = ((strstr (pszSong, ".mp3") != NULL) || (strstr (pszSong, ".ogg") != NULL));
if (bCustom) {
	if (audio.Format () != AUDIO_S16LSB) {
		audio.Shutdown ();
		audio.Setup (1, AUDIO_S16LSB);
		}
	}
else if (!(m_hmp = hmp_open (pszSong, bD1Song)))
	return 0;

#	if USE_SDL_MIXER
if (gameOpts->sound.bUseSDLMixer) {
	char	fnSong [FILENAME_LEN], *pfnSong;

	if (bCustom) {
		pfnSong = pszSong;
		if (strstr (pszSong, ".mp3") && !songManager.MP3 ()) {
			audio.Shutdown ();
			songManager.SetMP3 (1);
			audio.Setup (1);
			}
		}
	else {
		if (!strstr (pszSong, ".mp3") && songManager.MP3 ()) {
			audio.Shutdown ();
			songManager.SetMP3 (0);
			audio.Setup (1);
			}
#if defined (_WIN32)
		sprintf (fnSong, "%s/d2x-temp.mid", *gameFolders.szCacheDir ? gameFolders.szCacheDir : gameFolders.szHomeDir);
#else
		sprintf (fnSong, "%s/d2x-temp.mid", *gameFolders.szCacheDir ? gameFolders.szCacheDir : gameFolders.szHomeDir);
#endif
		if (!hmp_to_midi (m_hmp, fnSong)) {
			PrintLog ("SDL_mixer failed to load %s\n(%s)\n", fnSong, Mix_GetError ());
			return 0;
			}
		pfnSong = fnSong;
		}
	if (!(m_music = Mix_LoadMUS (pfnSong))) {
		PrintLog ("SDL_mixer failed to load %s\n(%s)\n", fnSong, Mix_GetError ());
		return 0;
		}
	if (-1 == Mix_FadeInMusicPos (m_music, bLoop ? -1 : 1, songManager.Pos () ? 1000 : 1500, (double) songManager.Pos () / 1000.0)) {
		PrintLog ("SDL_mixer cannot play %s\n(%s)\n", pszSong, Mix_GetError ());
		songManager.SetPos (0);
		return 0;
		}
	PrintLog ("SDL_mixer playing %s\n", pszSong);
	if (songManager.Pos ())
		songManager.SetPos (0);
	else
		songManager.SetStart (SDL_GetTicks ());
	
	songManager.SetPlaying (1);
	SetVolume (m_nVolume);
	return 1;
	}
#	endif
#	if defined (_WIN32)
if (bCustom) {
	PrintLog ("Cannot play %s - enable SDL_mixer\n", pszSong);
	return 0;
	}
hmp_play (m_hmp, bLoop);
songManager.SetPlaying (1);
SetVolume (m_nVolume);
#	endif
#endif
return 1;
}