Exemple #1
0
void SdlAudio::BGM_Play(std::string const& file, int volume, int /* pitch */, int fadein) {
	if (file.empty() || file == "(OFF)")
	{
		BGM_Stop();
		return;
	}

	std::string const path = FileFinder::FindMusic(file);
	if (path.empty()) {
		//HACK: Polish RTP translation replaced (OFF) reserved string with (Brak)
		if (file != "(Brak)")
			Output::Warning("Music not found: %s", file.c_str());
		BGM_Stop();
		return;
	}

	SDL_RWops *rw = SDL_RWFromFile(path.c_str(), "rb");
#if SDL_MIXER_MAJOR_VERSION>1
	bgm.reset(Mix_LoadMUS_RW(rw, 1), &Mix_FreeMusic);
#else
	bgm.reset(Mix_LoadMUS_RW(rw), &Mix_FreeMusic);
#endif
	if (!bgm) {
		Output::Warning("Couldn't load %s BGM.\n%s\n", file.c_str(), Mix_GetError());
		return;
	}
#if SDL_MAJOR_VERSION>1
	// SDL2_mixer produces noise when playing wav.
	// Workaround: Use Mix_LoadWAV
	// https://bugzilla.libsdl.org/show_bug.cgi?id=2094
	if (bgs_playing) {
		BGS_Stop();
	}
	if (Mix_GetMusicType(bgm.get()) == MUS_WAV) {
		BGM_Stop();
		BGS_Play(file, volume, 0, fadein);
		return;
	}
#endif

	BGM_Volume(volume);
	if (!me_stopped_bgm &&
#ifdef _WIN32
	    (Mix_GetMusicType(bgm.get()) == MUS_MID && WindowsUtils::GetWindowsVersion() >= 6
	     ? Mix_PlayMusic(bgm.get(), -1) : Mix_FadeInMusic(bgm.get(), -1, fadein))
#else
	     Mix_FadeInMusic(bgm.get(), -1, fadein)
#endif
	     == -1) {
		Output::Warning("Couldn't play %s BGM.\n%s\n", file.c_str(), Mix_GetError());
		return;
	}
}
Exemple #2
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 OS_playMusic(int id)
{
	if(!OS_sound_On)
		return;

	if (id == OS_music_theme)
		Mix_FadeInMusic(music_theme, -1, 0);

	if (id == OS_music_success)
		Mix_FadeInMusic(music_success, 0, 0);

	if (id == OS_music_failure)
		Mix_FadeInMusic(music_failure, 0, 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
}
Exemple #5
0
void musicInit(void)
{
    fprintf(stderr, "(Music) Initializing audio...");
    if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1)
    {
        fprintf(stderr, "\tFailed.\n"
                "(Music) Error initializing audio: %s\n", Mix_GetError());
        return;
    }
    fprintf(stderr, "\tSuccess!\n(Music) Loading music...");
    bgm = Mix_LoadMUS("bgm.mp3");
    if (!bgm)
    {
        fprintf(stderr, "\tLoad failed, proceeding without music.\n"
                "(Music) Error was: %s\n", Mix_GetError());
        return;
    }
    fprintf(stderr, "\tSuccess!\nStarting music...");
    if (Mix_FadeInMusic(bgm, -1, 500) < 0)
    {
        fprintf(stderr, "\tError Mix_FadeInMusic: %s\n", Mix_GetError());
        return;
    }
    fprintf(stderr, "\tSuccess!\n");

}
Exemple #6
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;
}
Exemple #7
0
void I_PlaySong(int handle, int looping)
{
  printf("Playing song %d (%d loops)\n", handle, looping);
  if ( music[handle] ) {
    Mix_FadeInMusic(music[handle], looping ? -1 : 0, 500);
  }
}
Exemple #8
0
int BEE::Sound::fade_in(int ticks) {
	if (!is_loaded) {
		if (!has_play_failed) {
			game->messenger_send({"engine", "sound"}, BEE_MESSAGE_WARNING, "Failed to fade in sound \"" + name + "\" because it is not loaded");
			has_play_failed = true;
		}
		return 1;
	}

	if (is_music) {
		Mix_FadeInMusic(music, 1, ticks);
	} else {
		int c = Mix_FadeInChannel(-1, chunk, 0, ticks);
		if (c >= 0) {
			current_channels.remove(c);
			current_channels.push_back(c);
		} else {
			game->messenger_send({"engine", "sound"}, BEE_MESSAGE_WARNING, "Failed to play sound \"" + name + "\": " + Mix_GetError());
			return 1;
		}

		set_pan_internal(c);
		effect_set(c, sound_effects);
	}

	is_playing = true;
	is_looping = false;

	return 0;
}
Exemple #9
0
void  PGE_MusPlayer::MUS_playMusicFadeIn(int ms)
{
    if(!isLoaded) return;
	if(play_mus)
    {
		if(Mix_PausedMusic()==0)
		{
			// Reset music sample count
			if (SDL_LockMutex(sampleCountMutex) == 0)
			{
				musSCount = 0;
				SDL_UnlockMutex(sampleCountMutex);
			}

			if(Mix_FadingMusic()!=MIX_FADING_IN)
				if(Mix_FadeInMusic(play_mus, -1, ms)==-1)
				{
                    PGE_MsgBox::warn(std::string(std::string("Mix_FadeInMusic:")+std::string(Mix_GetError())).c_str());
				}
		}
		else
			Mix_ResumeMusic();

    }
    else
    {
        PGE_MsgBox::warn(std::string(std::string("Play nothing:")+std::string(Mix_GetError())).c_str());
    }
}
Exemple #10
0
bool SDLMusic::play(const int loops, const int fadeIn)
{
    if (fadeIn > 0)
        return Mix_FadeInMusic(mMusic, loops, fadeIn);
    else
        return Mix_PlayMusic(mMusic, loops);
}
Exemple #11
0
/**
 * @brief Plays the loaded music.
 */
void music_mix_play (void)
{
   if (music_music == NULL) return;

   if (Mix_FadeInMusic( music_music, 0, MUSIC_FADEIN_DELAY ) < 0)
      WARN("SDL_Mixer: %s", Mix_GetError());
}
Exemple #12
0
EXPORT void op_init_game(pdata data,pgameinfo gameinfo)
{
    //Text initialisieren
    data->text.texture=gameinfo->texttexture;
    int a;
    for (a=0; a<256; a++)
        data->text.breite[a]=gameinfo->textwidth[a];

    //Gameinforeferenzpointer speicher:
    data->gameinfo=gameinfo;

    char buffer[1024];

    //Ton vorbereiten
    sprintf(buffer,"%ssounds/Vegas Glitz.ogg",gameinfo->datafolder);
    data->backgroundmusic = Mix_LoadMUS(buffer);
    data->old_music_volume=Mix_VolumeMusic((int)(trunc(96.0*gameinfo->volume)));
    Mix_FadeInMusic(data->backgroundmusic,-1,500);


    //Spiel ansich vorbereiten
    data->step=0;
    data->fade=1;
    data->countdown=3000;
}
Exemple #13
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);
}
Exemple #14
0
int load_files()
{
    background = IMG_Load ( "background.jpg" );

    font = TTF_OpenFont( "CALIFI.ttf", 30 );

    if( background == NULL )
    {
        return false;
    }

    if( font == NULL )
    {
        return false;
    }

    music = Mix_LoadMUS( "music.mp3" );

    if( music == NULL )
    {
        return false;
    }

    if(Mix_FadeInMusic(music,0,2000)==-1)
    {
        printf("Mix_FadeInMusic: %s\n", Mix_GetError());
    }

    return true;
}
	void Music::Play()
	{
		if ( !buffer )
			return;

		Mix_FadeInMusic( buffer, (isLoop ? -1 : 1), 100 );
		Music::currentlyPlaying = this;
	}
Exemple #16
0
/* Play sound */
void CSound::Play(int dwNumOfRepeats)
{
    if(Mix_FadeInMusic(mp3Audio,0,3000) ==  -1)
    {
        gApplicationLog.printf("\nCSound::Play() - MixPlayMusic() FAILED.");
    }

}
Exemple #17
0
static mrb_value
mrb_sdl2_mixer_music_fade_in_pos(mrb_state *mrb, mrb_value self)
{
  Mix_Music *c;
  mrb_int loops, ms, pos;
  mrb_get_args(mrb, "iii", &loops, &ms, &pos);
  c = mrb_sdl2_music_get_ptr(mrb, self);
  return mrb_fixnum_value(Mix_FadeInMusic(c, loops, ms));
}
Exemple #18
0
void CSoundPlayer::PlayMusic(int aLooping)
{
	if (!iInitialized)
		return;

	StopMusic();
	Mix_FadeInMusic(iMusic,aLooping, KFadeInTime );
	SetMusicVolume(iMusicVolume);
}
Exemple #19
0
EXPORT void op_init_game(pdata data,pgameinfo gameinfo)
{
  //Text initialisieren
  data->text.texture=gameinfo->texttexture;
  int a;
  for (a=0;a<256;a++)
    data->text.breite[a]=gameinfo->textwidth[a];
    
  //Gameinforeferenzpointer speicher:
  data->gameinfo=gameinfo;
  
	char buffer[1024];
	
  //Ton vorbereiten
	sprintf(buffer,"%ssounds/positive.ogg",gameinfo->datafolder);
  data->snd_positive=Mix_LoadWAV(buffer);
  Mix_VolumeChunk(data->snd_positive,(int)(round(128.0*gameinfo->volume)));
	sprintf(buffer,"%ssounds/negative.ogg",gameinfo->datafolder);
  data->snd_negative=Mix_LoadWAV(buffer);
  Mix_VolumeChunk(data->snd_negative,(int)(round(128.0*gameinfo->volume)));
	sprintf(buffer,"%ssounds/Radio Martini.ogg",gameinfo->datafolder);
  data->backgroundmusic = Mix_LoadMUS(buffer);
  data->old_music_volume=Mix_VolumeMusic((int)(trunc(96.0*gameinfo->volume)));
  Mix_FadeInMusic(data->backgroundmusic,-1,500);

  //Objekte laden  
  sprintf(buffer,"%stextures/reflexruebe.png",gameinfo->datafolder);
  data->texture=ZWloadtexturefromfileA(buffer,0,gameinfo->texquali);
  sprintf(buffer,"%smodels/ruebe.3dm",gameinfo->datafolder);
  ZWload3dm(&(data->ruebe),buffer,data->texture);
  ZWcreatedrawlist(&(data->ruebe),gameinfo->lightquali);
	sprintf(buffer,"%smodels/schild.3dm",gameinfo->datafolder);
  ZWload3dm(&(data->schild),buffer,data->texture);
  ZWcreatedrawlist(&(data->schild),0);

  //Licht!
  ZWenablelight(0);
  ZWsetlightambient(0,0.0,0.0,0.0);
  ZWsetlightdiffuse(0,1.0,1.0,1.0);
  ZWsetlightposition(0,0.0,0.0,2.0);
  ZWsetmaterial(lnone);
	
	for (a=0;a<gameinfo->playernum;a++)
	{
	  data->points[a]=0;
		data->blocked[a]=0;
	}
  
  //Spiel ansich vorbereiten
  data->step=0;
  data->fade=1;
  data->countdown=3000;
	data->schildposition=100.0;  
	data->gamestep=0;
	data->the_button=rand()%4;
}
Exemple #20
0
void sound_playmus()
{
    if(sound_enabled == true)
    {
        if(Mix_FadeInMusic(music, -1, sound_fadetime) == -1)
            return;
        else
            Mix_VolumeMusic(sound_volmus*10);
    }
}
Exemple #21
0
void AudioEngine::play_music(std::string file_location) {
    if(currently_playing.compare(file_location) != 0) { //only change the song if it's not already playing!
        //Initialise audio variables
        int audio_rate;      //output sampling rate (in Hz)
        Uint16 audio_format; //output sample format.
        int audio_channels;  //the number of channels for the output.
        int audio_buffers;   //the chunk size of the output, larger is better for slower machines but means the sound will be delayed more.
        int audio_volume;    //the volume at which you wish to play the music
        int looping;         //wether the music should loop or not


        // Initialize variables
        audio_rate =  MIX_DEFAULT_FREQUENCY; //22050
        audio_format = AUDIO_S16;            //Signed 16-bit samples, in little-endian byte order
        audio_channels = 2;                  //1 = mono, 2 = stereo
        audio_buffers = 4096;                //good value for slower machines and doesn't have too much delay (shouldn't matter too much for music vs sound effects anyway
        audio_volume = get_music_volume();
        looping = -1;                        //loop through the music forever

        //Initialise the audio API, returns -1 on errors so check it initialises correctly
        if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
            LOG(ERROR) << "Couldn't open audio: " << SDL_GetError(); //LOG why Audio couldn't be initialised
            audio_open = false;
            return;
        }
        //Query the auddio device for it's settings.
        Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);

        // Set the music volume
        set_music_volume(audio_volume);
    
        const char* c_file_location = file_location.c_str(); //Convert the file_location to a c string for the SDL API
        music = Mix_LoadMUS(c_file_location); //Load in the music

        if (music == nullptr ) {
            LOG(ERROR) << "Couldn't load " << c_file_location << ": " << SDL_GetError(); //print why music couldn't be loaded to the screen
            Mix_CloseAudio(); //close down the audio system
            audio_open = false;
            return;
        }

        //while(!Mix_FadeOutMusic(1000) && Mix_PlayingMusic()) {
        //	wait for any fades to complete
        //	SDL_Delay(100);
        //} //TODO: implement some sort of music (and screen!) fade

        //Start playing the music.
        if(Mix_FadeInMusic(music, looping, 2000) == -1) {
            LOG(ERROR) << "Mix_FadeInMusic: " << Mix_GetError();
            // well, there's no music, but most games don't break without music...
        }
        currently_playing = file_location;
    }
    return;
}
int Musica::fadeInSonMus(int ms)
{
    if (esMusica)
    {
        return Mix_FadeInMusic(cancion, 1, ms);
    }
    else
    {
        return Mix_FadeInChannel(-1, sonido, 0, ms);
    }
}
// Load assets
bool Module_lvl_2::Start()
{
	LOG("Loading background assets");
	graphics = App->textures->Load("level2.png");
	audio_lvl_2 = App->audio->Load("2nd_Level_Theme.ogg");

	Mix_FadeInMusic(audio_lvl_2, 1, 500);
	Mix_PlayMusic(audio_lvl_2, -1);
	
	return true;
}
Exemple #24
0
void SPlayer::handlePauseEvent(const string & selection) {
    if (menu->getSelected() == "Resume") {
	game->setPaused(false);
	delete menu;
	Mix_FadeInMusic(Player::sound,-1, 2000);
	menu = NULL;
    } else if (menu->getSelected() == "Main Menu") {
       delete menu;
       menu = NULL;	
       done = true;
    } else if (menu->getSelected() == "New Game") {
      
	delete menu;
	Mix_FadeInMusic(Player::sound,-1, 2000);
	menu = NULL;
	newGame();
    }
	

}
Exemple #25
0
void SDLInteraction::StartMusic()
{
    SDLMusicInit();

    if (music == NULL) {
        music = Mix_LoadMUS((datadir->absolutePath() + "/Music/main_theme.ogg").toLocal8Bit().constData());

    }
    Mix_VolumeMusic(MIX_MAX_VOLUME - 28);
    Mix_FadeInMusic(music, -1, 1750);
}
Exemple #26
0
void Sound::fadeInMusic(const std::string &path, int ms)
{
    mCurrentMusicFile = path;

    if (!mInstalled)
        return;

    haltMusic();

    if ((mMusic = loadMusic(path.c_str())))
        Mix_FadeInMusic(mMusic, -1, ms); // Loop forever
}
Exemple #27
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 #28
0
void	music_play(MUSIC *m, int loop, int fadein)
{
	int result;

	if (fadein) {
		result = Mix_FadeInMusic(m, loop ? -1 : 0, fadein * 1000);
	} else {
		result = Mix_PlayMusic(m, loop ? - 1 : 0);
	}

	if (result == -1)
		FATAL(Mix_GetError());
}
Exemple #29
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 #30
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;
}