diff --git a/src/doomdef.h b/src/doomdef.h index 3a49cccd4..26072b705 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -676,4 +676,8 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Hardware renderer: OpenGL #define GL_SHADERS +/// Default volume for songs that don't have "volume" set via musicdef +/// TODO: Remove this once all songs are ported +#define DEFAULT_MUSICDEF_VOLUME 25 + #endif // __DOOMDEF__ diff --git a/src/s_sound.c b/src/s_sound.c index 9b49784ec..0bff2e028 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1578,6 +1578,7 @@ static UINT32 queue_fadeinms; musicdef_t *musicdefstart = NULL; // First music definition struct cursongcredit cursongcredit; // Currently displayed song credit info +int musicdef_volume; // // search for music definition in wad @@ -1686,6 +1687,8 @@ void S_LoadMusicDefs(UINT16 wadnum) } } + def->volume = DEFAULT_MUSICDEF_VOLUME; + skip_lump: stoken = strtok(NULL, "\r\n "); line++; @@ -1720,6 +1723,8 @@ skip_lump: for (value = def->source; *value; value++) if (*value == '_') *value = ' '; // turn _ into spaces. //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); + } else if (!stricmp(stoken, "volume")) { + def->volume = atoi(value); } else { CONS_Alert(CONS_WARNING, "MUSICDEF: Invalid field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); } @@ -2047,6 +2052,19 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 music_flags = mflags; music_looping = looping; + musicdef_volume = DEFAULT_MUSICDEF_VOLUME; + + { + musicdef_t *def; + for (def = musicdefstart; def; def = def->next) + { + if (strcasecmp(def->name, music_name) == 0) + { + musicdef_volume = def->volume; + } + } + } + if (!S_PlayMusic(looping, fadeinms)) { CONS_Alert(CONS_ERROR, "Music %.6s could not be played!\n", newmusic); diff --git a/src/s_sound.h b/src/s_sound.h index c433aa974..332f93324 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -139,6 +139,7 @@ typedef struct musicdef_s char name[7]; //char usage[256]; char source[256]; + int volume; struct musicdef_s *next; } musicdef_t; @@ -151,6 +152,7 @@ extern struct cursongcredit } cursongcredit; extern musicdef_t *musicdefstart; +extern int musicdef_volume; void S_LoadMusicDefs(UINT16 wadnum); void S_InitMusicDefs(void); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 77fcc0914..0821a22c9 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -493,7 +493,8 @@ void I_FreeSfx(sfxinfo_t *sfx) INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority, INT32 channel) { - UINT8 volume = (((UINT16)vol + 1) * (UINT16)sfx_volume) / 62; // (256 * 31) / 62 == 127 + //UINT8 volume = (((UINT16)vol + 1) * (UINT16)sfx_volume) / 62; // (256 * 31) / 62 == 127 + int volume = ( vol + 1 ) / 8;/* reduce to 1/4, 256 / 8 = 128 / 4 = 32 */ INT32 handle = Mix_PlayChannel(channel, S_sfx[id].data, 0); Mix_Volume(handle, volume); Mix_SetPanning(handle, min((UINT16)(0xff-sep)<<1, 0xff), min((UINT16)(sep)<<1, 0xff)); @@ -531,6 +532,7 @@ void I_SetSfxVolume(UINT8 volume) static UINT32 get_real_volume(UINT8 volume) { + (void)volume; #ifdef _WIN32 if (I_SongType() == MU_MID) // HACK: Until we stop using native MIDI, @@ -540,7 +542,8 @@ static UINT32 get_real_volume(UINT8 volume) #endif // convert volume to mixer's 128 scale // then apply internal_volume as a percentage - return ((UINT32)volume*128/31) * (UINT32)internal_volume / 100; + //return ((UINT32)volume*128/31) * (UINT32)internal_volume / 100; + return MIX_MAX_VOLUME * musicdef_volume / 100 * internal_volume / 100; } static UINT32 get_adjusted_position(UINT32 position)