Skip to content

Commit

Permalink
SOUND: Load XACT SoundBank play event loop parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Jan 5, 2019
1 parent 9030515 commit a776e87
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/sound/xactsoundbank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ ChannelHandle XACTSoundBank::playSound(Sound &sound, SoundType soundType) {
return playTrack(sound.tracks[0], sound, soundType);
}

ChannelHandle XACTSoundBank::playTrack(Track &track, const Sound &UNUSED(sound), SoundType soundType) {
ChannelHandle XACTSoundBank::playTrack(Track &track, const Sound &sound, SoundType soundType) {
if (track.waves.empty())
return ChannelHandle();

Expand All @@ -254,7 +254,7 @@ ChannelHandle XACTSoundBank::playTrack(Track &track, const Sound &UNUSED(sound),

Common::ScopedPtr<RewindableAudioStream> stream(bank->getWave(wave.index));

size_t loops = 1;
size_t loops = (sound.loopCount == kLoopCountInfinite) ? 0 : (sound.loopCount + 1);
for (Events::const_iterator event = track.events.begin(); event != track.events.end(); ++event)
if (event->type == kEventTypeLoop)
loops = (event->params.loop.count == kLoopCountInfinite) ? 0 : (event->params.loop.count + 1);
Expand Down
7 changes: 5 additions & 2 deletions src/sound/xactsoundbank.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ class XACTSoundBank {

bool gainBoost; ///< Gain boost of 6dB enabled?

bool loopNewVariation; ///< Select a new wave variation on each loop?
uint16 loopCount; ///< Number of times to loop the sound.

float volume; ///< Volume attenuation in dB. 0.0f means full volume, -64.0f is maximum attenuation.
float pitch; ///< Pitch change in semitones (-24.0f to 24.0f).

Expand All @@ -374,8 +377,8 @@ class XACTSoundBank {

Tracks tracks; ///< All the tracks in the sound.

Sound() : categoryIndex(kCategoryNone), gainBoost(false), volume(0.0f), pitch(0.0f),
volumeVariationMin(0.0f), volumeVariationMax(0.0f),
Sound() : categoryIndex(kCategoryNone), gainBoost(false), loopNewVariation(false), loopCount(0),
volume(0.0f), pitch(0.0f), volumeVariationMin(0.0f), volumeVariationMax(0.0f),
pitchVariationMin(0.0f), pitchVariationMax(0.0f),
delay(0), layer(kLayerNone), priority(255), is3D(false),
parametricEQ(false), parametricEQGain(0.0f), parametricEQQ(1.0f), parametricEQFreq(30) {
Expand Down
6 changes: 6 additions & 0 deletions src/sound/xactsoundbank_ascii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ void XACTSoundBank_ASCII::load(Common::SeekableReadStream &xsb) {
} else if (tokens[0] == "PLAY") {
bool isComplex = false;

if (tokens.size() > 1)
sound->loopCount = getNumber(tokens[1]);

if (tokens.size() > 2)
sound->loopNewVariation = tokens[2] == "1";

if (tokens.size() > 5) {
sound->pitchVariationMin = CLIP(getNumber(tokens[4]) / 100.0f, -24.0f, 24.0f);
sound->pitchVariationMax = CLIP(getNumber(tokens[5]) / 100.0f, -24.0f, 24.0f);
Expand Down
7 changes: 5 additions & 2 deletions src/sound/xactsoundbank_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ enum SoundFlags {
};

enum PlayEventFlags {
kPlayEventMultipleVariations = 0x04
kPlayEventMultipleVariations = 0x04,
kPlayEventLoopNewVariation = 0x40
};

enum PitchEventFlags {
Expand Down Expand Up @@ -227,7 +228,7 @@ void XACTSoundBank_Binary::readComplexTrack(Common::SeekableReadStream &xsb, Tra
switch (event.type) {
case kEventTypePlay:
case kEventTypePlayComplex:
xsb.skip(2); // Unused
sound.loopCount = xsb.readUint16LE();

if (parameterSize >= 4) {
const uint32 indicesOrOffset = xsb.readUint32LE();
Expand All @@ -247,6 +248,8 @@ void XACTSoundBank_Binary::readComplexTrack(Common::SeekableReadStream &xsb, Tra
parameterSize -= 12;
}

sound.loopNewVariation = eventFlags & kPlayEventLoopNewVariation;

if (!(eventFlags & kPlayEventMultipleVariations)) {
track.variationSelectMethod = kSelectMethodOrdered;

Expand Down

0 comments on commit a776e87

Please sign in to comment.