New CON command

setactorsoundpitch <actor#> <sound#> <pitchoffset>
which can be used to change the pitch of a playing sound.

The pitch offset has the same meaning as the definesound pitch range endpoints,
i.e. the units are 1/100th of a seminote.  Note that just like the random pitch
offset, increasing the pitch makes the sound duration shorter (and vice versa).

git-svn-id: https://svn.eduke32.com/eduke32@2104 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2011-11-03 23:08:54 +00:00
parent 59670ed45e
commit e94243d7db
5 changed files with 46 additions and 0 deletions

View file

@ -83,6 +83,7 @@ static struct { uint32_t keyw; uint32_t date; } g_keywdate[] =
{ CON_CALCHYPOTENUSE, 20100927 },
{ CON_CLIPMOVENOSLIDE, 20101009 },
{ CON_INCLUDEDEFAULT, 20110615 },
{ CON_SETACTORSOUNDPITCH, 20111102 },
};
char g_szScriptFileName[BMAX_PATH] = "(none)"; // file we're currently compiling
@ -562,6 +563,7 @@ const char *keyw[] =
"calchypotenuse", // 358
"clipmovenoslide", // 359
"includedefault", // 360
"setactorsoundpitch", // 361
"<null>"
};
@ -3477,6 +3479,10 @@ static int32_t C_ParseCommand(int32_t loop)
C_GetManyVars(2);
continue;
case CON_SETACTORSOUNDPITCH:
C_GetManyVars(3);
continue;
case CON_SECTOROFWALL:
C_GetNextVarType(GAMEVAR_READONLY);
C_GetNextVar();

View file

@ -936,6 +936,7 @@ enum ScriptKeywords_t
CON_CALCHYPOTENUSE, // 358
CON_CLIPMOVENOSLIDE, // 359
CON_INCLUDEDEFAULT, // 360
CON_SETACTORSOUNDPITCH, // 361
CON_END
};
#endif

View file

@ -1089,6 +1089,22 @@ skip_check:
continue;
}
case CON_SETACTORSOUNDPITCH:
insptr++;
{
int32_t i = Gv_GetVarX(*insptr++), j = Gv_GetVarX(*insptr++), pitchoffset = Gv_GetVarX(*insptr++);
if ((j<0 || j>=MAXSOUNDS))
{
OSD_Printf(CON_ERROR "Invalid sound %d\n",g_errorLineNum,keyw[g_tw],j);
continue;
}
S_ChangeSoundPitch(j,i,pitchoffset);
continue;
}
case CON_GLOBALSOUND:
if (((unsigned)*(++insptr) >= MAXSOUNDS))
{

View file

@ -663,6 +663,28 @@ void S_StopEnvSound(int32_t num, int32_t i)
while (j >= 0);
}
void S_ChangeSoundPitch(int32_t num, int32_t i, int32_t pitchoffset)
{
int32_t j;
if ((unsigned)num > (unsigned)g_maxSoundPos || g_sounds[num].num <= 0)
return;
for (j=MAXSOUNDINSTANCES-1; j>=0; j--)
{
int32_t voice = g_sounds[num].SoundOwner[j].voice;
if ((i == -1 && voice > FX_Ok) || (i != -1 && g_sounds[num].SoundOwner[j].i == i))
{
if (i >= 0 && voice <= FX_Ok)
initprintf(OSD_ERROR "S_ChangeSoundPitch(): bad voice %d for sound ID %d index %d!\n", voice, num, j);
else if (voice > FX_Ok && FX_SoundActive(voice))
FX_SetPitch(voice, pitchoffset);
break;
}
}
}
void S_Update(void)
{
vec3_t *s, *c;

View file

@ -89,5 +89,6 @@ void S_SoundStartup(void);
void S_StopEnvSound(int32_t num,int32_t i);
void S_StopMusic(void);
void S_Update(void);
void S_ChangeSoundPitch(int32_t num, int32_t i, int32_t pitchoffset);
#endif