4 #define TUBA_STARTNOTE(n) strcat("weapons/tuba_loopnote", ftos(n), ".wav")
6 .float attenuate; // if set, attenuate it
7 .float cnt; // current volume
8 .float count; // initial volume
12 void tubasound(entity e, float restart)
31 m = mod(e.note, Tuba_PitchStep);
34 if(e.note - m < TUBA_MIN)
37 snd1 = TUBA_STARTNOTE(e.note - m + Tuba_PitchStep);
38 p1 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
40 else if(e.note - m + Tuba_PitchStep > TUBA_MAX)
43 snd1 = TUBA_STARTNOTE(e.note - m);
44 p1 = pow(2.0, m / 12.0);
49 snd1 = TUBA_STARTNOTE(e.note - m);
50 f1 = cos(M_PI_2 * m / Tuba_PitchStep);
51 p1 = pow(2.0, m / 12.0);
53 snd2 = TUBA_STARTNOTE(e.note - m + Tuba_PitchStep);
54 f2 = sin(M_PI_2 * m / Tuba_PitchStep);
55 p2 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
61 snd1 = TUBA_STARTNOTE(e.note);
64 sound7(e, CH_TUBA, snd1, e.cnt * f1, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p1, 0);
66 sound7(e.enemy, CH_TUBA, snd2, e.cnt * f2, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p2, 0);
71 snd1 = TUBA_STARTNOTE(e.note);
72 sound(e, CH_TUBA, snd1, e.cnt, e.attenuate * autocvar_g_balance_tuba_attenuation);
76 void Ent_TubaNote_Think()
79 f = autocvar_g_balance_tuba_fadetime;
81 self.cnt -= frametime * self.count / f;
84 self.nextthink = time;
87 sound(self, CH_TUBA, "misc/null.wav", 0, 0);
90 sound(self.enemy, CH_TUBA, "misc/null.wav", 0, 0);
101 void Ent_TubaNote_UpdateSound()
103 self.enemy.cnt = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1);
104 self.enemy.count = self.enemy.cnt;
105 self.enemy.note = self.note;
106 tubasound(self.enemy, 1);
109 void Ent_TubaNote_StopSound()
111 self.enemy.nextthink = time;
115 void Ent_TubaNote(float bIsNew)
119 n = floor(f / 2) - 42;
120 if(n != self.note || bIsNew)
122 Ent_TubaNote_StopSound();
125 self.enemy = spawn();
126 self.enemy.classname = "tuba_note";
129 self.enemy.enemy = spawn();
130 self.enemy.enemy.classname = "tuba_note_2";
136 self.enemy.origin_x = ReadCoord();
137 self.enemy.origin_y = ReadCoord();
138 self.enemy.origin_z = ReadCoord();
139 setorigin(self.enemy, self.enemy.origin);
140 self.enemy.attenuate = ReadByte();
142 setorigin(self.enemy.enemy, self.enemy.origin);
144 self.think = Ent_TubaNote_StopSound;
145 self.entremove = Ent_TubaNote_StopSound;
146 self.enemy.think = Ent_TubaNote_Think;
147 self.enemy.nextthink = time + 10;
151 Ent_TubaNote_UpdateSound();
158 Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep;
161 if(!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7"))
163 print("^1NOTE:^7 requested pitch shifting, but not supported by this engine build\n");
167 for(i = TUBA_MIN; i <= TUBA_MAX; ++i)
169 if(!Tuba_PitchStep || (mod(i, Tuba_PitchStep) == 0))
170 precache_sound(TUBA_STARTNOTE(i));