Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 212 additions & 12 deletions src/SB/Core/gc/iSnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,16 +613,20 @@ bool iSndIsPlaying(U32 assetID)
{
if (gSnd.voice[i].assetID == assetID)
{
if(streams[i].vinf.flags & 0xC000 && (streams[i].vinf.flags & 0x82) == 0) {
if (streams[i].vinf.flags & 0xC000 && (streams[i].vinf.flags & 0x82) == 0)
{
return true;
}
return false;
}
}

for(S32 i = 0; i < 0x3a; i++) {
if(gSnd.voice[i+6].assetID == assetID) {
if(voices[i].flags & 0x4 && (voices[i].flags & 0x8) == 0) {
for (S32 i = 0; i < 0x3a; i++)
{
if (gSnd.voice[i + 6].assetID == assetID)
{
if (voices[i].flags & 0x4 && (voices[i].flags & 0x8) == 0)
{
return true;
}
return false;
Expand All @@ -633,10 +637,12 @@ bool iSndIsPlaying(U32 assetID)

bool iSndIsPlaying(U32 assetID, U32 parid)
{
for(U32 i = 0; i < 0x40; i++) {
if((assetID == 0 || gSnd.voice[i].assetID == assetID) && gSnd.voice[i].parentID == parid)
for (U32 i = 0; i < 0x40; i++)
{
if ((assetID == 0 || gSnd.voice[i].assetID == assetID) && gSnd.voice[i].parentID == parid)
{
if(iSndIsPlaying(gSnd.voice[i].assetID)) {
if (iSndIsPlaying(gSnd.voice[i].assetID))
{
return true;
};
}
Expand All @@ -646,7 +652,6 @@ bool iSndIsPlaying(U32 assetID, U32 parid)

bool iSndIsPlayingByHandle(U32 handle)
{

if (handle == 0)
{
return false;
Expand All @@ -656,17 +661,18 @@ bool iSndIsPlayingByHandle(U32 handle)
{
if (gSnd.voice[i].sndID == handle)
{
return (streams[i].vinf.flags & 0xC000 && (streams[i].vinf.flags & 0x82) == 0);
return (streams[i].vinf.flags & 0xC000 && (streams[i].vinf.flags & 0x82) == 0);
}
}

for(S32 i = 0; i < 0x3a; i++) {
if(gSnd.voice[i+6].sndID == handle) {
for (S32 i = 0; i < 0x3a; i++)
{
if (gSnd.voice[i + 6].sndID == handle)
{
return (voices[i].flags & 0x4 && (voices[i].flags & 0x8) == 0);
}
}
return false;

}

U32 iVolFromX(F32 param1)
Expand All @@ -686,6 +692,18 @@ U32 iVolFromX(F32 param1)
}
}

void iSndCalcVol(xSndVoiceInfo* vp, vinfo* info)
{
S32 vol = iVolFromX(vp->vol * gSnd.categoryVolFader[vp->category]);

info->x10 = vol;
info->x14 = vol;
info->x18 = 0x40;
info->x1c = 0x40;
MIXAdjustFader(info->voice, vol - MIXGetFader(info->voice));
MIXAdjustPan(info->voice, 0x40 - MIXGetPan(info->voice));
}

void iSndVolUpdate(xSndVoiceInfo* info, vinfo* vinfo)
{
MIXUnMute(vinfo->voice);
Expand Down Expand Up @@ -716,6 +734,75 @@ void iSndUpdateSounds()
}
}

S32 iSndPlay(xSndVoiceInfo* vp)
{
S32 offset = (S32)vp - (S32)gSnd.voice;
S32 div = offset / 100;

xSTAssetName(vp->assetID);

if ((div < 0) || (div >= 64))
{
return 0;
}
else if (div < 6)
{
U32 ret = iSndPrepStream(vp);
if (ret < 0x3a)
{
if (vp->flags & 0x200)
{
return iSndPlayMemStream(vp);
}
else
{
return iSndPlayStream(vp);
}
}
return ret;
}
else
{
return iSndPlaySound(vp);
}
}

void iSndSetVol(U32 snd, F32 vol)
{
xSndVoiceInfo* vp = &gSnd.voice[0];

S32 i = 0;
for (; i < 64; i++, vp++)
{
if (vp->sndID == snd)
break;
}

if (i != 64)
{
vp->vol = vol;
S32 adj = iVolFromX(vol * gSnd.categoryVolFader[vp->category]);
vinfo* info;
if (i < 6)
{
info = &streams[i].vinf;
}
else
{
info = &voices[i - 6];
}
if (info->voice != 0)
{
info->x10 = adj;
info->x14 = adj;
info->x18 = 0x40;
info->x1c = 0x40;
MIXAdjustFader(info->voice, adj - MIXGetFader(info->voice));
MIXAdjustPan(info->voice, 0x40 - MIXGetPan(info->voice));
}
}
}

void iSndStartStereo(U32 id1, U32 id2, F32 pitch)
{
}
Expand Down Expand Up @@ -778,7 +865,45 @@ void sndloadcb(tag_xFile* tag)
{
SoundFlags = 0;
}
/* Matching
void iSndDIEDIEDIE()
Comment on lines +868 to +869

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna be real I just want the 69.67% bot message in the discord 😭
Part 2 PR coming up

{
if (!soundInited)
{
return;
}

OSDisableInterrupts();
soundInited = 0;

for (S32 i = 0; i < (S32)(sizeof(streams) / (sizeof(UNK_STREAM))); i++)
{
UNK_STREAM* pv = &streams[i];

if (pv->vinf.voice != NULL)
{
MIXReleaseChannel(pv->vinf.voice);
AXSetVoiceState(pv->vinf.voice, 0);
iSndMyAXFree(&pv->vinf.voice);
}
pv++;
}

for (S32 i = 0; i < (S32)(sizeof(voices) / (sizeof(vinfo))); i++)
{
vinfo* v = &voices[i];

if ((v->voice != NULL))
{
MIXReleaseChannel(v->voice);
AXSetVoiceState(v->voice, 0);
iSndMyAXFree(&v->voice);
}
}

AXQuit();
}
*/
void iSndSetExternalCallback(iSndExternalCallback callback)
{
}
Expand All @@ -791,3 +916,78 @@ void iSndMyAXFree(_AXVPB** param1)
*param1 = NULL;
}
}

void iSndSuspend()
{
AXRegisterCallback(0);

for (S32 i = 0; i < (S32)(sizeof(streams) / (sizeof(UNK_STREAM))); i++)
{
UNK_STREAM* pv = &streams[i];

if (pv->vinf.voice != NULL)
{
AXSetVoiceState(pv->vinf.voice, 0);
}
pv++;
}

for (S32 i = 0; i < (S32)(sizeof(voices) / (sizeof(vinfo))); i++)
{
vinfo* v = &voices[i];

if ((v->voice != NULL))
{
AXSetVoiceState(v->voice, 0);
}
}
}

void iSndResume()
{
for (S32 i = 0; i < (S32)(sizeof(streams) / (sizeof(UNK_STREAM))); i++)
{
UNK_STREAM* pv = &streams[i];

if ((pv->vinf.voice != NULL) && !(pv->vinf.flags & 2))
{
AXSetVoiceState(pv->vinf.voice, 1);
}
pv++;
}

for (S32 i = 0; i < (S32)(sizeof(voices) / (sizeof(vinfo))); i++)
{
vinfo* v = &voices[i];

if ((v->voice != NULL) && !(v->flags & 8))
{
AXSetVoiceState(v->voice, 1);
}
}

AXRegisterCallback(fcb);
}

F32 iSndGetVol(U32 snd)
{
xSndVoiceInfo* vp = &gSnd.voice[0];

for (int i = 0; i < 0x40; i++)
{
if (vp->flags & 1)
{
if (vp->sndID == snd)
{
if (gSnd.categoryVolFader[vp->category] <= 0.0f)
{
return 0.0f;
}
return (vp->vol / gSnd.categoryVolFader[vp->category]);
}
}
vp++;
}

return 0.0f;
}
6 changes: 5 additions & 1 deletion src/SB/Core/gc/iSnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ void iSndUpdate();

void iSndFindFreeVoice(U32 priority, U32 flags, U32 owner);

void iSndPlay(xSndVoiceInfo* vp);
S32 iSndPlay(xSndVoiceInfo* vp);
S32 iSndPrepStream(xSndVoiceInfo *);
S32 iSndPlayStream(xSndVoiceInfo *);
S32 iSndPlayMemStream(xSndVoiceInfo *);
S32 iSndPlaySound(xSndVoiceInfo *);
void iSndSetVol(U32 snd, F32 vol);
void iSndSetPitch(U32 snd, F32 pitch);
void iSndStartStereo(U32 id1, U32 id2, F32 pitch);
Expand Down
Loading