]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/tuba.qc
fixes for the pitch shifting code path
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / tuba.qc
1 #define TUBA_STARTNOTE(n) strcat("weapons/tuba_loopnote", ftos(n), ".wav")
2 .float note; // note
3 .float attenuate; // if set, attenuate it
4 .float cnt; // current volume
5 .float count; // initial volume
6
7 void Ent_TubaNote_Think()
8 {
9         float f;
10         f = autocvar_g_balance_tuba_fadetime;
11         if(f > 0)
12                 self.cnt -= frametime * self.count / f;
13         else
14                 self.cnt = 0;
15         self.nextthink = time;
16         if(self.cnt <= 0)
17         {
18                 sound(self, CH_TUBA, "misc/null.wav", 0, 0);
19                 remove(self);
20         }
21         else
22         {
23 #ifdef PITCHSHIFT
24                 sound7(self, CH_TUBA, "", self.cnt, self.attenuate * autocvar_g_balance_tuba_attenuation, 100 * pow(2.0, self.note / 12.0), 0);
25 #else
26                 sound(self, CH_TUBA, "", self.cnt, self.attenuate * autocvar_g_balance_tuba_attenuation);
27 #endif
28         }
29 }
30
31 void Ent_TubaNote_UpdateSound()
32 {
33         self.enemy.cnt = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1);
34         self.enemy.count = self.enemy.cnt;
35         self.enemy.note = self.note;
36 #ifdef PITCHSHIFT
37         sound7(self.enemy, CH_TUBA, TUBA_STARTNOTE(0), self.enemy.cnt, self.enemy.attenuate * autocvar_g_balance_tuba_attenuation, 100 * pow(2.0, self.note / 12.0), 0);
38 #else
39         sound(self.enemy, CH_TUBA, TUBA_STARTNOTE(self.note), self.enemy.cnt, self.enemy.attenuate * autocvar_g_balance_tuba_attenuation);
40 #endif
41 }
42
43 void Ent_TubaNote_StopSound()
44 {
45         self.enemy.nextthink = time;
46         self.enemy = world;
47 }
48
49 void Ent_TubaNote(float bIsNew)
50 {
51         float f, n;
52         f = ReadByte();
53         n = floor(f / 2) - 42;
54         if(n != self.note || bIsNew)
55                 if(self.enemy)
56                         Ent_TubaNote_StopSound();
57         if(!self.enemy)
58         {
59                 self.enemy = spawn();
60                 self.enemy.classname = "tuba_note";
61                 bIsNew = TRUE;
62         }
63         if(f & 1)
64         {
65                 self.enemy.origin_x = ReadCoord();
66                 self.enemy.origin_y = ReadCoord();
67                 self.enemy.origin_z = ReadCoord();
68                 setorigin(self.enemy, self.enemy.origin);
69                 self.enemy.attenuate = ReadByte();
70         }
71         self.think = Ent_TubaNote_StopSound;
72         self.entremove = Ent_TubaNote_StopSound;
73         self.enemy.think = Ent_TubaNote_Think;
74         self.enemy.nextthink = time + 10;
75         if(bIsNew)
76         {
77                 self.note = n;
78                 Ent_TubaNote_UpdateSound();
79         }
80 }
81
82 void Tuba_Precache()
83 {
84         float i;
85 #ifdef PITCHSHIFT
86         precache_sound(TUBA_STARTNOTE(0));
87 #else
88         for(i = -18; i <= +27; ++i)
89         {
90                 precache_sound(TUBA_STARTNOTE(i));
91         }
92 #endif
93         //precache_sound(""); // we want to change volume of existing sounds
94 }