Use volume field of sound, access with SOC/lua

Volumes may be defined on a 0-100 scale, but any number is
accepted.

If the volume is negative then the sound will play at
normal volume (therefore the info table won't need to be
modified.)
This commit is contained in:
James R 2021-11-08 18:50:19 -08:00
parent d22705727b
commit e82bba18f6
4 changed files with 29 additions and 2 deletions

View file

@ -2683,6 +2683,10 @@ void readsound(MYFILE *f, INT32 num)
{
S_sfx[num].pitch = value;
}
else if (fastcmp(word, "VOLUME"))
{
S_sfx[num].volume = value;
}
else if (fastcmp(word, "CAPTION") || fastcmp(word, "DESCRIPTION"))
{
deh_strlcpy(S_sfx[num].caption, word2,

View file

@ -41,6 +41,7 @@ enum sfxinfo_read {
sfxinfor_singular,
sfxinfor_priority,
sfxinfor_flags, // "pitch"
sfxinfor_volume,
sfxinfor_caption,
sfxinfor_skinsound
};
@ -49,6 +50,7 @@ const char *const sfxinfo_ropt[] = {
"singular",
"priority",
"flags",
"volume",
"caption",
"skinsound",
NULL};
@ -57,12 +59,14 @@ enum sfxinfo_write {
sfxinfow_singular = 0,
sfxinfow_priority,
sfxinfow_flags, // "pitch"
sfxinfow_volume,
sfxinfow_caption
};
const char *const sfxinfo_wopt[] = {
"singular",
"priority",
"flags",
"volume",
"caption",
NULL};
@ -1328,6 +1332,9 @@ static int lib_setSfxInfo(lua_State *L)
case sfxinfow_flags:
info->pitch = (INT32)luaL_checkinteger(L, 3);
break;
case sfxinfow_volume:
info->volume = (INT32)luaL_checkinteger(L, 3);
break;
case sfxinfow_caption:
strlcpy(info->caption, luaL_checkstring(L, 3), sizeof(info->caption));
break;
@ -1368,6 +1375,9 @@ static int sfxinfo_get(lua_State *L)
case sfxinfor_flags:
lua_pushinteger(L, sfx->pitch);
return 1;
case sfxinfor_volume:
lua_pushinteger(L, sfx->volume);
return 1;
case sfxinfor_caption:
lua_pushstring(L, sfx->caption);
return 1;
@ -1408,6 +1418,9 @@ static int sfxinfo_set(lua_State *L)
case sfxinfow_flags:
sfx->pitch = luaL_checkinteger(L, 1);
break;
case sfxinfow_volume:
sfx->volume = luaL_checkinteger(L, 1);
break;
case sfxinfow_caption:
strlcpy(sfx->caption, luaL_checkstring(L, 1), sizeof(sfx->caption));
break;

View file

@ -693,7 +693,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume)
channels[cnum].sfxinfo = sfx;
channels[cnum].origin = origin;
channels[cnum].volume = initial_volume;
channels[cnum].handle = I_StartSound(sfx_id, volume, sep, pitch, priority, cnum);
channels[cnum].handle = I_StartSound(sfx_id, S_GetSoundVolume(sfx, volume), sep, pitch, priority, cnum);
}
}
@ -899,7 +899,7 @@ void S_UpdateSounds(void)
}
if (audible)
I_UpdateSoundParams(c->handle, volume, sep, pitch);
I_UpdateSoundParams(c->handle, S_GetSoundVolume(c->sfxinfo, volume), sep, pitch);
else
S_StopChannel(cnum);
}
@ -1011,6 +1011,14 @@ fixed_t S_CalculateSoundDistance(fixed_t sx1, fixed_t sy1, fixed_t sz1, fixed_t
return FixedDiv(approx_dist, mapobjectscale); // approx_dist
}
INT32 S_GetSoundVolume(sfxinfo_t *sfx, INT32 volume)
{
if (sfx->volume < 0)
return volume;
else
return volume * sfx->volume / 100;
}
//
// Changes volume, stereo-separation, and pitch variables
// from the norm of a sound effect to be played.

View file

@ -295,6 +295,8 @@ void S_UpdateClosedCaptions(void);
FUNCMATH fixed_t S_CalculateSoundDistance(fixed_t px1, fixed_t py1, fixed_t pz1, fixed_t px2, fixed_t py2, fixed_t pz2);
INT32 S_GetSoundVolume(sfxinfo_t *sfx, INT32 volume);
void S_SetSfxVolume(INT32 volume);
void S_SetMusicVolume(INT32 digvolume);
#define S_SetDigMusicVolume S_SetMusicVolume