Skip to content

Commit

Permalink
SOUND: Load XACT SoundBank crossfade parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Jan 5, 2019
1 parent dcf421f commit c83d33d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
20 changes: 20 additions & 0 deletions src/sound/xactsoundbank.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ class XACTSoundBank {
kMode3DDisabled = 2
};

enum CrossfadeType {
kCrossfadeDisabled = 0,
kCrossfadeLinear = 1,
kCrossfadeLogarithmic = 2
};

struct Parameters3D {
Mode3D mode;

Expand Down Expand Up @@ -409,6 +415,17 @@ class XACTSoundBank {

typedef std::vector<Transition> Transitions;

struct ParametersCrossfade {
CrossfadeType type;

uint32 duration; ///< Fade duration in milliseconds.
uint8 stepCount; ///< Number of steps during the fade.

float volume; ///< Initial (fade-in) or final (fade-out) attenuation in dB (-64.0f to 0.0f).

ParametersCrossfade() : type(kCrossfadeDisabled), duration(0), stepCount(0), volume(0.0f) { }
};

struct Cue {
Common::UString name; ///< Name of the cue. Can be empty.

Expand All @@ -417,6 +434,9 @@ class XACTSoundBank {
bool stopOnStarve; ///< Stop playback on starvation?
bool interactive; ///< Is this an interactive cue?

ParametersCrossfade fadeIn; ///< Parameters for a crossfade-in.
ParametersCrossfade fadeOut; ///< Parameters for a crossfade-out.

/** How a cue variation to be played is selected. */
SelectMethod variationSelectMethod;

Expand Down
29 changes: 23 additions & 6 deletions src/sound/xactsoundbank_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace Sound {
static const size_t k3DDefinitionSize = 40;
static const size_t kCueDefinitionSize = 20;
static const size_t kSoundDefinitionSize = 20;
static const size_t kFadeDefinitionSize = 16;

enum XSBFlags {
kXSBNoCueNames = 1
Expand Down Expand Up @@ -171,7 +172,7 @@ void XACTSoundBank_Binary::readWaveBanks(Common::SeekableReadStream &xsb, uint32
}

void XACTSoundBank_Binary::readCues(Common::SeekableReadStream &xsb, uint32 xsbFlags,
uint32 offset, uint32 count) {
uint32 offset, uint32 count, uint32 offsetFadeParams) {

_cues.resize(count);
for (size_t i = 0; i < count; ++i) {
Expand All @@ -189,7 +190,9 @@ void XACTSoundBank_Binary::readCues(Common::SeekableReadStream &xsb, uint32 xsbF
const uint32 offsetName = xsb.readUint32LE();
const uint32 offsetEntry = xsb.readUint32LE();

xsb.skip(4); // Unknown
const uint16 fadeParamIndex = xsb.readUint16LE();

xsb.skip(2); // Unknown
xsb.skip(4); // Unknown. Some kind of offset? Can be 0x07FFFFFF.

if (!(xsbFlags & kXSBNoCueNames) && (offsetName != 0xFFFFFFFF)) {
Expand All @@ -199,6 +202,20 @@ void XACTSoundBank_Binary::readCues(Common::SeekableReadStream &xsb, uint32 xsbF
_cueMap[cue.name] = &cue;
}

if (cue.crossfade) {
xsb.seek(offsetFadeParams + fadeParamIndex * kFadeDefinitionSize);

cue.fadeIn.duration = xsb.readUint32LE() / 10000;
cue.fadeIn.volume = CLIP(xsb.readSint16LE() / 100.0f, -64.0f, 0.0f);
cue.fadeIn.type = static_cast<CrossfadeType>(xsb.readByte() >> 4);
cue.fadeIn.stepCount = xsb.readByte();

cue.fadeOut.duration = xsb.readUint32LE() / 10000;
cue.fadeOut.volume = CLIP(xsb.readSint16LE() / 100.0f, -64.0f, 0.0f);
cue.fadeOut.type = static_cast<CrossfadeType>(xsb.readByte() >> 4);
cue.fadeOut.stepCount = xsb.readByte();
}

if (offsetEntry != 0xFFFFFFFF) {
readCueVarations(xsb, cue, offsetEntry);

Expand Down Expand Up @@ -630,9 +647,9 @@ void XACTSoundBank_Binary::load(Common::SeekableReadStream &xsb) {

xsb.skip(2); // CRC. We're ignoring it (for now?)

const uint32 offsetWaveBanks = xsb.readUint32LE();
xsb.skip(4); // Some offset
const uint32 offset3DParams = xsb.readUint32LE();
const uint32 offsetWaveBanks = xsb.readUint32LE();
const uint32 offsetFadeParams = xsb.readUint32LE();
const uint32 offset3DParams = xsb.readUint32LE();
xsb.skip(4); // Some offset

const uint16 xsbFlags = xsb.readUint16LE();
Expand All @@ -652,7 +669,7 @@ void XACTSoundBank_Binary::load(Common::SeekableReadStream &xsb) {


readWaveBanks(xsb, offsetWaveBanks, bankCount);
readCues(xsb, xsbFlags, offsetCues, cueCount);
readCues(xsb, xsbFlags, offsetCues, cueCount, offsetFadeParams);
readSounds(xsb, offsetSounds, soundCount, offset3DParams);
}

Expand Down
3 changes: 2 additions & 1 deletion src/sound/xactsoundbank_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class XACTSoundBank_Binary : public XACTSoundBank {
uint32 count, uint8 flags);

void readWaveBanks(Common::SeekableReadStream &xsb, uint32 offset, uint32 count);
void readCues(Common::SeekableReadStream &xsb, uint32 xsbFlags, uint32 offset, uint32 count);
void readCues(Common::SeekableReadStream &xsb, uint32 xsbFlags, uint32 offset, uint32 count,
uint32 offsetFadeParams);
void readSounds(Common::SeekableReadStream &xsb, uint32 offset, uint32 count, uint32 offset3DParams);
};

Expand Down

0 comments on commit c83d33d

Please sign in to comment.