2022-06-01 13:06:32 -04:00
|
|
|
#include "Audio.h"
|
|
|
|
|
|
|
|
namespace Ship
|
|
|
|
{
|
2022-06-15 12:22:21 -04:00
|
|
|
void AudioSequenceV2::ParseFileBinary(BinaryReader* reader, Resource* res)
|
|
|
|
{
|
|
|
|
AudioSequence* seq = (AudioSequence*)res;
|
|
|
|
|
|
|
|
ResourceFile::ParseFileBinary(reader, res);
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
uint32_t seqDataSize = reader->ReadInt32();
|
2022-06-15 12:22:21 -04:00
|
|
|
|
|
|
|
seq->seqData.reserve(seqDataSize);
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
for (uint32_t i = 0; i < seqDataSize; i++)
|
2022-06-15 12:22:21 -04:00
|
|
|
seq->seqData.push_back(reader->ReadUByte());
|
|
|
|
|
|
|
|
seq->seqNumber = reader->ReadUByte();
|
|
|
|
seq->medium = reader->ReadUByte();
|
|
|
|
seq->cachePolicy = reader->ReadUByte();
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
uint32_t numFonts = reader->ReadInt32();
|
2022-06-15 12:22:21 -04:00
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
for (uint32_t i = 0; i < numFonts; i++)
|
2022-06-15 12:22:21 -04:00
|
|
|
seq->fonts.push_back(reader->ReadUByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioSampleV2::ParseFileBinary(BinaryReader* reader, Resource* res)
|
2022-06-01 13:06:32 -04:00
|
|
|
{
|
|
|
|
AudioSample* entry = (AudioSample*)res;
|
|
|
|
|
|
|
|
ResourceFile::ParseFileBinary(reader, res);
|
|
|
|
|
|
|
|
entry->codec = reader->ReadByte();
|
|
|
|
entry->medium = reader->ReadByte();
|
|
|
|
entry->unk_bit26 = reader->ReadByte();
|
|
|
|
entry->unk_bit25 = reader->ReadByte();
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
uint32_t dataSize = reader->ReadInt32();
|
2022-06-15 10:42:37 -04:00
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
for (uint32_t i = 0; i < dataSize; i++)
|
2022-06-01 13:06:32 -04:00
|
|
|
entry->data.push_back(reader->ReadUByte());
|
|
|
|
|
|
|
|
entry->loop.start = reader->ReadUInt32();
|
|
|
|
entry->loop.end = reader->ReadUInt32();
|
|
|
|
entry->loop.count = reader->ReadUInt32();
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
uint32_t loopStateCnt = reader->ReadUInt32();
|
2022-06-01 13:06:32 -04:00
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
for (uint32_t i = 0; i < loopStateCnt; i++)
|
2022-06-01 13:06:32 -04:00
|
|
|
entry->loop.states.push_back(reader->ReadInt16());
|
|
|
|
|
|
|
|
entry->book.order = reader->ReadInt32();
|
|
|
|
entry->book.npredictors = reader->ReadInt32();
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
uint32_t bookSize = reader->ReadInt32();
|
2022-06-01 13:06:32 -04:00
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
for (uint32_t i = 0; i < bookSize; i++)
|
2022-06-01 13:06:32 -04:00
|
|
|
entry->book.books.push_back(reader->ReadInt16());
|
|
|
|
}
|
|
|
|
|
2022-06-15 12:22:21 -04:00
|
|
|
void AudioSoundFontV2::ParseFileBinary(BinaryReader* reader, Resource* res)
|
2022-06-01 13:06:32 -04:00
|
|
|
{
|
|
|
|
AudioSoundFont* soundFont = (AudioSoundFont*)res;
|
|
|
|
|
|
|
|
ResourceFile::ParseFileBinary(reader, res);
|
|
|
|
|
2022-06-10 13:37:50 -04:00
|
|
|
soundFont->id = reader->ReadInt32();
|
2022-06-01 13:06:32 -04:00
|
|
|
soundFont->medium = reader->ReadByte();
|
|
|
|
soundFont->cachePolicy = reader->ReadByte();
|
|
|
|
soundFont->data1 = reader->ReadInt16();
|
|
|
|
soundFont->data2 = reader->ReadInt16();
|
|
|
|
soundFont->data3 = reader->ReadInt16();
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
uint32_t drumCnt = reader->ReadInt32();
|
|
|
|
uint32_t instrumentCnt = reader->ReadInt32();
|
|
|
|
uint32_t sfxCnt = reader->ReadInt32();
|
2022-06-01 13:06:32 -04:00
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
for (uint32_t i = 0; i < drumCnt; i++)
|
2022-06-01 13:06:32 -04:00
|
|
|
{
|
|
|
|
DrumEntry drum;
|
|
|
|
drum.releaseRate = reader->ReadUByte();
|
|
|
|
drum.pan = reader->ReadUByte();
|
|
|
|
drum.loaded = reader->ReadUByte();
|
|
|
|
|
|
|
|
drum.env = ReadEnvelopeData(reader);
|
2022-06-15 10:42:37 -04:00
|
|
|
|
2022-06-01 13:06:32 -04:00
|
|
|
bool hasSample = reader->ReadByte();
|
2022-06-10 13:37:50 -04:00
|
|
|
drum.sampleFileName = reader->ReadString();
|
2022-06-01 13:06:32 -04:00
|
|
|
drum.tuning = reader->ReadSingle();
|
|
|
|
|
|
|
|
soundFont->drums.push_back(drum);
|
|
|
|
}
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
for (uint32_t i = 0; i < instrumentCnt; i++)
|
2022-06-01 13:06:32 -04:00
|
|
|
{
|
|
|
|
InstrumentEntry entry;
|
|
|
|
|
2022-06-13 21:54:25 -04:00
|
|
|
entry.isValidEntry = reader->ReadUByte();
|
|
|
|
entry.loaded = reader->ReadUByte();
|
|
|
|
entry.normalRangeLo = reader->ReadUByte();
|
|
|
|
entry.normalRangeHi = reader->ReadUByte();
|
|
|
|
entry.releaseRate = reader->ReadUByte();
|
2022-06-01 13:06:32 -04:00
|
|
|
|
|
|
|
entry.env = ReadEnvelopeData(reader);
|
2022-06-15 10:42:37 -04:00
|
|
|
|
2022-06-01 13:06:32 -04:00
|
|
|
{
|
|
|
|
bool hasSFEntry = reader->ReadByte();
|
|
|
|
|
|
|
|
if (hasSFEntry)
|
|
|
|
{
|
|
|
|
entry.lowNotesSound = new SoundFontEntry();
|
|
|
|
bool hasSampleRef = reader->ReadByte();
|
2022-06-10 13:37:50 -04:00
|
|
|
entry.lowNotesSound->sampleFileName = reader->ReadString();
|
2022-06-01 13:06:32 -04:00
|
|
|
entry.lowNotesSound->tuning = reader->ReadSingle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
bool hasSFEntry = reader->ReadByte();
|
|
|
|
|
|
|
|
if (hasSFEntry)
|
|
|
|
{
|
|
|
|
entry.normalNotesSound = new SoundFontEntry();
|
|
|
|
bool hasSampleRef = reader->ReadByte();
|
2022-06-10 13:37:50 -04:00
|
|
|
entry.normalNotesSound->sampleFileName = reader->ReadString();
|
2022-06-01 13:06:32 -04:00
|
|
|
entry.normalNotesSound->tuning = reader->ReadSingle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
bool hasSFEntry = reader->ReadByte();
|
|
|
|
|
|
|
|
if (hasSFEntry)
|
|
|
|
{
|
|
|
|
entry.highNotesSound = new SoundFontEntry();
|
|
|
|
bool hasSampleRef = reader->ReadByte();
|
2022-06-10 13:37:50 -04:00
|
|
|
entry.highNotesSound->sampleFileName = reader->ReadString();
|
2022-06-01 13:06:32 -04:00
|
|
|
entry.highNotesSound->tuning = reader->ReadSingle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
soundFont->instruments.push_back(entry);
|
|
|
|
}
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
for (uint32_t i = 0; i < sfxCnt; i++)
|
2022-06-01 13:06:32 -04:00
|
|
|
{
|
|
|
|
SoundFontEntry* entry = new SoundFontEntry();
|
|
|
|
|
|
|
|
bool hasSFEntry = reader->ReadByte();
|
|
|
|
|
|
|
|
if (hasSFEntry)
|
|
|
|
{
|
|
|
|
bool hasSampleRef = reader->ReadByte();
|
2022-06-10 13:37:50 -04:00
|
|
|
entry->sampleFileName = reader->ReadString();
|
2022-06-01 13:06:32 -04:00
|
|
|
entry->tuning = reader->ReadSingle();
|
|
|
|
}
|
|
|
|
|
|
|
|
soundFont->soundEffects.push_back(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-15 12:22:21 -04:00
|
|
|
std::vector<AdsrEnvelope*> AudioSoundFontV2::ReadEnvelopeData(BinaryReader* reader)
|
2022-06-01 13:06:32 -04:00
|
|
|
{
|
|
|
|
std::vector<AdsrEnvelope*> envelopes;
|
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
uint32_t envelopeCnt = reader->ReadInt32();
|
2022-06-01 13:06:32 -04:00
|
|
|
|
2022-06-22 14:59:21 -04:00
|
|
|
for (uint32_t i = 0; i < envelopeCnt; i++)
|
2022-06-01 13:06:32 -04:00
|
|
|
{
|
|
|
|
AdsrEnvelope* env = new AdsrEnvelope();
|
|
|
|
env->delay = reader->ReadInt16();
|
|
|
|
env->arg = reader->ReadInt16();
|
|
|
|
|
|
|
|
envelopes.push_back(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
return envelopes;
|
|
|
|
}
|
|
|
|
|
2022-06-15 12:22:21 -04:00
|
|
|
void AudioV2::ParseFileBinary(BinaryReader* reader, Resource* res)
|
2022-06-01 13:06:32 -04:00
|
|
|
{
|
|
|
|
Audio* audio = (Audio*)res;
|
|
|
|
|
|
|
|
ResourceFile::ParseFileBinary(reader, res);
|
|
|
|
}
|
2022-06-02 13:42:18 -04:00
|
|
|
}
|