Skip to content

Commit 301009e

Browse files
authored
iSnd progress (#706)
1 parent a8695c5 commit 301009e

File tree

5 files changed

+167
-12
lines changed

5 files changed

+167
-12
lines changed

src/SB/Core/gc/iMemMgr.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#ifndef IMEMMGR_H
22
#define IMEMMGR_H
33

4+
#include "dolphin/os/OSAlloc.h"
45
#include <types.h>
56

7+
extern volatile OSHeapHandle the_heap;
8+
69
void iMemInit();
710
void iMemExit();
811

9-
#endif
12+
#endif

src/SB/Core/gc/iSnd.cpp

Lines changed: 158 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#include "iSnd.h"
22

3+
#include "dolphin/ai.h"
4+
#include "dolphin/os.h"
5+
#include "dolphin/os/OSAlloc.h"
6+
#include "dolphin/os/OSCache.h"
7+
#include "iMemMgr.h"
38
#include "iTRC.h"
49
#include "xSnd.h"
510
#include "xstransvc.h"
@@ -10,16 +15,19 @@
1015
#include <dolphin/dvd/dvd.h>
1116
#include <dolphin/mix.h>
1217

18+
#include <stdio.h>
1319
#include <types.h>
1420

21+
u32 aram_array[40];
22+
1523
// Size: 0x20
1624
// This was not in dwarf data
1725
struct vinfo
1826
{
1927
_AXVPB* voice;
2028
U32 flags;
2129
U32 aid;
22-
U8 buf[4];
30+
U32 xc;
2331
S32 x10;
2432
S32 x14;
2533
S32 x18;
@@ -52,9 +60,12 @@ UNK_STREAM streams[6];
5260

5361
vinfo voices[58];
5462

55-
u32 zero_point = 0;
56-
u32 zero_end = 0;
57-
S32 SoundFlags = 0;
63+
U32* ua_stream_buffer = NULL; //unaligned stream buffer
64+
U32* stream_buffer = 0;
65+
u32 silence_buffer = 0;
66+
volatile u32 zero_point = 0;
67+
volatile u32 zero_end = 0;
68+
volatile U32 SoundFlags = 0;
5869
volatile S32 fc = 0;
5970
static char soundInited = 0;
6071
U32 houston_we_have_a_problem = 0;
@@ -453,14 +464,16 @@ static void fcb()
453464
}
454465
}
455466

456-
if (streams[i].vinf.x10 == streams[i].vinf.x14 && streams[i].vinf.x18 == streams[i].vinf.x1c)
467+
if (streams[i].vinf.x10 == streams[i].vinf.x14 &&
468+
streams[i].vinf.x18 == streams[i].vinf.x1c)
457469
{
458470
continue;
459471
}
460472

461473
streams[i].vinf.x14 = streams[i].vinf.x10;
462474
streams[i].vinf.x1c = streams[i].vinf.x18;
463-
MIXAdjustInput(streams[i].vinf.voice, streams[i].vinf.x14 - MIXGetInput(streams[i].vinf.voice));
475+
MIXAdjustInput(streams[i].vinf.voice,
476+
streams[i].vinf.x14 - MIXGetInput(streams[i].vinf.voice));
464477
MIXAdjustPan(streams[i].vinf.voice, streams[i].vinf.x1c - MIXGetPan(streams[i].vinf.voice));
465478
need_update = TRUE;
466479
}
@@ -501,6 +514,78 @@ static void fcb()
501514
}
502515
}
503516

