3 #define TUBA_INSTRUMENTS 1
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, snd1, e.cnt * f1, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p1, 0);
68 sound7(e.enemy, CH_TUBA, 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, 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, "misc/null.wav", 0, 0);
92 sound(self.enemy, CH_TUBA, "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)
130 if(n != self.note || i != self.tuba_instrument || bIsNew)
133 Ent_TubaNote_StopSound();
138 self.enemy = spawn();
139 self.enemy.classname = "tuba_note";
142 self.enemy.enemy = spawn();
143 self.enemy.enemy.classname = "tuba_note_2";
148 self.enemy.attenuate = att;
153 self.tuba_instrument = i;
154 Ent_TubaNote_UpdateSound();
160 self.enemy.origin_x = ReadCoord();
161 self.enemy.origin_y = ReadCoord();
162 self.enemy.origin_z = ReadCoord();
163 setorigin(self.enemy, self.enemy.origin);
165 setorigin(self.enemy.enemy, self.enemy.origin);
168 self.think = Ent_TubaNote_StopSound;
169 self.entremove = Ent_TubaNote_StopSound;
170 self.enemy.think = Ent_TubaNote_Think;
171 self.enemy.nextthink = time + 10;
177 Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep;
180 if(!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7"))
182 print("^1NOTE:^7 requested pitch shifting, but not supported by this engine build\n");
186 for(n = TUBA_MIN; n <= TUBA_MAX; ++n)
188 if(!Tuba_PitchStep || (mod(n, Tuba_PitchStep) == 0))
190 for(i = 0; i < TUBA_INSTRUMENTS; ++i)
191 precache_sound(TUBA_STARTNOTE(i, n));