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
5 changes: 4 additions & 1 deletion src/SB/Core/gc/iMemMgr.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#ifndef IMEMMGR_H
#define IMEMMGR_H

#include "dolphin/os/OSAlloc.h"
#include <types.h>

extern volatile OSHeapHandle the_heap;

void iMemInit();
void iMemExit();

#endif
#endif
164 changes: 158 additions & 6 deletions src/SB/Core/gc/iSnd.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "iSnd.h"

#include "dolphin/ai.h"
#include "dolphin/os.h"
#include "dolphin/os/OSAlloc.h"
#include "dolphin/os/OSCache.h"
#include "iMemMgr.h"
#include "iTRC.h"
#include "xSnd.h"
#include "xstransvc.h"
Expand All @@ -10,16 +15,19 @@
#include <dolphin/dvd/dvd.h>
#include <dolphin/mix.h>

#include <stdio.h>
#include <types.h>

u32 aram_array[40];

// Size: 0x20
// This was not in dwarf data
struct vinfo
{
_AXVPB* voice;
U32 flags;
U32 aid;
U8 buf[4];
U32 xc;
S32 x10;
S32 x14;
S32 x18;
Expand Down Expand Up @@ -52,9 +60,12 @@ UNK_STREAM streams[6];

vinfo voices[58];

u32 zero_point = 0;
u32 zero_end = 0;
S32 SoundFlags = 0;
U32* ua_stream_buffer = NULL; //unaligned stream buffer
U32* stream_buffer = 0;
u32 silence_buffer = 0;
volatile u32 zero_point = 0;
volatile u32 zero_end = 0;
volatile U32 SoundFlags = 0;
volatile S32 fc = 0;
static char soundInited = 0;
U32 houston_we_have_a_problem = 0;
Expand Down Expand Up @@ -453,14 +464,16 @@ static void fcb()
}
}

if (streams[i].vinf.x10 == streams[i].vinf.x14 && streams[i].vinf.x18 == streams[i].vinf.x1c)
if (streams[i].vinf.x10 == streams[i].vinf.x14 &&
streams[i].vinf.x18 == streams[i].vinf.x1c)
{
continue;
}

streams[i].vinf.x14 = streams[i].vinf.x10;
streams[i].vinf.x1c = streams[i].vinf.x18;
MIXAdjustInput(streams[i].vinf.voice, streams[i].vinf.x14 - MIXGetInput(streams[i].vinf.voice));
MIXAdjustInput(streams[i].vinf.voice,
streams[i].vinf.x14 - MIXGetInput(streams[i].vinf.voice));
MIXAdjustPan(streams[i].vinf.voice, streams[i].vinf.x1c - MIXGetPan(streams[i].vinf.voice));
need_update = TRUE;
}
Expand Down Expand Up @@ -501,6 +514,78 @@ static void fcb()
}
}

void iSndInit()
{
soundInited = 1;
AIInit(NULL);
ARInit(aram_array, 40);
ARQInit();
AXInit();
MIXInit();

for (S32 i = 0; i < 58; i++)
{
voices[i].voice = NULL;
voices[i].flags = 0;
}

for (S32 i = 0; i < 6; i++)
{
streams[i].vinf.voice = 0;
streams[i].vinf.flags = 0;
streams[i].source_a = 0;
streams[i].dest_a = 0;
streams[i].dest_b = 0;
streams[i].source_b = 0;
streams[i].xe4 = 0;
}

// FIXME: No idea what type this is, appears to only be used in this fuction.
ua_stream_buffer = (U32*)OSAllocFromHeap(the_heap, 0x18100);
stream_buffer = (U32*)(((U32)ua_stream_buffer + 0x1f) & ~0x1f);
U32* local_buffer = stream_buffer;
for (S32 i = 0; i < 0x100; i++)
{
local_buffer[i] = NULL;
}

silence_buffer = ARAlloc(0x400);
zero_point = silence_buffer;
zero_point *= 2;
zero_point += 2;
zero_end = zero_point + 0x800;

SoundFlags |= 0x1;

BOOL enabled = OSDisableInterrupts();
DCInvalidateRange((void*)silence_buffer, 0x400);
ARQRequest request;
ARQPostRequest(&request, 0, 0, 1, (u32)stream_buffer, silence_buffer, 0x400, arq_callback);
OSRestoreInterrupts(enabled);

while (SoundFlags != 0)
;

char str_buf[0x20];
U32 r27 = 0;

struct Junk
{
U8 foo[0x4000];
};

for (S32 i = 0; i < 6; i++)
{
u32 buf = ARAlloc(0x8000);
sprintf(str_buf, "streaming channel %d", i);
streams[i].dest_a = buf;
streams[i].dest_b = buf + 0x4000;
streams[i].source_a = (u32)stream_buffer + r27 + 0x4000;
r27 += 0x4000;
}
AXRegisterCallback(fcb);
}

void iSndExit()
{
soundInited = 0;
Expand All @@ -517,6 +602,73 @@ void iSndInitSceneLoaded()
{
}

bool iSndIsPlaying(U32 assetID)
{
if (assetID == 0)
{
return false;
}

for (S32 i = 0; i < 6; i++)
{
if (gSnd.voice[i].assetID == assetID)
{
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) {
return true;
}
return false;
}
}
return true;
}

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)
{
if(iSndIsPlaying(gSnd.voice[i].assetID)) {
return true;
};
}
}
return false;
}

bool iSndIsPlayingByHandle(U32 handle)
{

if (handle == 0)
{
return false;
}

for (S32 i = 0; i < 6; i++)
{
if (gSnd.voice[i].sndID == handle)
{
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) {
return (voices[i].flags & 0x4 && (voices[i].flags & 0x8) == 0);
}
}
return false;

}

U32 iVolFromX(F32 param1)
{
float f = MAX(param1, 1e-20f);
Expand Down
6 changes: 3 additions & 3 deletions src/SB/Core/gc/iSnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ void iSndExit();
void iSndSetEnvironmentalEffect(isound_effect);
void iSndInitSceneLoaded();

S32 iSndIsPlaying(U32 assetID);
S32 iSndIsPlaying(U32 assetID, U32 parid);
S32 iSndIsPlayingByHandle(U32 handle);
bool iSndIsPlaying(U32 assetID);
bool iSndIsPlaying(U32 assetID, U32 parid);
bool iSndIsPlayingByHandle(U32 handle);
iSndFileInfo* iSndLookup(U32 id);

void iSndPause(U32 snd, U32 pause);
Expand Down
2 changes: 1 addition & 1 deletion src/SB/Game/zEntPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7544,7 +7544,7 @@ S32 zEntPlayerDyingInGoo()

WEAK U32 xSndIsPlaying(U32 assetID)
{
return (U8)iSndIsPlaying(assetID);
return iSndIsPlaying(assetID);
}

WEAK S32 zNPCTiki::IsHealthy()
Expand Down
2 changes: 1 addition & 1 deletion src/SB/Game/zNPCTypeCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3221,5 +3221,5 @@ S32 xPsyche::HasGoal(S32 goal)

U32 xSndIsPlaying(U32 assetID, U32 parid)
{
return iSndIsPlaying(assetID, parid) & 0xff;
return iSndIsPlaying(assetID, parid);
}