517+
void iSndInit()
518+
{
519+
soundInited = 1;
520+
AIInit(NULL);
521+
ARInit(aram_array, 40);
522+
ARQInit();
523+
AXInit();
524+
MIXInit();
525+
526+
for (S32 i = 0; i < 58; i++)
527+
{
528+
voices[i].voice = NULL;
529+
voices[i].flags = 0;
530+
}
531+
532+
for (S32 i = 0; i < 6; i++)
533+
{
534+
streams[i].vinf.voice = 0;
535+
streams[i].vinf.flags = 0;
536+
streams[i].source_a = 0;
537+
streams[i].dest_a = 0;
538+
streams[i].dest_b = 0;
539+
streams[i].source_b = 0;
540+
streams[i].xe4 = 0;
541+
}
542+
543+
// FIXME: No idea what type this is, appears to only be used in this fuction.
544+
ua_stream_buffer = (U32*)OSAllocFromHeap(the_heap, 0x18100);
545+
stream_buffer = (U32*)(((U32)ua_stream_buffer + 0x1f) & ~0x1f);
546+
U32* local_buffer = stream_buffer;
547+
for (S32 i = 0; i < 0x100; i++)
548+
{
549+
local_buffer[i] = NULL;
550+
}
551+
552+
silence_buffer = ARAlloc(0x400);
553+
zero_point = silence_buffer;
554+
zero_point *= 2;
555+
zero_point += 2;
556+
zero_end = zero_point + 0x800;
557+
558+
SoundFlags |= 0x1;
559+
560+
BOOL enabled = OSDisableInterrupts();
561+
DCInvalidateRange((void*)silence_buffer, 0x400);
562+
ARQRequest request;
563+
ARQPostRequest(&request, 0, 0, 1, (u32)stream_buffer, silence_buffer, 0x400, arq_callback);
564+
OSRestoreInterrupts(enabled);
565+
566+
while (SoundFlags != 0)
567+
;
568+
569+
char str_buf[0x20];
570+
U32 r27 = 0;
571+
572+
struct Junk
573+
{
574+
U8 foo[0x4000];
575+
};
576+
577+
for (S32 i = 0; i < 6; i++)
578+
{
579+
u32 buf = ARAlloc(0x8000);
580+
sprintf(str_buf, "streaming channel %d", i);
581+
streams[i].dest_a = buf;
582+
streams[i].dest_b = buf + 0x4000;
583+
streams[i].source_a = (u32)stream_buffer + r27 + 0x4000;
584+
r27 += 0x4000;
585+
}
586+
AXRegisterCallback(fcb);
587+
}
588+
504589
void iSndExit()
505590
{
506591
soundInited = 0;
@@ -517,6 +602,73 @@ void iSndInitSceneLoaded()
517602
{
518603
}
519604

605+
bool iSndIsPlaying(U32 assetID)
606+
{
607+
if (assetID == 0)
608+
{
609+
return false;
610+
}
611+
612+
for (S32 i = 0; i < 6; i++)
613+
{
614+
if (gSnd.voice[i].assetID == assetID)
615+
{
616+
if(streams[i].vinf.flags & 0xC000 && (streams[i].vinf.flags & 0x82) == 0) {
617+
return true;
618+
}
619+
return false;
620+
}
621+
}
622+
623+
for(S32 i = 0; i < 0x3a; i++) {
624+
if(gSnd.voice[i+6].assetID == assetID) {
625+
if(voices[i].flags & 0x4 && (voices[i].flags & 0x8) == 0) {
626+
return true;
627+
}
628+
return false;
629+
}
630+
}
631+
return true;
632+
}
633+
634+
bool iSndIsPlaying(U32 assetID, U32 parid)
635+
{
636+
for(U32 i = 0; i < 0x40; i++) {
637+
if((assetID == 0 || gSnd.voice[i].assetID == assetID) && gSnd.voice[i].parentID == parid)
638+
{
639+
if(iSndIsPlaying(gSnd.voice[i].assetID)) {
640+
return true;
641+
};
642+
}
643+
}
644+
return false;
645+
}
646+
647+
bool iSndIsPlayingByHandle(U32 handle)
648+
{
649+
650+
if (handle == 0)
651+
{
652+
return false;
653+
}
654+
655+
for (S32 i = 0; i < 6; i++)
656+
{
657+
if (gSnd.voice[i].sndID == handle)
658+
{
659+
return (streams[i].vinf.flags & 0xC000 && (streams[i].vinf.flags & 0x82) == 0);
660+
}
661+
}
662+
663+
for(S32 i = 0; i < 0x3a; i++) {
664+
if(gSnd.voice[i+6].sndID == handle) {
665+
return (voices[i].flags & 0x4 && (voices[i].flags & 0x8) == 0);
666+
}
667+
}
668+
return false;
669+
670+
}
671+
520672
U32 iVolFromX(F32 param1)
521673
{
522674
float f = MAX(param1, 1e-20f);

src/SB/Core/gc/iSnd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ void iSndExit();
6767
void iSndSetEnvironmentalEffect(isound_effect);
6868
void iSndInitSceneLoaded();
6969

70-
S32 iSndIsPlaying(U32 assetID);
71-
S32 iSndIsPlaying(U32 assetID, U32 parid);
72-
S32 iSndIsPlayingByHandle(U32 handle);
70+
bool iSndIsPlaying(U32 assetID);
71+
bool iSndIsPlaying(U32 assetID, U32 parid);
72+
bool iSndIsPlayingByHandle(U32 handle);
7373
iSndFileInfo* iSndLookup(U32 id);
7474

7575
void iSndPause(U32 snd, U32 pause);

src/SB/Game/zEntPlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7544,7 +7544,7 @@ S32 zEntPlayerDyingInGoo()
75447544

75457545
WEAK U32 xSndIsPlaying(U32 assetID)
75467546
{
7547-
return (U8)iSndIsPlaying(assetID);
7547+
return iSndIsPlaying(assetID);
75487548
}
75497549

75507550
WEAK S32 zNPCTiki::IsHealthy()

src/SB/Game/zNPCTypeCommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3221,5 +3221,5 @@ S32 xPsyche::HasGoal(S32 goal)
32213221

32223222
U32 xSndIsPlaying(U32 assetID, U32 parid)
32233223
{
3224-
return iSndIsPlaying(assetID, parid) & 0xff;
3224+
return iSndIsPlaying(assetID, parid);
32253225
}

0 commit comments

Comments
 (0)