3 #define TUBA_INSTRUMENTS 3
5 #define TUBA_STARTNOTE(i,n) strcat("weapons/tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n), ".wav")
7 .float attenuate; // if set, attenuate it
8 .float cnt; // current volume
9 .float count; // initial volume
10 .float tuba_instrument;
14 void tubasound(entity e, float restart)
33 m = mod(e.note, Tuba_PitchStep);
36 if(e.note - m < TUBA_MIN)
39 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
40 p1 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
42 else if(e.note - m + Tuba_PitchStep > TUBA_MAX)
45 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
46 p1 = pow(2.0, m / 12.0);
51 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
52 f1 = cos(M_PI_2 * m / Tuba_PitchStep);
53 p1 = pow(2.0, m / 12.0);
55 snd2 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
56 f2 = sin(M_PI_2 * m / Tuba_PitchStep);
57 p2 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
63 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
66 sound7(e, CH_TUBA_SINGLE, snd1, e.cnt * f1, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p1, 0);
68 sound7(e.enemy, CH_TUBA_SINGLE, snd2, e.cnt * f2, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p2, 0);
73 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
74 sound(e, CH_TUBA_SINGLE, snd1, e.cnt, e.attenuate * autocvar_g_balance_tuba_attenuation);
78 void Ent_TubaNote_Think()
81 f = autocvar_g_balance_tuba_fadetime;
83 self.cnt -= frametime * self.count / f;
86 self.nextthink = time;
89 sound(self, CH_TUBA_SINGLE, "misc/null.wav", 0, 0);
92 sound(self.enemy, CH_TUBA_SINGLE, "misc/null.wav", 0, 0);
103 void Ent_TubaNote_UpdateSound()
105 self.enemy.cnt = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1);
106 self.enemy.count = self.enemy.cnt;
107 self.enemy.note = self.note;
108 self.enemy.tuba_instrument = self.tuba_instrument;
109 tubasound(self.enemy, 1);
112 void Ent_TubaNote_StopSound()
114 self.enemy.nextthink = time;
118 void Ent_TubaNote(float bIsNew)
120 float f, n, i, att, upd;
132 if(n != self.note || i != self.tuba_instrument || bIsNew)
135 Ent_TubaNote_StopSound();
140 self.enemy = spawn();
141 self.enemy.classname = "tuba_note";
144 self.enemy.enemy = spawn();
145 self.enemy.enemy.classname = "tuba_note_2";
150 self.enemy.attenuate = att;
155 self.tuba_instrument = i;
162 self.enemy.origin_x = ReadCoord();
163 self.enemy.origin_y = ReadCoord();
164 self.enemy.origin_z = ReadCoord();
165 setorigin(self.enemy, self.enemy.origin);
167 setorigin(self.enemy.enemy, self.enemy.origin);
170 self.think = Ent_TubaNote_StopSound;
171 self.entremove = Ent_TubaNote_StopSound;
172 self.enemy.think = Ent_TubaNote_Think;
173 self.enemy.nextthink = time + 10;
176 Ent_TubaNote_UpdateSound();
182 Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep;
185 if(!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7"))
187 print("^1NOTE:^7 requested pitch shifting, but not supported by this engine build\n");
191 for(n = TUBA_MIN; n <= TUBA_MAX; ++n)
193 if(!Tuba_PitchStep || (mod(n, Tuba_PitchStep) == 0))
195 for(i = 0; i < TUBA_INSTRUMENTS; ++i)
196 precache_sound(TUBA_STARTNOTE(i, n));