From 6393690103b49b5ecbc44bc5bf53355d050a54a0 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Sun, 3 Nov 2024 10:56:53 -0600 Subject: [PATCH] Removed 32 bit structs --- .gitignore | 3 +- include/sf64audio_provisional.h | 42 -------------- src/audio/audio_load.c | 70 +++++++++++------------ src/port/resource/loaders/AudioLoader.cpp | 9 ++- 4 files changed, 43 insertions(+), 81 deletions(-) diff --git a/.gitignore b/.gitignore index b1d2d12a..d8a373e1 100644 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,5 @@ starship.cfg.json Starship.log *.sav *.lib -*.pdb \ No newline at end of file +*.pdb +dumps/ \ No newline at end of file diff --git a/include/sf64audio_provisional.h b/include/sf64audio_provisional.h index 167a55b0..63bb5c3e 100644 --- a/include/sf64audio_provisional.h +++ b/include/sf64audio_provisional.h @@ -224,12 +224,6 @@ typedef struct { /* 0x08 */ s16* book; // size 8 * order * numPredictors. } AdpcmBook; // size >= 8, 0x8 aligned -typedef struct { - /* 0x00 */ s32 order; - /* 0x04 */ s32 numPredictors; - /* 0x08 */ u32 book; // size 8 * order * numPredictors. -} AdpcmBook32Bit; // size >= 8, 0x8 aligned - typedef struct { /* 0x00 */ u32 codec : 4; // The state of compression or decompression /* 0x00 */ u32 medium : 2; // Medium where sample is currently stored @@ -244,28 +238,11 @@ typedef struct { book; // Adpcm book parameters used by the sample. Offset from the start of the sound font / pointer to ram } Sample; // size = 0x10 -typedef struct { - /* 0x00 */ u32 codec : 4; // The state of compression or decompression - /* 0x00 */ u32 medium : 2; // Medium where sample is currently stored - /* 0x00 */ u32 unk_bit26 : 1; - /* 0x00 */ u32 isRelocated : 1; // Has the sample header been relocated (offsets to pointers) - /* 0x01 */ u32 size : 24; // Size of the sample - /* 0x04 */ u32 sampleAddr; // Raw sample data. Offset from the start of the sample bank or absolute address to - // either rom or ram - /* 0x08 */ u32 loop; // Adpcm loop parameters used by the sample. Offset from the start of the sound font / pointer to ram - /* 0x0C */ u32 book; // Adpcm book parameters used by the sample. Offset from the start of the sound font / pointer to ram -} Sample32Bit; // size = 0x10 - typedef struct { /* 0x00 */ Sample* sample; /* 0x04 */ f32 tuning; // frequency modulation factor } TunedSample;// size = 0x8 -typedef struct { - /* 0x00 */ u32 sample; - /* 0x04 */ f32 tuning; // frequency modulation factor -} TunedSample32Bit; - typedef struct { /* 0x00 */ u8 isRelocated; // have the envelope and all samples been relocated (offsets to pointers) /* 0x01 */ u8 normalRangeLo; @@ -277,17 +254,6 @@ typedef struct { /* 0x18 */ TunedSample highPitchTunedSample; } Instrument; // size = 0x20 -typedef struct { - /* 0x00 */ u8 isRelocated; // have the envelope and all samples been relocated (offsets to pointers) - /* 0x01 */ u8 normalRangeLo; - /* 0x02 */ u8 normalRangeHi; - /* 0x03 */ u8 adsrDecayIndex; // index used to obtain adsr decay rate from adsrDecayTable - /* 0x04 */ u32 envelope; - /* 0x08 */ TunedSample32Bit lowPitchTunedSample; - /* 0x10 */ TunedSample32Bit normalPitchTunedSample; - /* 0x18 */ TunedSample32Bit highPitchTunedSample; -} Instrument32Bit; // size = 0x20 - typedef struct { /* 0x00 */ u8 adsrDecayIndex; // index used to obtain adsr decay rate from adsrDecayTable /* 0x01 */ u8 pan; @@ -296,14 +262,6 @@ typedef struct { /* 0x0C */ EnvelopePoint* envelope; } Drum; // size = 0x10 -typedef struct { - /* 0x00 */ u8 adsrDecayIndex; // index used to obtain adsr decay rate from adsrDecayTable - /* 0x01 */ u8 pan; - /* 0x02 */ u8 isRelocated; // have tunedSample.sample and envelope been relocated (offsets to pointers) - /* 0x04 */ TunedSample tunedSample; - /* 0x0C */ EnvelopePoint* envelope; -} Drum32Bit; // size = 0x10 - typedef struct { /* 0x00 */ TunedSample tunedSample; } SoundEffect; // size = 0x08 diff --git a/src/audio/audio_load.c b/src/audio/audio_load.c index 5c9678ed..ef464289 100644 --- a/src/audio/audio_load.c +++ b/src/audio/audio_load.c @@ -1209,41 +1209,41 @@ static const char devstr50[] = "Error: Already wavetable is touched %x.\n"; static const char devstr51[] = "Touch Warning: Length zero %x\n"; void AudioLoad_RelocateSample(TunedSample* tSample, u32 fontDataAddr, SampleBankRelocInfo* relocInfo) { - Sample32Bit* baseSample = fontDataAddr + BSWAP32(tSample->sample); - - // "Touch Warning: Length zero %x\n"; - if ((baseSample->size != 0) && (baseSample->isRelocated != 1)) { - Sample* output = memalloc(sizeof(Sample)); - - output->loop = Audio_LoadLoop(fontDataAddr + BSWAP32(baseSample->loop)); - output->book = Audio_LoadBook(fontDataAddr + BSWAP32(baseSample->book)); - output->codec = baseSample->codec; - output->medium = baseSample->medium; - output->unk_bit26 = baseSample->unk_bit26; - output->isRelocated = baseSample->isRelocated; - output->size = baseSample->size; - - output->isRelocated = 1; - switch (baseSample->medium) { - case MEDIUM_RAM: -// baseSample->sampleAddr = Audio_LoadCopy(relocInfo->baseAddr1 + BSWAP32(baseSample->sampleAddr), BSWAP32(baseSample->size)); - baseSample->medium = relocInfo->medium1; - break; - case MEDIUM_UNK: -// baseSample->sampleAddr = Audio_LoadCopy(relocInfo->baseAddr2 + BSWAP32(baseSample->sampleAddr), BSWAP32(baseSample->size)); - baseSample->medium = relocInfo->medium2; - break; - case MEDIUM_CART: - case MEDIUM_DISK_DRIVE: - output->sampleAddr = fontDataAddr + BSWAP32(baseSample->sampleAddr); - break; - } - - baseSample->isRelocated = true; - if (baseSample->unk_bit26 && (baseSample->medium != 0)) { - gUsedSamples[gNumUsedSamples++] = output; - } - } +// Sample32Bit* baseSample = fontDataAddr + BSWAP32(tSample->sample); +// +// // "Touch Warning: Length zero %x\n"; +// if ((baseSample->size != 0) && (baseSample->isRelocated != 1)) { +// Sample* output = memalloc(sizeof(Sample)); +// +// output->loop = Audio_LoadLoop(fontDataAddr + BSWAP32(baseSample->loop)); +// output->book = Audio_LoadBook(fontDataAddr + BSWAP32(baseSample->book)); +// output->codec = baseSample->codec; +// output->medium = baseSample->medium; +// output->unk_bit26 = baseSample->unk_bit26; +// output->isRelocated = baseSample->isRelocated; +// output->size = baseSample->size; +// +// output->isRelocated = 1; +// switch (baseSample->medium) { +// case MEDIUM_RAM: +//// baseSample->sampleAddr = Audio_LoadCopy(relocInfo->baseAddr1 + BSWAP32(baseSample->sampleAddr), BSWAP32(baseSample->size)); +// baseSample->medium = relocInfo->medium1; +// break; +// case MEDIUM_UNK: +//// baseSample->sampleAddr = Audio_LoadCopy(relocInfo->baseAddr2 + BSWAP32(baseSample->sampleAddr), BSWAP32(baseSample->size)); +// baseSample->medium = relocInfo->medium2; +// break; +// case MEDIUM_CART: +// case MEDIUM_DISK_DRIVE: +// output->sampleAddr = fontDataAddr + BSWAP32(baseSample->sampleAddr); +// break; +// } +// +// baseSample->isRelocated = true; +// if (baseSample->unk_bit26 && (baseSample->medium != 0)) { +// gUsedSamples[gNumUsedSamples++] = output; +// } +// } } static const char devstr52[] = "It's busy now!!!!! %d\n"; diff --git a/src/port/resource/loaders/AudioLoader.cpp b/src/port/resource/loaders/AudioLoader.cpp index 541af702..4ebe0d74 100644 --- a/src/port/resource/loaders/AudioLoader.cpp +++ b/src/port/resource/loaders/AudioLoader.cpp @@ -126,16 +126,19 @@ Sample* Audio_LoadSample(uint32_t sampleAddr, AudioTableEntry entry, uint32_t sa Sample* sample = memalloc(Sample); uint32_t flags = reader.ReadUInt32(); + uint32_t addr = reader.ReadUInt32(); + sample->codec = (flags >> 28) & 0x0F; - sample->medium = MEDIUM_RAM; // (flags >> 24) & 0x03; + sample->medium = (flags >> 24) & 0x03; sample->unk_bit26 = (flags >> 22) & 0x01; sample->size = flags; - uint32_t addr = reader.ReadUInt32(); sample->loop = Audio_LoadLoop(entry.romAddr + reader.ReadUInt32()); sample->book = Audio_LoadBook(entry.romAddr + reader.ReadUInt32()); - sample->isRelocated = 1; sample->sampleAddr = (uint8_t*) Audio_LoadBlob(gAudioTable, gSampleBankTable->entries[sampleBankID].romAddr + addr); + sample->isRelocated = 1; + sample->medium = MEDIUM_RAM; + std::filesystem::path path{ "dumps/" + std::to_string(addr) + ".raw" }; std::ofstream ofs(path); ofs.write(reinterpret_cast(sample->sampleAddr), sample->size);