aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorbert Lange2009-07-10 16:01:40 +0000
committerNorbert Lange2009-07-10 16:01:40 +0000
commit100d86ee4d3bc412ae61e890ca45b0e2a3d57895 (patch)
tree294e82158da755dc43f7baa71849bcfd121ee8f9
parent3ae850fe9c14d2feffbbad0b31df0c9f4ae0cb96 (diff)
downloadscummvm-rg350-100d86ee4d3bc412ae61e890ca45b0e2a3d57895.tar.gz
scummvm-rg350-100d86ee4d3bc412ae61e890ca45b0e2a3d57895.tar.bz2
scummvm-rg350-100d86ee4d3bc412ae61e890ca45b0e2a3d57895.zip
made all structures that are only written when loading song/samples const
fixed volume-handling a bit, still not correct svn-id: r42343
-rw-r--r--sound/mods/maxtrax.cpp38
-rw-r--r--sound/mods/maxtrax.h16
2 files changed, 31 insertions, 23 deletions
diff --git a/sound/mods/maxtrax.cpp b/sound/mods/maxtrax.cpp
index b922fb0dc3..b94f1fd4e5 100644
--- a/sound/mods/maxtrax.cpp
+++ b/sound/mods/maxtrax.cpp
@@ -83,7 +83,7 @@ void MaxTrax::interrupt() {
}
if (_playerCtx.musicPlaying) {
- Event *curEvent = _playerCtx.nextEvent;
+ const Event *curEvent = _playerCtx.nextEvent;
int32 eventTime = _playerCtx.nextEventTime;
for (; eventTime <= millis; eventTime += (++curEvent)->startTime) {
const byte cmd = curEvent->command;
@@ -170,8 +170,8 @@ void MaxTrax::interrupt() {
VoiceContext &voice = _voiceCtx[i]; // a2
if (!voice.channel)
continue;
- ChannelContext &channel = *voice.channel; // a3
- Patch &patch = *voice.patch; // a5, used with start and later
+ const ChannelContext &channel = *voice.channel; // a3
+ const Patch &patch = *voice.patch; // a5, used with start and later
voice.lastTicks += _playerCtx.tickUnit;
bool envHandling = true;
byte newVolume = 0xFF; // if set to 0 this means skip recalc
@@ -230,6 +230,8 @@ void MaxTrax::interrupt() {
// .I9 - env managment
if (envHandling) {
assert(voice.status != VoiceContext::kStatusSustain);
+ assert(voice.envelope);
+ assert(voice.envelopeLeft >= 0);
if (voice.ticksLeft > _playerCtx.tickUnit) {
voice.baseVolume = (uint16)MIN(MAX(0, voice.baseVolume + voice.incrVolume), 0x8000);
voice.ticksLeft -= _playerCtx.tickUnit;
@@ -237,6 +239,7 @@ void MaxTrax::interrupt() {
} else {
// a0 = voice.envelope
voice.baseVolume = voice.envelope->volume;
+ assert(voice.envelopeLeft > 0);
if (--voice.envelopeLeft) {
++voice.envelope;
const uint16 duration = voice.envelope->duration;
@@ -245,6 +248,7 @@ void MaxTrax::interrupt() {
voice.incrVolume = (duration) ? (1000 * vol) / (duration * _playerCtx.vBlankFreq) : vol;
// goto .l18
} else if (voice.status == VoiceContext::kStatusDecay) {
+ voice.envelope = 0;
voice.status = VoiceContext::kStatusHalt;
// set d4 = 0, goto I17
newVolume = 0;
@@ -252,17 +256,19 @@ void MaxTrax::interrupt() {
assert(voice.status == VoiceContext::kStatusAttack);
voice.status = VoiceContext::kStatusSustain;
voice.lastTicks = _playerCtx.tickUnit;
+ voice.envelope = 0;
// goto .l18
}
}
- }
+ } else
+ assert(voice.envelope == 0);
// .l18 - recalc
if (newVolume) {
// calc volume
uint16 vol = (voice.noteVolume < (1 << 7)) ? (voice.noteVolume * _playerCtx.volume) >> 7 : _playerCtx.volume;
if (voice.baseVolume < (1 << 15))
- vol = (vol * (voice.baseVolume >> 8)) >> 7;
+ vol = (uint16)(((uint32)vol * voice.baseVolume) >> 15);
if (voice.channel->volume < (1 << 7))
vol = (vol * voice.channel->volume) >> 7;
@@ -329,13 +335,13 @@ void MaxTrax::killVoice(byte num) {
voice.uinqueId = 0;
// "stop" voice, set period to 1, vol to 0
- Paula::disableChannel(0);
+ Paula::disableChannel(num);
Paula::setChannelPeriod(num, 1);
Paula::setChannelVolume(num, 0);
}
int MaxTrax::calcNote(VoiceContext &voice) {
- ChannelContext &channel = *voice.channel;
+ const ChannelContext &channel = *voice.channel;
voice.lastPeriod = 0;
int16 bend = 0;
@@ -355,7 +361,7 @@ int MaxTrax::calcNote(VoiceContext &voice) {
// more it-never-worked microtonal code
tone += voice.baseNote << 8;
- Patch &patch = *voice.patch;
+ const Patch &patch = *voice.patch;
tone += ((int16)patch.tune << 8) / 24;
tone -= 45 << 8; // MIDI note 45
@@ -387,7 +393,7 @@ int8 MaxTrax::noteOn(ChannelContext &channel, const byte note, uint16 volume, ui
if (!volume)
return -1;
- Patch &patch = *channel.patch;
+ const Patch &patch = *channel.patch;
if (!patch.samplePtr)
return -1;
int8 voiceNum = -1;
@@ -416,7 +422,7 @@ int8 MaxTrax::noteOn(ChannelContext &channel, const byte note, uint16 volume, ui
// return if no channel found
voiceNum = (channel.flags & ChannelContext::kFlagRightChannel) != 0 ? 0 : 1;
static int c = 0;
- voiceNum = (++c) % 4;
+ voiceNum = (&channel - _channelCtx) % 4;
}
assert(voiceNum >= 0 && voiceNum < ARRAYSIZE(_voiceCtx));
@@ -535,7 +541,7 @@ void MaxTrax::freePatches() {
delete[] _patch[i].samplePtr;
delete[] _patch[i].attackPtr;
}
- memset(_patch, 0, sizeof(_patch));
+ memset(const_cast<Patch *>(_patch), 0, sizeof(_patch));
}
bool MaxTrax::load(Common::SeekableReadStream &musicData, bool loadScores, bool loadSamples) {
@@ -581,7 +587,8 @@ bool MaxTrax::load(Common::SeekableReadStream &musicData, bool loadScores, bool
for (int i = tempScores; i > 0; --i, ++curScore) {
const uint32 numEvents = musicData.readUint32BE();
- Event *curEvent = curScore->events = new Event[numEvents];
+ Event *curEvent = new Event[numEvents];
+ curScore->events = curEvent;
for (int j = numEvents; j > 0; --j, ++curEvent) {
curEvent->command = musicData.readByte();
curEvent->parameter = musicData.readByte();
@@ -612,7 +619,7 @@ bool MaxTrax::load(Common::SeekableReadStream &musicData, bool loadScores, bool
const uint16 number = musicData.readUint16BE();
assert(number < ARRAYSIZE(_patch));
// pointer to samples needed?
- Patch &curPatch = _patch[number];
+ Patch &curPatch = const_cast<Patch &>(_patch[number]);
curPatch.tune = musicData.readUint16BE();
curPatch.volume = musicData.readUint16BE();
@@ -641,8 +648,9 @@ bool MaxTrax::load(Common::SeekableReadStream &musicData, bool loadScores, bool
}
// read Samples
- curPatch.samplePtr = new int8[totalSamples];
- musicData.read(curPatch.samplePtr, totalSamples);
+ int8 *allocSamples = new int8[totalSamples];
+ curPatch.samplePtr = allocSamples;
+ musicData.read(allocSamples, totalSamples);
}
} else if (wavesInFile > 0){
uint32 skipLen = 3 * 2;
diff --git a/sound/mods/maxtrax.h b/sound/mods/maxtrax.h
index 1edfa5945b..cdfb614580 100644
--- a/sound/mods/maxtrax.h
+++ b/sound/mods/maxtrax.h
@@ -68,7 +68,7 @@ public:
bool musicLoop;
int scoreIndex;
- Event *nextEvent;
+ const Event *nextEvent;
int32 nextEventTime;
bool addedNote;
@@ -82,8 +82,8 @@ public:
uint16 volume;
};
- struct Patch {
- Envelope *attackPtr;
+ const struct Patch {
+ const Envelope *attackPtr;
//Envelope *releasePtr;
uint16 attackLen;
uint16 releaseLen;
@@ -92,7 +92,7 @@ public:
uint16 volume;
// this was the SampleData struct in the assembler source
- int8 *samplePtr;
+ const int8 *samplePtr;
uint32 sampleTotalLen;
uint32 sampleAttackLen;
uint16 sampleOctaves;
@@ -106,14 +106,14 @@ public:
};
struct Score {
- Event *events;
+ const Event *events;
uint32 numEvents;
} *_scores;
int _numScores;
struct ChannelContext {
- Patch *patch;
+ const Patch *patch;
uint16 regParamNumber;
uint16 modulation;
@@ -149,8 +149,8 @@ public:
struct VoiceContext {
ChannelContext *channel;
- Patch *patch;
- Envelope *envelope;
+ const Patch *patch;
+ const Envelope *envelope;
uint32 uinqueId;
uint32 lastTicks;
uint32 ticksLeft;