Format and fix mixer for Windows

This commit is contained in:
louist103 2025-04-30 21:34:15 -04:00
commit 630c814f0c
14 changed files with 234 additions and 237 deletions

View file

@ -418,12 +418,12 @@ void OTRGlobals::Initialize() {
RESOURCE_FORMAT_BINARY, "AudioSoundFont",
static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSoundFont), 2);
loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryXMLSoundFontV0>(), RESOURCE_FORMAT_XML,
"SoundFont", static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSoundFont), 0);
"SoundFont", static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSoundFont), 0);
loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryAudioSequenceV2>(),
RESOURCE_FORMAT_BINARY, "AudioSequence",
static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSequence), 2);
loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryXMLAudioSequenceV0>(), RESOURCE_FORMAT_XML,
"Sequence", static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSequence), 0);
"Sequence", static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSequence), 0);
loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryBackgroundV0>(), RESOURCE_FORMAT_BINARY,
"Background", static_cast<uint32_t>(SOH::ResourceType::SOH_Background), 0);

View file

@ -16,7 +16,6 @@
#define ROUND_UP_8(v) (((v) + 7) & ~7)
#define ROUND_DOWN_16(v) ((v) & ~0xf)
#define DMEM_BUF_SIZE (0x1000 - 0x3C0 - 0x40)
#define BUF_U8(a) (rspa.buf.as_u8 + ((a)-0x3C0))
#define BUF_S16(a) (rspa.buf.as_s16 + ((a)-0x3C0) / sizeof(int16_t))
@ -38,7 +37,7 @@ static struct {
uint16_t filter_count;
int16_t filter[8];
__attribute__((aligned(16))) union {
union {
int16_t as_s16[DMEM_BUF_SIZE / sizeof(int16_t)];
uint8_t as_u8[DMEM_BUF_SIZE];
} buf;

View file

@ -346,8 +346,7 @@ uint8_t ResourceFactoryXMLAudioSampleV0::CodecStrToInt(const char* str, const ch
return CODEC_S16;
} else {
char buff[2048];
snprintf(buff, 2048,
"Invalid codec in %s. Got %s, expected ADPCM, S8, S16MEM, ADPCMSMALL, REVERB, S16.", file,
snprintf(buff, 2048, "Invalid codec in %s. Got %s, expected ADPCM, S8, S16MEM, ADPCMSMALL, REVERB, S16.", file,
str);
throw std::runtime_error(buff);
}

View file

@ -6,18 +6,18 @@
namespace SOH {
class ResourceFactoryBinaryAudioSampleV2 final : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
class ResourceFactoryXMLAudioSampleV0 final : public Ship::ResourceFactoryXML {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
private:
static uint8_t CodecStrToInt(const char* str, const char* file);
};
private:
static uint8_t CodecStrToInt(const char* str, const char* file);
};
} // namespace SOH

View file

@ -6,15 +6,15 @@
namespace SOH {
class ResourceFactoryBinaryAudioSequenceV2 final : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
class ResourceFactoryXMLAudioSequenceV0 final : public Ship::ResourceFactoryXML {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
} // namespace SOH

View file

@ -7,24 +7,24 @@
namespace SOH {
class ResourceFactoryBinaryAudioSoundFontV2 final : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
class ResourceFactoryXMLSoundFontV0 final : public Ship::ResourceFactoryXML {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
static int8_t MediumStrToInt(const char* str, const char* file);
static int8_t CachePolicyToInt(const char* str, const char* file);
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
static int8_t MediumStrToInt(const char* str, const char* file);
static int8_t CachePolicyToInt(const char* str, const char* file);
private:
void ParseDrums(AudioSoundFont* soundFont, tinyxml2::XMLElement* element);
void ParseInstruments(AudioSoundFont* soundFont, tinyxml2::XMLElement* element);
void ParseSfxTable(AudioSoundFont* soundFont, tinyxml2::XMLElement* element);
std::vector<AdsrEnvelope> ParseEnvelopes(AudioSoundFont* soundFont, tinyxml2::XMLElement* element,
unsigned int* count);
};
private:
void ParseDrums(AudioSoundFont* soundFont, tinyxml2::XMLElement* element);
void ParseInstruments(AudioSoundFont* soundFont, tinyxml2::XMLElement* element);
void ParseSfxTable(AudioSoundFont* soundFont, tinyxml2::XMLElement* element);
std::vector<AdsrEnvelope> ParseEnvelopes(AudioSoundFont* soundFont, tinyxml2::XMLElement* element,
unsigned int* count);
};
} // namespace SOH

View file

@ -1,19 +1,19 @@
#include "AudioSample.h"
namespace SOH {
AudioSample::~AudioSample() {
if (sample.book != nullptr && sample.book->book != nullptr) {
delete[] sample.book->book;
}
if (sample.sampleAddr != nullptr) {
delete[] sample.sampleAddr;
}
AudioSample::~AudioSample() {
if (sample.book != nullptr && sample.book->book != nullptr) {
delete[] sample.book->book;
}
Sample* AudioSample::GetPointer() {
return &sample;
if (sample.sampleAddr != nullptr) {
delete[] sample.sampleAddr;
}
}
Sample* AudioSample::GetPointer() {
return &sample;
}
size_t AudioSample::GetPointerSize() {
return sizeof(Sample);
}
size_t AudioSample::GetPointerSize() {
return sizeof(Sample);
}
} // namespace SOH

View file

@ -5,56 +5,56 @@
#include <libultraship/libultra/types.h>
namespace SOH {
typedef struct {
/* 0x00 */ u32 start;
/* 0x04 */ u32 end;
/* 0x08 */ u32 count;
/* 0x0C */ char unk_0C[0x4];
/* 0x10 */ s16 state[16]; // only exists if count != 0. 8-byte aligned
} AdpcmLoop; // size = 0x30 (or 0x10)
typedef struct {
/* 0x00 */ u32 start;
/* 0x04 */ u32 end;
/* 0x08 */ u32 count;
/* 0x0C */ char unk_0C[0x4];
/* 0x10 */ s16 state[16]; // only exists if count != 0. 8-byte aligned
} AdpcmLoop; // size = 0x30 (or 0x10)
typedef struct {
/* 0x00 */ s32 order;
/* 0x04 */ s32 npredictors;
/* 0x08 */ s16* book; // size 8 * order * npredictors. 8-byte aligned
} AdpcmBook; // s
typedef struct {
/* 0x00 */ s32 order;
/* 0x04 */ s32 npredictors;
/* 0x08 */ s16* book; // size 8 * order * npredictors. 8-byte aligned
} AdpcmBook; // s
typedef struct Sample {
union {
struct {
///* 0x0 */ u32 unk_0 : 1;
/* 0x0 */ u32 codec : 4; // The state of compression or decompression, See `SampleCodec`
/* 0x0 */ u32 medium : 2; // Medium where sample is currently stored. See `SampleMedium`
/* 0x0 */ u32 unk_bit26 : 1;
/* 0x0 */ u32 isRelocated : 1; // Has the sample header been relocated (offsets to pointers)
};
u32 asU32;
typedef struct Sample {
union {
struct {
///* 0x0 */ u32 unk_0 : 1;
/* 0x0 */ u32 codec : 4; // The state of compression or decompression, See `SampleCodec`
/* 0x0 */ u32 medium : 2; // Medium where sample is currently stored. See `SampleMedium`
/* 0x0 */ u32 unk_bit26 : 1;
/* 0x0 */ u32 isRelocated : 1; // Has the sample header been relocated (offsets to pointers)
};
/* 0x1 */ u32 size; // Size of the sample
u32 fileSize;
/* 0x4 */ u8* sampleAddr; // Raw sample data. Offset from the start of the sample bank or absolute address to either
// rom or ram
/* 0x8 */ AdpcmLoop*
loop; // Adpcm loop parameters used by the sample. Offset from the start of the sound font / pointer to ram
/* 0xC */ AdpcmBook*
book; // Adpcm book parameters used by the sample. Offset from the start of the sound font / pointer to ram
} Sample; // size = 0x10
class AudioSample : public Ship::Resource<Sample> {
public:
using Resource::Resource;
AudioSample() : Resource(std::shared_ptr<Ship::ResourceInitData>()) {
}
~AudioSample();
Sample* GetPointer();
size_t GetPointerSize();
Sample sample;
AdpcmLoop loop;
AdpcmBook book;
// Only applies to streamed audio
float tuning = -1.0f;
u32 asU32;
};
/* 0x1 */ u32 size; // Size of the sample
u32 fileSize;
/* 0x4 */ u8* sampleAddr; // Raw sample data. Offset from the start of the sample bank or absolute address to either
// rom or ram
/* 0x8 */ AdpcmLoop*
loop; // Adpcm loop parameters used by the sample. Offset from the start of the sound font / pointer to ram
/* 0xC */ AdpcmBook*
book; // Adpcm book parameters used by the sample. Offset from the start of the sound font / pointer to ram
} Sample; // size = 0x10
class AudioSample : public Ship::Resource<Sample> {
public:
using Resource::Resource;
AudioSample() : Resource(std::shared_ptr<Ship::ResourceInitData>()) {
}
~AudioSample();
Sample* GetPointer();
size_t GetPointerSize();
Sample sample;
AdpcmLoop loop;
AdpcmBook book;
// Only applies to streamed audio
float tuning = -1.0f;
};
}; // namespace SOH

View file

@ -2,17 +2,17 @@
namespace SOH {
Sequence* AudioSequence::GetPointer() {
return &sequence;
}
Sequence* AudioSequence::GetPointer() {
return &sequence;
}
size_t AudioSequence::GetPointerSize() {
return sizeof(Sequence);
}
size_t AudioSequence::GetPointerSize() {
return sizeof(Sequence);
}
AudioSequence::~AudioSequence() {
delete[] sequence.seqData;
sequence.seqData = nullptr;
}
AudioSequence::~AudioSequence() {
delete[] sequence.seqData;
sequence.seqData = nullptr;
}
} // namespace SOH

View file

@ -5,27 +5,27 @@
namespace SOH {
typedef struct {
char* seqData;
uint32_t seqDataSize;
uint16_t seqNumber;
uint8_t medium;
uint8_t cachePolicy;
uint32_t numFonts;
uint8_t fonts[16];
} Sequence;
typedef struct {
char* seqData;
uint32_t seqDataSize;
uint16_t seqNumber;
uint8_t medium;
uint8_t cachePolicy;
uint32_t numFonts;
uint8_t fonts[16];
} Sequence;
class AudioSequence : public Ship::Resource<Sequence> {
public:
using Resource::Resource;
class AudioSequence : public Ship::Resource<Sequence> {
public:
using Resource::Resource;
AudioSequence() : Resource(std::shared_ptr<Ship::ResourceInitData>()) {
}
~AudioSequence();
AudioSequence() : Resource(std::shared_ptr<Ship::ResourceInitData>()) {
}
~AudioSequence();
Sequence* GetPointer();
size_t GetPointerSize();
Sequence* GetPointer();
size_t GetPointerSize();
Sequence sequence;
};
Sequence sequence;
};
}; // namespace SOH

View file

@ -2,27 +2,27 @@
namespace SOH {
AudioSoundFont::~AudioSoundFont() {
for (auto i : instrumentAddresses) {
if (i != nullptr) {
delete[] i->envelope;
delete i;
}
}
for (auto d : drumAddresses) {
if (d != nullptr) {
delete[] d->envelope;
delete d;
}
AudioSoundFont::~AudioSoundFont() {
for (auto i : instrumentAddresses) {
if (i != nullptr) {
delete[] i->envelope;
delete i;
}
}
SoundFont* AudioSoundFont::GetPointer() {
return &soundFont;
for (auto d : drumAddresses) {
if (d != nullptr) {
delete[] d->envelope;
delete d;
}
}
}
size_t AudioSoundFont::GetPointerSize() {
return sizeof(SoundFont);
}
SoundFont* AudioSoundFont::GetPointer() {
return &soundFont;
}
size_t AudioSoundFont::GetPointerSize() {
return sizeof(SoundFont);
}
} // namespace SOH

View file

@ -8,74 +8,74 @@
namespace SOH {
typedef struct {
/* 0x0 */ s16 delay;
/* 0x2 */ s16 arg;
} AdsrEnvelope; // size = 0x4
typedef struct {
/* 0x0 */ s16 delay;
/* 0x2 */ s16 arg;
} AdsrEnvelope; // size = 0x4
typedef struct {
/* 0x00 */ Sample* sample;
/* 0x04 */ union {
u32 tuningAsU32;
f32 tuning; // frequency scale factor
};
} SoundFontSound; // size = 0x8
typedef struct {
/* 0x00 */ u8 loaded;
/* 0x01 */ u8 normalRangeLo;
/* 0x02 */ u8 normalRangeHi;
/* 0x03 */ u8 releaseRate;
/* 0x04 */ AdsrEnvelope* envelope;
/* 0x08 */ SoundFontSound lowNotesSound;
/* 0x10 */ SoundFontSound normalNotesSound;
/* 0x18 */ SoundFontSound highNotesSound;
} Instrument; // size = 0x20
typedef struct {
/* 0x00 */ u8 releaseRate;
/* 0x01 */ u8 pan;
/* 0x02 */ u8 loaded;
/* 0x04 */ SoundFontSound sound;
/* 0x14 */ AdsrEnvelope* envelope;
} Drum; // size = 0x14
typedef struct {
/* 0x00 */ u8 numInstruments;
/* 0x01 */ u8 numDrums;
/* 0x02 */ u8 sampleBankId1;
/* 0x03 */ u8 sampleBankId2;
/* 0x04 */ u16 numSfx;
/* 0x08 */ Instrument** instruments;
/* 0x0C */ Drum** drums;
/* 0x10 */ SoundFontSound* soundEffects;
s32 fntIndex;
} SoundFont; // size = 0x14
class AudioSoundFont : public Ship::Resource<SoundFont> {
public:
using Resource::Resource;
AudioSoundFont() : Resource(std::shared_ptr<Ship::ResourceInitData>()) {
}
~AudioSoundFont();
SoundFont* GetPointer();
size_t GetPointerSize();
int8_t medium;
int8_t cachePolicy;
uint16_t data1;
uint16_t data2;
uint16_t data3;
std::vector<Drum*> drumAddresses;
std::vector<std::vector<AdsrEnvelope>> drumEnvelopeArrays;
std::vector<Instrument*> instrumentAddresses;
std::vector<SoundFontSound> soundEffects;
SoundFont soundFont;
typedef struct {
/* 0x00 */ Sample* sample;
/* 0x04 */ union {
u32 tuningAsU32;
f32 tuning; // frequency scale factor
};
} SoundFontSound; // size = 0x8
typedef struct {
/* 0x00 */ u8 loaded;
/* 0x01 */ u8 normalRangeLo;
/* 0x02 */ u8 normalRangeHi;
/* 0x03 */ u8 releaseRate;
/* 0x04 */ AdsrEnvelope* envelope;
/* 0x08 */ SoundFontSound lowNotesSound;
/* 0x10 */ SoundFontSound normalNotesSound;
/* 0x18 */ SoundFontSound highNotesSound;
} Instrument; // size = 0x20
typedef struct {
/* 0x00 */ u8 releaseRate;
/* 0x01 */ u8 pan;
/* 0x02 */ u8 loaded;
/* 0x04 */ SoundFontSound sound;
/* 0x14 */ AdsrEnvelope* envelope;
} Drum; // size = 0x14
typedef struct {
/* 0x00 */ u8 numInstruments;
/* 0x01 */ u8 numDrums;
/* 0x02 */ u8 sampleBankId1;
/* 0x03 */ u8 sampleBankId2;
/* 0x04 */ u16 numSfx;
/* 0x08 */ Instrument** instruments;
/* 0x0C */ Drum** drums;
/* 0x10 */ SoundFontSound* soundEffects;
s32 fntIndex;
} SoundFont; // size = 0x14
class AudioSoundFont : public Ship::Resource<SoundFont> {
public:
using Resource::Resource;
AudioSoundFont() : Resource(std::shared_ptr<Ship::ResourceInitData>()) {
}
~AudioSoundFont();
SoundFont* GetPointer();
size_t GetPointerSize();
int8_t medium;
int8_t cachePolicy;
uint16_t data1;
uint16_t data2;
uint16_t data3;
std::vector<Drum*> drumAddresses;
std::vector<std::vector<AdsrEnvelope>> drumEnvelopeArrays;
std::vector<Instrument*> instrumentAddresses;
std::vector<SoundFontSound> soundEffects;
SoundFont soundFont;
};
}; // namespace SOH

View file

@ -892,7 +892,7 @@ AudioTable* AudioLoad_GetLoadTable(s32 tableType) {
}
void AudioLoad_RelocateFont(s32 fontId, SoundFontData* mem, RelocInfo* relocInfo) {
return;
return;
uintptr_t reloc;
uintptr_t reloc2;
Instrument* inst;
@ -1354,7 +1354,7 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
int customSeqListSize = 0;
char** seqList = ResourceMgr_ListFiles("audio/sequences*", &seqListSize);
char** customSeqList = ResourceMgr_ListFiles("custom/music/*", &customSeqListSize);
sequenceMapSize = (size_t)(seqListSize + customSeqListSize );
sequenceMapSize = (size_t)(seqListSize + customSeqListSize);
sequenceMap = malloc((sequenceMapSize + 0xF) * sizeof(char*));
gAudioContext.seqLoadStatus = malloc(sequenceMapSize);

View file

@ -853,27 +853,26 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
s5 = samplesLenAdjusted;
goto skip;
case CODEC_S16:
case CODEC_OPUS:
AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE,
(samplesLenAdjusted + 16) * 2);
flags = A_CONTINUE;
skipBytes = 0;
size_t bytesToRead;
nSamplesProcessed += samplesLenAdjusted;
case CODEC_OPUS:
AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, (samplesLenAdjusted + 16) * 2);
flags = A_CONTINUE;
skipBytes = 0;
size_t bytesToRead;
nSamplesProcessed += samplesLenAdjusted;
if (((synthState->samplePosInt * 2) + (samplesLenAdjusted)*2) < audioFontSample->size) {
bytesToRead = (samplesLenAdjusted)*2;
} else {
bytesToRead = audioFontSample->size - (synthState->samplePosInt * 2);
}
// 2S2H [Port] [Custom audio] Handle decoding OPUS data
if (audioFontSample->codec == CODEC_OPUS) {
aOPUSdecImpl(sampleAddr, DMEM_UNCOMPRESSED_NOTE, bytesToRead, &synthState->opusFile,
synthState->samplePosInt, audioFontSample->fileSize);
} else {
aLoadBuffer(cmd++, sampleAddr + (synthState->samplePosInt * 2), DMEM_UNCOMPRESSED_NOTE,
bytesToRead);
}
if (((synthState->samplePosInt * 2) + (samplesLenAdjusted)*2) < audioFontSample->size) {
bytesToRead = (samplesLenAdjusted)*2;
} else {
bytesToRead = audioFontSample->size - (synthState->samplePosInt * 2);
}
// 2S2H [Port] [Custom audio] Handle decoding OPUS data
if (audioFontSample->codec == CODEC_OPUS) {
aOPUSdecImpl(sampleAddr, DMEM_UNCOMPRESSED_NOTE, bytesToRead, &synthState->opusFile,
synthState->samplePosInt, audioFontSample->fileSize);
} else {
aLoadBuffer(cmd++, sampleAddr + (synthState->samplePosInt * 2), DMEM_UNCOMPRESSED_NOTE,
bytesToRead);
}
goto skip;
case CODEC_REVERB: