X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsound.c;h=12b01c382b8f1c50cd62403b9ce65317fa9e8840;hb=c8689f0335cd584d24570046c6eb5a3b75701305;hp=ed50734bacf0e1ce5f5ba8b360b6f1f7a82af186;hpb=64e7c54dce6ea8c063f04198c64c5057d751c928;p=rocksndiamonds.git diff --git a/src/libgame/sound.c b/src/libgame/sound.c index ed50734b..12b01c38 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -4,7 +4,7 @@ // (c) 1995-2014 by Artsoft Entertainment // Holger Schemel // info@artsoft.org -// http://www.artsoft.org/ +// https://www.artsoft.org/ // ---------------------------------------------------------------------------- // sound.c // ============================================================================ @@ -131,6 +131,7 @@ static void ReloadCustomMusic(void); static void FreeSound(void *); static void FreeMusic(void *); static void FreeAllMusic_NoConf(void); +static void Mixer_StopMusicChannel(void); static SoundInfo *getSoundInfoEntryFromSoundID(int); static MusicInfo *getMusicInfoEntryFromMusicID(int); @@ -223,12 +224,16 @@ static void Mixer_PlayMusicChannel(void) { int loops = (IS_LOOP(mixer[audio.music_channel]) ? -1 : 1); + // stopping music channel before playing next track seems to be needed to + // prevent audio problems that may occur when playing MP3 files on Windows + Mixer_StopMusicChannel(); + // use short fade-in to prevent "plop" sound for certain music files // (this may happen when switching on music while playing the game) Mix_VolumeMusic(mixer[audio.music_channel].volume); Mix_FadeInMusic(mixer[audio.music_channel].data_ptr, loops, 100); -#if defined(PLATFORM_WIN32) +#if defined(PLATFORM_WINDOWS) // playing MIDI music is broken since Windows Vista, as it sets the volume // for MIDI music also for all other sounds and music, which cannot be set // back to normal unless playing MIDI music again with that desired volume @@ -276,7 +281,7 @@ static void Mixer_FadeMusicChannel(void) Mix_FadeOutMusic(SOUND_FADING_INTERVAL); -#if defined(PLATFORM_WIN32) +#if defined(PLATFORM_WINDOWS) // playing MIDI music is broken since Windows Vista, as it sets the volume // for MIDI music also for all other sounds and music, which cannot be set // back to normal unless playing MIDI music again with that desired volume @@ -404,8 +409,8 @@ static void Mixer_InsertSound(SoundControl snd_ctrl) { if (!mixer[i].active) { - Error(ERR_INFO, "Mixer_InsertSound: Channel %d inactive", i); - Error(ERR_INFO, "Mixer_InsertSound: This should never happen!"); + Debug("audio", "Mixer_InsertSound: Channel %d inactive", i); + Debug("audio", "Mixer_InsertSound: This should never happen!"); mixer_active_channels--; } @@ -533,8 +538,10 @@ static void *Load_WAV(char *filename) if ((snd_info->data_ptr = Mix_LoadWAV(filename)) == NULL) { - Error(ERR_WARN, "cannot read sound file '%s': %s", filename, Mix_GetError()); + Warn("cannot read sound file '%s': %s", filename, Mix_GetError()); + free(snd_info); + return NULL; } @@ -557,8 +564,10 @@ static void *Load_MOD(char *filename) if ((mod_info->data_ptr = Mix_LoadMUS(filename)) == NULL) { - Error(ERR_WARN, "cannot read music file '%s': %s", filename, Mix_GetError()); + Warn("cannot read music file '%s': %s", filename, Mix_GetError()); + free(mod_info); + return NULL; } @@ -602,7 +611,7 @@ static void LoadCustomMusic_NoConf(void) if ((dir = openDirectory(music_directory)) == NULL) { - Error(ERR_WARN, "cannot read music directory '%s'", music_directory); + Warn("cannot read music directory '%s'", music_directory); audio.music_available = FALSE; @@ -610,7 +619,7 @@ static void LoadCustomMusic_NoConf(void) } if (draw_init_text) - DrawInitText("Loading music", 120, FC_GREEN); + DrawInitTextHead("Loading music"); while ((dir_entry = readDirectory(dir)) != NULL) // loop all entries { @@ -635,7 +644,7 @@ static void LoadCustomMusic_NoConf(void) continue; if (draw_init_text) - DrawInitText(basename, 150, FC_YELLOW); + DrawInitTextItem(basename); if (FileIsMusic(dir_entry->filename)) mus_info = Load_WAV_or_MOD(dir_entry->filename);