Audio support nearly complete.

This commit is contained in:
Nicholas Estelami
2022-06-10 13:37:50 -04:00
parent 746c7a5303
commit 114c6e01d9
25 changed files with 1953 additions and 209 deletions

View File

@@ -15,7 +15,7 @@ namespace Ship
int dataSize = reader->ReadInt32();
for (size_t i = 0; i < dataSize; i++)
for (uint32_t i = 0; i < dataSize; i++)
entry->data.push_back(reader->ReadUByte());
entry->loop.start = reader->ReadUInt32();
@@ -24,7 +24,7 @@ namespace Ship
int loopStateCnt = reader->ReadUInt32();
for (size_t i = 0; i < loopStateCnt; i++)
for (uint32_t i = 0; i < loopStateCnt; i++)
entry->loop.states.push_back(reader->ReadInt16());
entry->book.order = reader->ReadInt32();
@@ -32,7 +32,7 @@ namespace Ship
int bookSize = reader->ReadInt32();
for (size_t i = 0; i < bookSize; i++)
for (uint32_t i = 0; i < bookSize; i++)
entry->book.books.push_back(reader->ReadInt16());
}
@@ -42,6 +42,7 @@ namespace Ship
ResourceFile::ParseFileBinary(reader, res);
soundFont->id = reader->ReadInt32();
soundFont->medium = reader->ReadByte();
soundFont->cachePolicy = reader->ReadByte();
soundFont->data1 = reader->ReadInt16();
@@ -62,7 +63,7 @@ namespace Ship
drum.env = ReadEnvelopeData(reader);
bool hasSample = reader->ReadByte();
drum.offset = reader->ReadInt32();
drum.sampleFileName = reader->ReadString();
drum.tuning = reader->ReadSingle();
soundFont->drums.push_back(drum);
@@ -87,7 +88,7 @@ namespace Ship
{
entry.lowNotesSound = new SoundFontEntry();
bool hasSampleRef = reader->ReadByte();
entry.lowNotesSound->sampleOffset = reader->ReadInt32();
entry.lowNotesSound->sampleFileName = reader->ReadString();
entry.lowNotesSound->tuning = reader->ReadSingle();
}
}
@@ -99,7 +100,7 @@ namespace Ship
{
entry.normalNotesSound = new SoundFontEntry();
bool hasSampleRef = reader->ReadByte();
entry.normalNotesSound->sampleOffset = reader->ReadInt32();
entry.normalNotesSound->sampleFileName = reader->ReadString();
entry.normalNotesSound->tuning = reader->ReadSingle();
}
}
@@ -111,7 +112,7 @@ namespace Ship
{
entry.highNotesSound = new SoundFontEntry();
bool hasSampleRef = reader->ReadByte();
entry.highNotesSound->sampleOffset = reader->ReadInt32();
entry.highNotesSound->sampleFileName = reader->ReadString();
entry.highNotesSound->tuning = reader->ReadSingle();
}
}
@@ -128,7 +129,7 @@ namespace Ship
if (hasSFEntry)
{
bool hasSampleRef = reader->ReadByte();
entry->sampleOffset = reader->ReadInt32();
entry->sampleFileName = reader->ReadString();
entry->tuning = reader->ReadSingle();
}
@@ -159,10 +160,5 @@ namespace Ship
Audio* audio = (Audio*)res;
ResourceFile::ParseFileBinary(reader, res);
//int sampleCnt = reader->ReadInt32();
//for (size_t i = 0; i < sampleCnt; i++)
//audio->samples.push_back(ReadSampleEntry(reader));
}
}

View File

@@ -3,6 +3,7 @@
#include "Resource.h"
#include <vector>
#include <map>
#include <string>
namespace Ship
{
@@ -24,14 +25,12 @@ namespace Ship
/* 0x00 */ uint32_t start;
/* 0x04 */ uint32_t end;
/* 0x08 */ uint32_t count;
///* 0x10 */ int16_t state[16]; // only exists if count != 0. 8-byte aligned
/* 0x10 */ std::vector<int16_t> states;
};
struct SoundFontEntry
{
//SampleEntry* sampleEntry = nullptr;
uint32_t sampleOffset;
std::string sampleFileName;
float tuning;
};
@@ -40,10 +39,9 @@ namespace Ship
uint8_t releaseRate;
uint8_t pan;
uint8_t loaded;
uint32_t offset;
std::string sampleFileName;
float tuning;
std::vector<AdsrEnvelope*> env;
//SampleEntry* sample = nullptr;
};
struct InstrumentEntry
@@ -83,6 +81,7 @@ namespace Ship
public:
uint32_t ptr;
uint32_t size;
uint32_t id;
uint8_t medium;
uint8_t cachePolicy;
uint16_t data1;
@@ -97,6 +96,7 @@ namespace Ship
class AudioSample : public Resource
{
public:
uint32_t originalOffset;
uint8_t codec;
uint8_t medium;
uint8_t unk_bit26;
@@ -115,6 +115,5 @@ namespace Ship
//std::vector<AudioTableEntry> sampleBankTable;
//std::vector<char*> sequences;
//std::vector<SampleEntry*> samples;
};
}

View File

@@ -12,10 +12,10 @@ namespace Ship
{
enum class ResourceType
{
Archive = 0x4F415243, // OARC
Model = 0x4F4D444C, // OMDL
Archive = 0x4F415243, // OARC (UNUSED)
Model = 0x4F4D444C, // OMDL (WIP)
Texture = 0x4F544558, // OTEX
Material = 0x4F4D4154, // OMAT
Material = 0x4F4D4154, // OMAT (WIP)
Animation = 0x4F414E4D, // OANM
PlayerAnimation = 0x4F50414D, // OPAM
DisplayList = 0x4F444C54, // ODLT

View File

@@ -339,6 +339,18 @@ namespace Ship {
return LoadedList;
}
std::shared_ptr<std::vector<std::string>> ResourceMgr::ListFiles(std::string SearchMask)
{
auto result = std::make_shared<std::vector<std::string>>();
auto fileList = OTR->ListFiles(SearchMask);
for (DWORD i = 0; i < fileList.size(); i++) {
result->push_back(fileList[i].cFileName);
}
return result;
}
void ResourceMgr::InvalidateResourceCache() {
ResourceCache.clear();
}

View File

@@ -41,6 +41,7 @@ namespace Ship
std::shared_ptr<std::vector<std::shared_ptr<Resource>>> CacheDirectory(const std::string& SearchMask);
std::shared_ptr<std::vector<std::shared_ptr<ResourcePromise>>> CacheDirectoryAsync(const std::string& SearchMask);
std::shared_ptr<std::vector<std::shared_ptr<Resource>>> DirtyDirectory(std::string SearchMask);
std::shared_ptr<std::vector<std::string>> ListFiles(std::string SearchMask);
protected:
void Start();

View File

@@ -30,8 +30,8 @@ namespace Ship {
WAVEFORMATEX desired;
desired.wFormatTag = WAVE_FORMAT_PCM;
desired.nChannels = 2;
desired.nSamplesPerSec = 32000;
desired.nAvgBytesPerSec = 32000 * 2 * 2;
desired.nSamplesPerSec = 44000; // OTRTODO
desired.nAvgBytesPerSec = 44000 * 2 * 2; // OTRTODO
desired.nBlockAlign = 4;
desired.wBitsPerSample = 16;
desired.cbSize = 0;