+.float cnt; // current volume
+.float count; // initial volume
+.float tuba_instrument;
+
+float Tuba_PitchStep;
+
+void tubasound(entity e, float restart)
+{
+ string snd1;
+
+ snd1 = string_null;
+
+ if(Tuba_PitchStep)
+ {
+ string snd2;
+ float f1, f2;
+ float p1, p2;
+ float m;
+
+ f1 = 1;
+ p1 = 1;
+ snd2 = string_null;
+ f2 = 0;
+ p2 = 1;
+
+ m = mod(e.note, Tuba_PitchStep);
+ if(m)
+ {
+ if(e.note - m < TUBA_MIN)
+ {
+ if(restart)
+ snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
+ p1 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
+ }
+ else if(e.note - m + Tuba_PitchStep > TUBA_MAX)
+ {
+ if(restart)
+ snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
+ p1 = pow(2.0, m / 12.0);
+ }
+ else
+ {
+ if(restart)
+ snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
+ f1 = cos(M_PI_2 * m / Tuba_PitchStep);
+ p1 = pow(2.0, m / 12.0);
+ if(restart)
+ snd2 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
+ f2 = sin(M_PI_2 * m / Tuba_PitchStep);
+ p2 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
+ }
+ }
+ else
+ {
+ if(restart)
+ snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
+ }
+
+ sound7(e, CH_TUBA, snd1, e.cnt * f1, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p1, 0);
+ if(f2)
+ sound7(e.enemy, CH_TUBA, snd2, e.cnt * f2, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p2, 0);
+ }
+ else
+ {
+ if(restart)
+ snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
+ sound(e, CH_TUBA, snd1, e.cnt, e.attenuate * autocvar_g_balance_tuba_attenuation);
+ }
+}