2016-05-03 01:16:26 +00:00
|
|
|
#include "amuse/AudioGroupSampleDirectory.hpp"
|
|
|
|
#include "amuse/Common.hpp"
|
2016-05-29 04:31:58 +00:00
|
|
|
#include <string.h>
|
2016-05-03 01:16:26 +00:00
|
|
|
|
|
|
|
namespace amuse
|
|
|
|
{
|
|
|
|
|
|
|
|
void AudioGroupSampleDirectory::Entry::swapBig()
|
|
|
|
{
|
2016-05-14 22:38:37 +00:00
|
|
|
m_sfxId = SBig(m_sfxId);
|
2016-05-03 01:16:26 +00:00
|
|
|
m_sampleOff = SBig(m_sampleOff);
|
|
|
|
m_unk = SBig(m_unk);
|
|
|
|
m_sampleRate = SBig(m_sampleRate);
|
|
|
|
m_numSamples = SBig(m_numSamples);
|
|
|
|
m_loopStartSample = SBig(m_loopStartSample);
|
|
|
|
m_loopLengthSamples = SBig(m_loopLengthSamples);
|
|
|
|
m_adpcmParmOffset = SBig(m_adpcmParmOffset);
|
|
|
|
}
|
|
|
|
|
2016-05-29 04:31:58 +00:00
|
|
|
void AudioGroupSampleDirectory::ADPCMParms::swapBigDSP()
|
2016-05-03 01:16:26 +00:00
|
|
|
{
|
2016-05-29 04:31:58 +00:00
|
|
|
dsp.m_bytesPerFrame = SBig(dsp.m_bytesPerFrame);
|
|
|
|
dsp.m_hist2 = SBig(dsp.m_hist2);
|
|
|
|
dsp.m_hist1 = SBig(dsp.m_hist1);
|
2016-05-11 04:48:08 +00:00
|
|
|
for (int i=0 ; i<8 ; ++i)
|
|
|
|
{
|
2016-05-29 04:31:58 +00:00
|
|
|
dsp.m_coefs[i][0] = SBig(dsp.m_coefs[i][0]);
|
|
|
|
dsp.m_coefs[i][1] = SBig(dsp.m_coefs[i][1]);
|
2016-05-11 04:48:08 +00:00
|
|
|
}
|
2016-05-03 01:16:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-29 04:31:58 +00:00
|
|
|
void AudioGroupSampleDirectory::ADPCMParms::swapBigVADPCM()
|
|
|
|
{
|
|
|
|
int16_t* allCoefs = reinterpret_cast<int16_t*>(vadpcm.m_coefs[0][0]);
|
|
|
|
for (int i=0 ; i<128 ; ++i)
|
|
|
|
allCoefs[i] = SBig(allCoefs[i]);
|
|
|
|
}
|
|
|
|
|
2016-05-28 02:28:59 +00:00
|
|
|
AudioGroupSampleDirectory::AudioGroupSampleDirectory(const unsigned char* data, GCNDataTag)
|
2016-05-09 07:22:58 +00:00
|
|
|
{
|
2016-05-14 04:46:39 +00:00
|
|
|
const unsigned char* cur = data;
|
|
|
|
while (*reinterpret_cast<const uint32_t*>(cur) != 0xffffffff)
|
|
|
|
{
|
|
|
|
const AudioGroupSampleDirectory::Entry* ent =
|
|
|
|
reinterpret_cast<const AudioGroupSampleDirectory::Entry*>(cur);
|
|
|
|
|
2016-05-14 22:38:37 +00:00
|
|
|
std::pair<Entry, ADPCMParms>& store = m_entries[SBig(ent->m_sfxId)];
|
2016-05-14 04:46:39 +00:00
|
|
|
store.first = *ent;
|
|
|
|
store.first.swapBig();
|
|
|
|
|
|
|
|
if (store.first.m_adpcmParmOffset)
|
|
|
|
{
|
|
|
|
const AudioGroupSampleDirectory::ADPCMParms* adpcm =
|
|
|
|
reinterpret_cast<const AudioGroupSampleDirectory::ADPCMParms*>(data +
|
|
|
|
store.first.m_adpcmParmOffset);
|
|
|
|
store.second = *adpcm;
|
2016-05-29 04:31:58 +00:00
|
|
|
store.second.swapBigDSP();
|
2016-05-14 04:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cur += 32;
|
|
|
|
}
|
2016-05-09 07:22:58 +00:00
|
|
|
}
|
|
|
|
|
2016-05-28 02:28:59 +00:00
|
|
|
struct MusyX1SdirEntry
|
|
|
|
{
|
|
|
|
uint16_t m_sfxId;
|
|
|
|
uint32_t m_sampleOff;
|
|
|
|
uint32_t m_pitchSampleRate;
|
|
|
|
uint32_t m_numSamples;
|
|
|
|
uint32_t m_loopStartSample;
|
|
|
|
uint32_t m_loopLengthSamples;
|
|
|
|
|
|
|
|
void swapBig()
|
|
|
|
{
|
|
|
|
m_sfxId = SBig(m_sfxId);
|
|
|
|
m_sampleOff = SBig(m_sampleOff);
|
|
|
|
m_pitchSampleRate = SBig(m_pitchSampleRate);
|
|
|
|
m_numSamples = SBig(m_numSamples);
|
|
|
|
m_loopStartSample = SBig(m_loopStartSample);
|
|
|
|
m_loopLengthSamples = SBig(m_loopLengthSamples);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIntoMusyX2(AudioGroupSampleDirectory::Entry& ent) const
|
|
|
|
{
|
|
|
|
ent.m_sfxId = m_sfxId;
|
|
|
|
ent.m_sampleOff = m_sampleOff;
|
|
|
|
ent.m_unk = 0;
|
|
|
|
ent.m_pitch = m_pitchSampleRate >> 24;
|
|
|
|
ent.m_sampleRate = m_pitchSampleRate & 0xffff;
|
|
|
|
ent.m_numSamples = m_numSamples;
|
|
|
|
ent.m_loopStartSample = m_loopStartSample;
|
|
|
|
ent.m_loopLengthSamples = m_loopLengthSamples;
|
|
|
|
ent.m_adpcmParmOffset = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-29 18:22:20 +00:00
|
|
|
struct MusyX1AbsSdirEntry
|
|
|
|
{
|
|
|
|
uint16_t m_sfxId;
|
|
|
|
uint32_t m_sampleOff;
|
|
|
|
uint32_t m_unk;
|
|
|
|
uint32_t m_pitchSampleRate;
|
|
|
|
uint32_t m_numSamples;
|
|
|
|
uint32_t m_loopStartSample;
|
|
|
|
uint32_t m_loopLengthSamples;
|
|
|
|
|
|
|
|
void swapBig()
|
|
|
|
{
|
|
|
|
m_sfxId = SBig(m_sfxId);
|
|
|
|
m_sampleOff = SBig(m_sampleOff);
|
|
|
|
m_unk = SBig(m_unk);
|
|
|
|
m_pitchSampleRate = SBig(m_pitchSampleRate);
|
|
|
|
m_numSamples = SBig(m_numSamples);
|
|
|
|
m_loopStartSample = SBig(m_loopStartSample);
|
|
|
|
m_loopLengthSamples = SBig(m_loopLengthSamples);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIntoMusyX2(AudioGroupSampleDirectory::Entry& ent) const
|
|
|
|
{
|
|
|
|
ent.m_sfxId = m_sfxId;
|
|
|
|
ent.m_sampleOff = m_sampleOff;
|
|
|
|
ent.m_unk = m_unk;
|
|
|
|
ent.m_pitch = m_pitchSampleRate >> 24;
|
|
|
|
ent.m_sampleRate = m_pitchSampleRate & 0xffff;
|
|
|
|
ent.m_numSamples = m_numSamples;
|
|
|
|
ent.m_loopStartSample = m_loopStartSample;
|
|
|
|
ent.m_loopLengthSamples = m_loopLengthSamples;
|
|
|
|
ent.m_adpcmParmOffset = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-29 04:31:58 +00:00
|
|
|
AudioGroupSampleDirectory::AudioGroupSampleDirectory(const unsigned char* data,
|
2016-05-29 18:22:20 +00:00
|
|
|
const unsigned char* sampData,
|
|
|
|
bool absOffs, N64DataTag)
|
2016-05-28 02:28:59 +00:00
|
|
|
{
|
|
|
|
const unsigned char* cur = data;
|
2016-05-29 18:22:20 +00:00
|
|
|
|
|
|
|
if (absOffs)
|
|
|
|
{
|
|
|
|
while (*reinterpret_cast<const uint32_t*>(cur) != 0xffffffff)
|
|
|
|
{
|
|
|
|
MusyX1AbsSdirEntry ent = *reinterpret_cast<const MusyX1AbsSdirEntry*>(cur);
|
|
|
|
ent.swapBig();
|
|
|
|
|
|
|
|
std::pair<Entry, ADPCMParms>& store = m_entries[ent.m_sfxId];
|
|
|
|
ent.setIntoMusyX2(store.first);
|
|
|
|
|
|
|
|
memcpy(&store.second.vadpcm.m_coefs, sampData + ent.m_sampleOff, 256);
|
|
|
|
store.second.swapBigVADPCM();
|
|
|
|
|
|
|
|
cur += 28;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-05-28 02:28:59 +00:00
|
|
|
{
|
2016-05-29 18:22:20 +00:00
|
|
|
while (*reinterpret_cast<const uint32_t*>(cur) != 0xffffffff)
|
|
|
|
{
|
|
|
|
MusyX1SdirEntry ent = *reinterpret_cast<const MusyX1SdirEntry*>(cur);
|
|
|
|
ent.swapBig();
|
2016-05-28 02:28:59 +00:00
|
|
|
|
2016-05-29 18:22:20 +00:00
|
|
|
std::pair<Entry, ADPCMParms>& store = m_entries[ent.m_sfxId];
|
|
|
|
ent.setIntoMusyX2(store.first);
|
2016-05-28 02:28:59 +00:00
|
|
|
|
2016-05-29 18:22:20 +00:00
|
|
|
memcpy(&store.second.vadpcm.m_coefs, sampData + ent.m_sampleOff, 256);
|
|
|
|
store.second.swapBigVADPCM();
|
2016-05-29 04:31:58 +00:00
|
|
|
|
2016-05-29 18:22:20 +00:00
|
|
|
cur += 24;
|
|
|
|
}
|
2016-05-28 02:28:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-29 18:22:20 +00:00
|
|
|
AudioGroupSampleDirectory::AudioGroupSampleDirectory(const unsigned char* data,
|
|
|
|
bool absOffs, PCDataTag)
|
2016-05-28 02:28:59 +00:00
|
|
|
{
|
|
|
|
const unsigned char* cur = data;
|
2016-05-29 18:22:20 +00:00
|
|
|
|
|
|
|
if (absOffs)
|
2016-05-28 02:28:59 +00:00
|
|
|
{
|
2016-05-29 18:22:20 +00:00
|
|
|
while (*reinterpret_cast<const uint32_t*>(cur) != 0xffffffff)
|
|
|
|
{
|
|
|
|
const MusyX1AbsSdirEntry* ent = reinterpret_cast<const MusyX1AbsSdirEntry*>(cur);
|
2016-05-28 02:28:59 +00:00
|
|
|
|
2016-05-29 18:22:20 +00:00
|
|
|
std::pair<Entry, ADPCMParms>& store = m_entries[ent->m_sfxId];
|
|
|
|
ent->setIntoMusyX2(store.first);
|
2016-05-28 02:28:59 +00:00
|
|
|
|
2016-05-29 18:22:20 +00:00
|
|
|
cur += 28;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (*reinterpret_cast<const uint32_t*>(cur) != 0xffffffff)
|
|
|
|
{
|
|
|
|
const MusyX1SdirEntry* ent = reinterpret_cast<const MusyX1SdirEntry*>(cur);
|
|
|
|
|
|
|
|
std::pair<Entry, ADPCMParms>& store = m_entries[ent->m_sfxId];
|
|
|
|
ent->setIntoMusyX2(store.first);
|
|
|
|
|
|
|
|
cur += 24;
|
|
|
|
}
|
2016-05-28 02:28:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 01:16:26 +00:00
|
|
|
}
|