@@ -15,6 +15,8 @@ extern F32 _598;
1515extern F32 _599;
1616extern xSndGlobals gSnd ;
1717
18+ static S32 faders_active;
19+
1820void xSndInit ()
1921{
2022 iSndInit ();
@@ -86,6 +88,49 @@ void xSndResume()
8688 sDelayedPaused = 0 ;
8789}
8890
91+ void xSndPauseAll (U32 pause_effects, U32 pause_streams)
92+ {
93+ sDelayedPaused = pause_effects;
94+
95+ for (U32 i = 0 ; i < 0x40 ; i++)
96+ {
97+ if (gSnd .voice [i].flags & 1 )
98+ {
99+ if (gSnd .voice [i].flags & 2 )
100+ {
101+ iSndPause (gSnd .voice [i].sndID , pause_effects);
102+ }
103+ else if (gSnd .voice [i].flags & 4 )
104+ {
105+ iSndPause (gSnd .voice [i].sndID , pause_streams);
106+ }
107+ }
108+ }
109+ }
110+
111+ void xSndPauseCategory (U32 mask, U32 pause)
112+ {
113+ for (U32 i = 0 ; i < 0x40 ; i++)
114+ {
115+ if ((gSnd .voice [i].flags & 1 ) && (mask & 1 << gSnd .voice [i].category ))
116+ {
117+ iSndPause (gSnd .voice [i].sndID , pause);
118+ }
119+ }
120+ }
121+
122+ void xSndStopAll (U32 mask)
123+ {
124+ for (U32 i = 0 ; i < 0x40 ; i++)
125+ {
126+ if ((gSnd .voice [i].flags & 1 ) && (mask & 1 << gSnd .voice [i].category ))
127+ {
128+ iSndStop (gSnd .voice [i].sndID );
129+ }
130+ }
131+ xSndDelayedInit ();
132+ }
133+
89134void xSndSetCategoryVol (sound_category category, F32 vol)
90135{
91136 gSnd .categoryVolFader [category] = vol;
@@ -101,6 +146,32 @@ void xSndDelayedInit()
101146 sDelayedPaused = 0 ;
102147}
103148
149+ void xSndAddDelayed (U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, U32 parentID, xEnt* parentEnt, xVec3* pos, F32 innerRadius, F32 outerRadius, sound_category category, F32 delay)
150+ {
151+ _xSndDelayed* snd = &sDelayedSnd [0 ];
152+
153+ for (U32 i = 0x10 ; i != 0 ; i--)
154+ {
155+ if (snd->delay <= 0 .0f )
156+ {
157+ snd->id = id;
158+ snd->vol = vol;
159+ snd->pitch = pitch;
160+ snd->priority = priority;
161+ snd->flags = flags;
162+ snd->parentID = parentID;
163+ snd->parentEnt = parentEnt;
164+ snd->pos = pos;
165+ snd->innerRadius = innerRadius;
166+ snd->outerRadius = outerRadius;
167+ snd->category = category;
168+ snd->delay = delay;
169+ return ;
170+ }
171+ snd++;
172+ }
173+ }
174+
104175void xSndCalculateListenerPosition ()
105176{
106177 xMat4x3* pMat;
@@ -129,53 +200,36 @@ void xSndCalculateListenerPosition()
129200
130201void xSndInternalUpdateVoicePos (xSndVoiceInfo* pVoice)
131202{
132- U32 flags = pVoice->flags ;
133- xVec3* ent;
134-
135- if ((flags & 1 ) != 0 )
203+ if ((pVoice->flags & 1 ) && (pVoice->flags & 8 ))
136204 {
137- // FIXME: WIP
138- // if ((flags & 8) != 0)
139- // {
140- // if ((flags & 0x10) != 0)
141- // {
142- // if (pVoice->parentPos == (xVec3*)0x0)
143- // {
144- // if (pVoice->parentID == 0)
145- // {
146- // if ((flags & 8) == 0)
147- // {
148- // pVoice->actualPos = gSnd.pos;
149- // }
150- // }
151- // else
152- // {
153- // ent = pVoice->parentID & 0xfffffffc);
154- // if ((flags & 0x800) == 0)
155- // {
156- // if ((? & 1) == 0)
157- // {
158- // pVoice->flags = flags & 0xffffffef;
159- // }
160- // else
161- // {
162- // pxVar2 = (xVec3*)xEntGetPos((xEnt*)ent);
163- // xVec3Copy(pVoice->actualPos, ent);
164- // }
165- // }
166- // else
167- // {
168- // pVoice->actualPos = ent;
169- // }
170- // }
171- // }
172- // else
173- // {
174- // pVoice->actualPos = pVoice->parentPos;
175- // }
176- // }
177- // xSndProcessSoundPos(pVoice->actualPos, pVoice->playPos);
178- // }
205+ if (pVoice->flags & 0x10 )
206+ {
207+ if (pVoice->parentPos != NULL )
208+ {
209+ pVoice->actualPos = *pVoice->parentPos ;
210+ }
211+ else if (pVoice->parentID != 0 )
212+ {
213+ xEnt* ent = (xEnt*)(pVoice->parentID & 0xfffffffc ); // uhh...
214+ if (pVoice->flags & 0x800 )
215+ {
216+ pVoice->actualPos = *(xVec3*)(ent);
217+ }
218+ else if (ent->baseFlags & 1 )
219+ {
220+ xVec3Copy (&pVoice->actualPos , xEntGetPos (ent));
221+ }
222+ else
223+ {
224+ pVoice->flags &= 0xffffffef ;
225+ }
226+ }
227+ else if (!(pVoice->flags & 8 ))
228+ {
229+ pVoice->actualPos = gSnd .pos ;
230+ }
231+ }
232+ xSndProcessSoundPos (&pVoice->actualPos , &pVoice->playPos );
179233 }
180234}
181235
@@ -193,7 +247,7 @@ void xSndSetListenerData(sound_listener_type listenerType, const xMat4x3* matrix
193247 * This code appears to be correct but there appears to be a possibility
194248 * of accessing this array out of bounds.
195249 * It may be possible the dwarf data for sound_listener_type is incorrect
196- * Otherwise it could be a potential bug
250+ * Otherwise it could be a potential bug
197251 * (Gamecube audio bug source????)
198252 */
199253 int i = (int )listenerType;
@@ -304,6 +358,34 @@ void xSndSetExternalCallback(void (*callback)(U32))
304358 iSndSetExternalCallback (callback);
305359}
306360
361+ void reset_faders ()
362+ {
363+ faders_active = 0 ;
364+ }
365+
366+ class fade_data {
367+ // total size: 0x18
368+ public:
369+ unsigned char in; // offset 0x0, size 0x1
370+ unsigned int handle; // offset 0x4, size 0x4
371+ float start_delay; // offset 0x8, size 0x4
372+ float time; // offset 0xC, size 0x4
373+ float end_time; // offset 0x10, size 0x4
374+ float volume; // offset 0x14, size 0x4
375+
376+ void operator =(const fade_data& rhs);
377+ };
378+
379+ void fade_data::operator =(const fade_data& rhs)
380+ {
381+ in = rhs.in ;
382+ handle = rhs.handle ;
383+ start_delay = rhs.start_delay ;
384+ time = rhs.time ;
385+ end_time = rhs.end_time ;
386+ volume = rhs.volume ;
387+ }
388+
307389U32 xSndStreamReady (U32 owner)
308390{
309391 xSndVoiceInfo* begin = gSnd .voice ;
@@ -313,7 +395,14 @@ U32 xSndStreamReady(U32 owner)
313395 {
314396 if (v->lock_owner == owner)
315397 {
316- return (v->flags & 1 ) >> 5 ; // FIXME: Missing cntlzw instruction.
398+ if (v->flags & 1 )
399+ {
400+ return 0 ;
401+ }
402+ else
403+ {
404+ return 1 ;
405+ }
317406 }
318407 }
319408
0 commit comments