mirror of
https://github.com/HarbourMasters/Starship.git
synced 2025-02-09 03:37:49 +03:00
Fixed audio decompression, -100 mental points for Lywx
This commit is contained in:
parent
820da896e3
commit
01afbc67b7
@ -76,9 +76,9 @@ d064229a32cc05ab85e2381ce07744eb3ffaf530:
|
||||
logging: INFO
|
||||
output:
|
||||
binary: ./mods/sf64jp.o2r
|
||||
code: src/assets
|
||||
code: srcjp/assets
|
||||
headers: include/assets
|
||||
modding: src/assets
|
||||
modding: srcjp/assets
|
||||
# enums:
|
||||
# - include/sf64object.h
|
||||
# - include/sf64level.h
|
||||
|
@ -795,7 +795,7 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData,
|
||||
}
|
||||
|
||||
void AudioLoad_ProcessLoads(s32 resetStatus) {
|
||||
// AudioLoad_ProcessSlowLoads(resetStatus);
|
||||
AudioLoad_ProcessSlowLoads(resetStatus);
|
||||
// AudioLoad_ProcessSamplePreloads(resetStatus);
|
||||
// AudioLoad_ProcessAsyncLoads(resetStatus);
|
||||
}
|
||||
@ -907,9 +907,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;
|
||||
|
||||
if (sample == NULL) {
|
||||
*status = SLOW_LOAD_STATUS_0;
|
||||
@ -928,8 +926,7 @@ s32 AudioLoad_SlowLoadSample(s32 fontId, u8 instId, s8* status) {
|
||||
slowLoad->sample = *sample;
|
||||
slowLoad->status = status;
|
||||
|
||||
slowLoad->curRamAddr =
|
||||
AudioHeap_AllocTemporarySampleCache(sample->size, fontId, sample->sampleAddr, sample->medium);
|
||||
slowLoad->curRamAddr = GameEngine_Malloc(sample->size);
|
||||
|
||||
if (slowLoad->curRamAddr == NULL) {
|
||||
if ((sample->medium == MEDIUM_UNK) || (sample->codec == 2)) {
|
||||
|
@ -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
|
||||
|
@ -55,8 +55,8 @@ bool gEnableGammaBoost = true;
|
||||
void AudioThread_CreateNextAudioBuffer(int16_t* samples, uint32_t num_samples);
|
||||
}
|
||||
|
||||
std::vector<uint8_t*> MemoryPool;
|
||||
GameEngine* GameEngine::Instance;
|
||||
static GamePool MemoryPool = { .chunk = 1024 * 512, .cursor = 0, .length = 0, .memory = nullptr };
|
||||
|
||||
GameEngine::GameEngine() {
|
||||
std::vector<std::string> archiveFiles;
|
||||
@ -284,7 +284,10 @@ void GameEngine::Create() {
|
||||
void GameEngine::Destroy() {
|
||||
PortEnhancements_Exit();
|
||||
AudioExit();
|
||||
free(MemoryPool.memory);
|
||||
for (auto ptr : MemoryPool) {
|
||||
free(ptr);
|
||||
}
|
||||
MemoryPool.clear();
|
||||
}
|
||||
|
||||
void GameEngine::StartFrame() const {
|
||||
@ -749,27 +752,16 @@ extern "C" int32_t OTRConvertHUDXToScreenX(int32_t v) {
|
||||
}
|
||||
|
||||
extern "C" void* GameEngine_Malloc(size_t size) {
|
||||
// This is really wrong
|
||||
return malloc(size);
|
||||
// TODO: Kenix please take a look at this, i think it works but you are better at this
|
||||
|
||||
const auto chunk = MemoryPool.chunk;
|
||||
|
||||
if (size == 0) {
|
||||
return nullptr;
|
||||
MemoryPool.push_back(new uint8_t[size]);
|
||||
return (void*) MemoryPool.back();
|
||||
}
|
||||
|
||||
if (MemoryPool.cursor + size < MemoryPool.length) {
|
||||
const auto res = static_cast<uint8_t*>(MemoryPool.memory) + MemoryPool.cursor;
|
||||
MemoryPool.cursor += size;
|
||||
// SPDLOG_INFO("Allocating {} into memory pool", size);
|
||||
return res;
|
||||
extern "C" void GameEngine_Free(void* ptr) {
|
||||
for (auto it = MemoryPool.begin(); it != MemoryPool.end(); ++it) {
|
||||
if (*it == ptr) {
|
||||
free(ptr);
|
||||
MemoryPool.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MemoryPool.length += chunk;
|
||||
MemoryPool.memory =
|
||||
MemoryPool.memory == nullptr ? malloc(MemoryPool.length) : realloc(MemoryPool.memory, MemoryPool.length);
|
||||
memset(static_cast<uint8_t*>(MemoryPool.memory) + MemoryPool.length, 0, MemoryPool.length - chunk);
|
||||
SPDLOG_INFO("Memory pool resized from {} to {}", MemoryPool.length - chunk, MemoryPool.length);
|
||||
return GameEngine_Malloc(size);
|
||||
}
|
@ -11,16 +11,25 @@ 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());
|
||||
sample->mSample.sampleAddr = new uint8_t[sample->mSample.size];
|
||||
reader->Read((char*) sample->mSample.sampleAddr, sample->mSample.size);
|
||||
|
||||
if(sample->mSample.codec == 2){
|
||||
sample->mSample.medium = 2;
|
||||
for(size_t i = 0; i < sample->mSample.size / 2; i++){
|
||||
int16_t* sampleData = (int16_t*) sample->mSample.sampleAddr;
|
||||
sampleData[i] = BSWAP16(sampleData[i]);
|
||||
}
|
||||
} else {
|
||||
sample->mSample.medium = 0;
|
||||
}
|
||||
|
||||
sample->mSample.isRelocated = 1;
|
||||
|
||||
return sample;
|
||||
@ -34,9 +43,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());
|
||||
@ -44,7 +53,16 @@ std::shared_ptr<Ship::IResource> ResourceFactoryBinarySampleV2::ReadResource(std
|
||||
sample->mSample.sampleAddr = new uint8_t[sample->mSample.size];
|
||||
reader->Read((char*) sample->mSample.sampleAddr, sample->mSample.size);
|
||||
|
||||
if(sample->mSample.codec == 2){
|
||||
sample->mSample.medium = 2;
|
||||
for(size_t i = 0; i < sample->mSample.size / 2; i++){
|
||||
int16_t* sampleData = (int16_t*) sample->mSample.sampleAddr;
|
||||
sampleData[i] = BSWAP16(sampleData[i]);
|
||||
}
|
||||
} else {
|
||||
sample->mSample.medium = 0;
|
||||
}
|
||||
|
||||
sample->mSample.isRelocated = 1;
|
||||
|
||||
return sample;
|
||||
|
Loading…
Reference in New Issue
Block a user