* @param gs the global sound def
* @param r a random number in 0..1
*/
- void globalsound(int channel, entity from, entity gs, float r, int chan, float _vol, float _atten)
+ void globalsound(int channel, entity from, entity gs, float r, int chan, float _vol, float _atten, float _pitch)
{
//assert(IS_PLAYER(from), eprint(from));
if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return;
string sample = GlobalSound_sample(gs.m_globalsoundstr, r);
switch (channel) {
case MSG_ONE:
- soundto(channel, from, chan, sample, _vol, _atten);
+ soundto(channel, from, chan, sample, _vol, _atten, _pitch);
break;
case MSG_ALL:
- _sound(from, chan, sample, _vol, _atten);
+ if(sound_allowed(MSG_BROADCAST, from))
+ sound7(from, chan, sample, _vol, _atten, _pitch, 0);
break;
}
return;
}
+ // FIXME: pitch not implemented
WriteHeader(channel, globalsound);
WriteByte(channel, gs.m_id);
WriteByte(channel, r * 255);
* @param ps the player sound def
* @param r a random number in 0..1
*/
- void playersound(int channel, entity from, entity ps, float r, int chan, float _vol, float _atten)
+ void playersound(int channel, entity from, entity ps, float r, int chan, float _vol, float _atten, float _pitch)
{
//assert(IS_PLAYER(from), eprint(from));
if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return;
string sample = GlobalSound_sample(s, r);
switch (channel) {
case MSG_ONE:
- soundto(channel, from, chan, sample, _vol, _atten);
+ soundto(channel, from, chan, sample, _vol, _atten, _pitch);
break;
case MSG_ALL:
- _sound(from, chan, sample, _vol, _atten);
+ if(sound_allowed(MSG_BROADCAST, from))
+ sound7(from, chan, sample, _vol, _atten, _pitch, 0);
break;
}
return;
}
+ // FIXME: pitch not implemented
WriteHeader(channel, playersound);
WriteByte(channel, ps.m_id);
WriteByte(channel, r * 255);
return sample;
}
+ float GlobalSound_pitch(float _pitch)
+ {
+ // customizable gradient function that crosses (0,a), (c,1) and asymptotically approaches b
+ float a = 1.5; // max pitch
+ float b = 0.75; // min pitch
+ float c = 100; // standard pitch (scale * 100)
+ float d = _pitch;
+ float pitch_shift = (b*d*(a-1) + a*c*(1-b)) / (d*(a-1) + c*(1-b));
+
+ return pitch_shift * 100;
+ }
+
void PrecacheGlobalSound(string sample)
{
int n;
if (gs == NULL && ps == NULL && sample == "") return;
if(this.classname == "body") return;
float r = random();
+ float myscale = ((this.scale) ? this.scale : 1); // safety net
+ float thepitch = ((myscale == 1) ? 0 : GlobalSound_pitch(myscale * 100));
if (sample != "") sample = GlobalSound_sample(sample, r);
switch (voicetype)
{
if (IS_REAL_CLIENT(msg_entity))
{
float atten = (CS(msg_entity).cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE;
- if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten);
- else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten);
- else soundto(MSG_ONE, this, chan, sample, vol, atten);
+ if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten, thepitch);
+ else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten, thepitch);
+ else soundto(MSG_ONE, this, chan, sample, vol, atten, thepitch);
}
}
if (voicetype == VOICETYPE_LASTATTACKER_ONLY) break;
msg_entity = this;
if (IS_REAL_CLIENT(msg_entity))
{
- if (gs) globalsound(MSG_ONE, this, gs, r, chan, VOL_BASE, ATTEN_NONE);
- else if (ps) playersound(MSG_ONE, this, ps, r, chan, VOL_BASE, ATTEN_NONE);
- else soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NONE);
+ if (gs) globalsound(MSG_ONE, this, gs, r, chan, VOL_BASE, ATTEN_NONE, thepitch);
+ else if (ps) playersound(MSG_ONE, this, ps, r, chan, VOL_BASE, ATTEN_NONE, thepitch);
+ else soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NONE, thepitch);
}
break;
}
#define X() \
MACRO_BEGIN \
float atten = (CS(msg_entity).cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; \
- if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten); \
- else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten); \
- else soundto(MSG_ONE, this, chan, sample, vol, atten); \
+ if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten, thepitch); \
+ else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten, thepitch); \
+ else soundto(MSG_ONE, this, chan, sample, vol, atten, thepitch); \
MACRO_END
if (fake) { msg_entity = this; X(); }
? bound(ATTEN_MIN, CS(msg_entity).cvar_cl_voice_directional_taunt_attenuation, \
ATTEN_MAX) \
: ATTEN_NONE; \
- if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten); \
- else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten); \
- else soundto(MSG_ONE, this, chan, sample, vol, atten); \
+ if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten, thepitch); \
+ else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten, thepitch); \
+ else soundto(MSG_ONE, this, chan, sample, vol, atten, thepitch); \
} \
MACRO_END
if (fake)
msg_entity = this;
if (fake)
{
- if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, ATTEN_NORM);
- else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, ATTEN_NORM);
- else soundto(MSG_ONE, this, chan, sample, vol, ATTEN_NORM);
+ if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, ATTEN_NORM, thepitch);
+ else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, ATTEN_NORM, thepitch);
+ else soundto(MSG_ONE, this, chan, sample, vol, ATTEN_NORM, thepitch);
}
else
{
- if (gs) globalsound(MSG_ALL, this, gs, r, chan, vol, ATTEN_NORM);
- else if (ps) playersound(MSG_ALL, this, ps, r, chan, vol, ATTEN_NORM);
- else _sound(this, chan, sample, vol, ATTEN_NORM);
+ if (gs) globalsound(MSG_ALL, this, gs, r, chan, vol, ATTEN_NORM, thepitch);
+ else if (ps) playersound(MSG_ALL, this, ps, r, chan, vol, ATTEN_NORM, thepitch);
+ else if (sound_allowed(MSG_BROADCAST, this)) sound7(this, chan, sample, vol, ATTEN_NORM, thepitch, 0);
}
break;
}
const int SND_ATTENUATION = BIT(1);
const int SND_LARGEENTITY = BIT(3);
const int SND_LARGESOUND = BIT(4);
+const int SND_SPEEDUSHORT4000 = BIT(5);
-void soundtoat(int to, entity e, vector o, int chan, string samp, float vol, float attenu)
+void soundtoat(int to, entity e, vector o, int chan, string samp, float vol, float attenu, float _pitch)
{
if (!sound_allowed(to, e)) return;
int entno = etof(e);
attenu = floor(attenu * 64);
vol = floor(vol * 255);
int sflags = 0;
+ int speed4000 = floor((_pitch * 0.01) * 4000 + 0.5);
if (vol != 255) sflags |= SND_VOLUME;
if (attenu != 64) sflags |= SND_ATTENUATION;
if (entno >= 8192 || chan < 0 || chan > 7) sflags |= SND_LARGEENTITY;
if (idx >= 256) sflags |= SND_LARGESOUND;
+ if (speed4000 && speed4000 != 4000) sflags |= SND_SPEEDUSHORT4000;
WriteByte(to, SVC_SOUND);
WriteByte(to, sflags);
if (sflags & SND_VOLUME) WriteByte(to, vol);
if (sflags & SND_ATTENUATION) WriteByte(to, attenu);
+ if (sflags & SND_SPEEDUSHORT4000) WriteShort(to, speed4000);
if (sflags & SND_LARGEENTITY)
{
WriteShort(to, entno);
WriteCoord(to, o.z);
}
-void soundto(int _dest, entity e, int chan, string samp, float vol, float _atten)
+void soundto(int _dest, entity e, int chan, string samp, float vol, float _atten, float _pitch)
{
if (!sound_allowed(_dest, e)) return;
vector o = e.origin + 0.5 * (e.mins + e.maxs);
- soundtoat(_dest, e, o, chan, samp, vol, _atten);
+ soundtoat(_dest, e, o, chan, samp, vol, _atten, _pitch);
}
void soundat(entity e, vector o, int chan, string samp, float vol, float _atten)
{
- soundtoat(((chan & 8) ? MSG_ALL : MSG_BROADCAST), e, o, chan, samp, vol, _atten);
+ soundtoat(((chan & 8) ? MSG_ALL : MSG_BROADCAST), e, o, chan, samp, vol, _atten, 0);
}
void stopsoundto(int _dest, entity e, int chan)
{
void play2(entity e, string filename)
{
msg_entity = e;
- soundtoat(MSG_ONE, NULL, '0 0 0', CH_INFO, filename, VOL_BASE, ATTEN_NONE);
+ soundtoat(MSG_ONE, NULL, '0 0 0', CH_INFO, filename, VOL_BASE, ATTEN_NONE, 0);
}
.float spamtime;