Trying to understand this thing

This commit is contained in:
KiritoDv 2025-01-17 12:37:06 -06:00
parent 0169c08350
commit c7507be77e
4 changed files with 83 additions and 73 deletions

View File

@ -517,20 +517,20 @@ typedef struct SequenceLayer {
} SequenceLayer; // size = 0x80
typedef struct UnkStruct_800097A8 {
/* 0x00 */ s16* unk_0;
/* 0x04 */ s32 unk_4;
/* 0x08 */ s32 unk_8;
/* 0x0C */ s16* unk_C;
/* 0x00 */ s16* inputBuffer;
/* 0x04 */ s32 remainingLength;
/* 0x08 */ s32 totalLength;
/* 0x0C */ s16* tempBuffer;
/* 0x10 */ char pad10[4];
/* 0x14 */ struct SampleDma* unk_14;
/* 0x18 */ s16 unk18;
/* 0x14 */ struct SampleDma* dma;
/* 0x18 */ s16 accumulator;
/* 0x1A */ char pad1A[6];
} UnkStruct_800097A8; /* size = 0x20 */
} DMADecompress; /* size = 0x20 */
typedef struct {
/* 0x000 */ s16 adpcmdecState[16];
/* 0x020 */ s16 finalResampleState[16];
/* 0x040 */ UnkStruct_800097A8 unk_40;
/* 0x040 */ DMADecompress unk_40;
/* 0x060 */ char pad[0x20];
/* 0x080 */ s16 panSamplesBuffer[0x20];
// /* 0x040 */ s16 mixEnvelopeState[32];

View File

@ -657,6 +657,9 @@ s32 AudioLoad_Dma(OSIoMesg* mesg, u32 priority, s32 direction, uintptr_t devAddr
OSMesgQueue* retQueue, s32 medium, const char* dmaType) {
OSPiHandle* handle;
memcpy(ramAddr, devAddr, size);
return 0;
// switch (medium) {
// case MEDIUM_CART:
// handle = osCartRomInit();
@ -795,9 +798,9 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData,
}
void AudioLoad_ProcessLoads(s32 resetStatus) {
// AudioLoad_ProcessSlowLoads(resetStatus);
// AudioLoad_ProcessSamplePreloads(resetStatus);
// AudioLoad_ProcessAsyncLoads(resetStatus);
AudioLoad_ProcessSlowLoads(resetStatus);
AudioLoad_ProcessSamplePreloads(resetStatus);
AudioLoad_ProcessAsyncLoads(resetStatus);
}
static const char devstr27[] = "Clear Workarea %x -%x size %x \n";
@ -907,6 +910,7 @@ s32 AudioLoad_SlowLoadSample(s32 fontId, u8 instId, s8* status) {
Sample* sample;
AudioSlowLoad* slowLoad;
*status = SLOW_LOAD_DONE;
sample = AudioLoad_GetFontSample(fontId, instId);
return 0;

View File

@ -2,6 +2,7 @@
#include "sf64audio_provisional.h"
#include "audio/mixer.h"
#include "endianness.h"
#include "port/Engine.h"
#define DMEM_WET_SCRATCH 0x470
#define DMEM_COMPRESSED_ADPCM_DATA 0x990
@ -390,7 +391,7 @@ void AudioSynth_HartleyTransform(f32* arg0, s32 arg1, f32* arg2) {
// https://decomp.me/scratch/TZQNS
#ifdef NON_MATCHING
void func_80009124(s16** arg0) {
void AudioSynth_DecodePCMChunk(s16** arg0) {
s16* var_a1;
s32 temp_a0;
u8 temp_s0;
@ -517,22 +518,22 @@ void func_80009124(s16** arg0) {
*arg0 = var_a1;
}
#else
void func_80009124(s16** arg0);
#pragma GLOBAL_ASM("asm/us/rev1/nonmatchings/audio/audio_synthesis/func_80009124.s")
void AudioSynth_DecodePCMChunk(s16** arg0);
#pragma GLOBAL_ASM("asm/us/rev1/nonmatchings/audio/audio_synthesis/AudioSynth_DecodePCMChunk.s")
#endif
void func_80009504(s16* arg0, UnkStruct_800097A8* arg1) {
void AudioSynth_DecodePCM(s16* arg0, DMADecompress* arg1) {
s32 i;
if (arg1->unk_0 != NULL) {
arg1->unk_C = arg1->unk_0;
arg1->unk_0 = 0;
if (arg1->inputBuffer != NULL) {
arg1->tempBuffer = arg1->inputBuffer;
arg1->inputBuffer = 0;
}
arg1->unk18 += D_8014C1B4;
while (arg1->unk18 > 0x1000) {
func_80009124(&arg1->unk_C);
arg1->unk18 -= 0x1000;
arg1->accumulator += D_8014C1B4;
while (arg1->accumulator > 0x1000) {
AudioSynth_DecodePCMChunk(&arg1->tempBuffer);
arg1->accumulator -= 0x1000;
}
AudioSynth_InverseDiscreteCosineTransform(D_80145D48, D_80146148, 8, D_80146548);
@ -551,66 +552,63 @@ void func_80009504(s16* arg0, UnkStruct_800097A8* arg1) {
}
}
s32 func_8000967C(s32 length, s16* ramAddr, UnkStruct_800097A8* arg2) {
s32 AudioSynth_DecompressSample(s32 length, s16* ramAddr, DMADecompress* arg2) {
s32 pad;
s32 temp_t0;
s32 chunkSize;
s32 i;
s32 var_s1;
s16* temp_t7 = (s16*) arg2->unk_14->ramAddr;
s32 sampleIdx;
s16* buffer = (s16*) arg2->dma->ramAddr;
for (i = 0; i < arg2->unk_4; i++) {
ramAddr[i] = temp_t7[i];
for (i = 0; i < arg2->remainingLength; i++) {
ramAddr[i] = buffer[i];
}
var_s1 = arg2->unk_4;
temp_t0 = (length - arg2->unk_4 + 0xFF) / 256;
arg2->unk_4 = (temp_t0 * 256) + arg2->unk_4 - length;
sampleIdx = arg2->remainingLength;
chunkSize = (length - arg2->remainingLength + 0xFF) / 256;
arg2->remainingLength = (chunkSize * 256) + arg2->remainingLength - length;
for (i = 0; i < temp_t0; i++) {
func_80009504(&ramAddr[var_s1], arg2);
var_s1 += 0x100;
for (i = 0; i < chunkSize; i++) {
AudioSynth_DecodePCM(&ramAddr[sampleIdx], arg2);
sampleIdx += 0x100;
}
for (i = 0; i < arg2->unk_4; i++) {
temp_t7[i] = ramAddr[length + i];
for (i = 0; i < arg2->remainingLength; i++) {
buffer[i] = ramAddr[length + i];
}
return temp_t0;
return chunkSize;
}
u8* func_800097A8(Sample* sample, s32 length, u32 flags, UnkStruct_800097A8* arg3) {
// @port: We don't need to do a dma call
return sample->sampleAddr;
static SampleDma pad2 = {0};
static SampleDma sp1C = {0};
u8* AudioSynth_ProcessDecompression(Sample* sample, s32 length, u32 flags, DMADecompress* arg3) {
s32 pad1;
SampleDma* pad2;
SampleDma* sp1C;
if(sp1C.ramAddr == NULL){
sp1C.ramAddr = GameEngine_Malloc(0x1000 * 2);
}
if(pad2.ramAddr == NULL){
pad2.ramAddr = GameEngine_Malloc(0x1000 * 2);
}
if (flags == A_INIT) {
arg3->unk_0 = (s16*) sample->sampleAddr;
arg3->unk_4 = 0;
arg3->unk_8 = 0;
arg3->unk18 = 0;
if (gSampleDmaReuseQueue1RdPos != gSampleDmaReuseQueue1WrPos) {
arg3->unk_14 = &gSampleDmas[gSampleDmaReuseQueue1[gSampleDmaReuseQueue1RdPos++]];
arg3->unk_14->devAddr = -1;
arg3->unk_14->sizeUnused = 0;
}
arg3->inputBuffer = (s16*) sample->sampleAddr;
arg3->remainingLength = 0;
arg3->totalLength = 0;
arg3->accumulator = 0;
arg3->dma = &pad2;
arg3->dma->devAddr = -1;
arg3->dma->sizeUnused = 0;
}
if (gSampleDmaReuseQueue1RdPos != gSampleDmaReuseQueue1WrPos) {
sp1C = &gSampleDmas[gSampleDmaReuseQueue1[gSampleDmaReuseQueue1RdPos++]];
}
if (1) {} //! FAKE
sp1C->ttl = 2;
sp1C.ttl = 2;
// @port: (uintptr_t)
sp1C->devAddr = (uintptr_t) sample->sampleAddr;
sp1C->sizeUnused = length * 2;
pad2 = arg3->unk_14;
pad2->ttl = 2;
arg3->unk_8 += func_8000967C(length, (s16*) sp1C->ramAddr, arg3);
return sp1C->ramAddr;
sp1C.devAddr = (uintptr_t) sample->sampleAddr;
sp1C.sizeUnused = length * 2;
pad2.ttl = 2;
arg3->totalLength += AudioSynth_DecompressSample(length, (s16*) sp1C.ramAddr, arg3);
return sp1C.ramAddr;
}
Acmd* AudioSynth_LoadRingBufferPart(Acmd* aList, u16 dmem, u16 startPos, s32 size, s32 reverbIndex) {
@ -888,6 +886,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisSta
s32 dmemUncompressedAddrOffset1;
u32 sampleslenFixedPoint;
u8* samplesToLoadAddr;
uintptr_t buffAddr;
s32 gain;
u32 nEntries;
s32 aligned;
@ -1009,7 +1008,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisSta
}
}
switch (bookSample->codec) {
switch ((uint8_t) bookSample->codec) {
case CODEC_ADPCM:
frameSize = 9;
skipInitialSamples = SAMPLES_PER_FRAME;
@ -1022,11 +1021,18 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisSta
sampleDmaStart = 0;
break;
case CODEC_S16_INMEMORY:
case CODEC_S16_INMEMORY: {
buffAddr = AudioSynth_ProcessDecompression(bookSample, numSamplesToLoadAdj, flags,
&synthState->synthesisBuffers->unk_40);
if (0) {}
aLoadBuffer(aList++, OS_K0_TO_PHYSICAL(buffAddr), DMEM_UNCOMPRESSED_NOTE,
(numSamplesToLoadAdj + SAMPLES_PER_FRAME) * 2);
flags = A_CONTINUE;
skipBytes = 0;
numSamplesProcessed = numSamplesToLoadAdj;
dmemUncompressedAddrOffset1 = numSamplesToLoadAdj;
goto skip;
}
case CODEC_S16:
skipBytes = 0;

View File

@ -11,9 +11,9 @@ std::shared_ptr<Ship::IResource> ResourceFactoryBinarySampleV1::ReadResource(std
auto sample = std::make_shared<Sample>(file->InitData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
sample->mSample.codec = reader->ReadUInt32();
sample->mSample.medium = reader->ReadUInt32();
sample->mSample.unk = reader->ReadUInt32();
sample->mSample.codec = reader->ReadUByte();
sample->mSample.medium = reader->ReadUByte();
sample->mSample.unk = reader->ReadUByte();
sample->mSample.size = reader->ReadUInt32();
sample->mSample.loop = LoadChild<AdpcmLoopData*>(reader->ReadUInt64());
sample->mSample.book = LoadChild<AdpcmBookData*>(reader->ReadUInt64());
@ -34,9 +34,9 @@ std::shared_ptr<Ship::IResource> ResourceFactoryBinarySampleV2::ReadResource(std
auto sample = std::make_shared<Sample>(file->InitData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
sample->mSample.codec = reader->ReadUInt32();
sample->mSample.medium = reader->ReadUInt32();
sample->mSample.unk = reader->ReadUInt32();
sample->mSample.codec = reader->ReadUByte();
sample->mSample.medium = reader->ReadUByte();
sample->mSample.unk = reader->ReadUByte();
sample->mSample.size = reader->ReadUInt32();
sample->mSample.tuning = reader->ReadFloat();
sample->mSample.loop = LoadChild<AdpcmLoopData*>(reader->ReadUInt64());