aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorbert Lange2009-07-17 00:58:26 +0000
committerNorbert Lange2009-07-17 00:58:26 +0000
commit1fa1bdc9f650b272801aa2f960a79b6fc44f1bd5 (patch)
treea443147a36d8a18e580b427339490603fbc077c1
parent30cb4772f2c5a82c4efa9b241f10d90e020020db (diff)
downloadscummvm-rg350-1fa1bdc9f650b272801aa2f960a79b6fc44f1bd5.tar.gz
scummvm-rg350-1fa1bdc9f650b272801aa2f960a79b6fc44f1bd5.tar.bz2
scummvm-rg350-1fa1bdc9f650b272801aa2f960a79b6fc44f1bd5.zip
avoid some calculations from being done every time in CalcNote
svn-id: r42553
-rw-r--r--sound/mods/maxtrax.cpp15
-rw-r--r--sound/mods/maxtrax.h8
2 files changed, 15 insertions, 8 deletions
diff --git a/sound/mods/maxtrax.cpp b/sound/mods/maxtrax.cpp
index 1178b25967..90c6a52064 100644
--- a/sound/mods/maxtrax.cpp
+++ b/sound/mods/maxtrax.cpp
@@ -276,6 +276,7 @@ endOfEventLoop:
if ((uint16)(voice.portaTicks >> 8) >= channel.portamentoTime) {
voice.hasPortamento = false;
voice.baseNote = voice.endNote;
+ voice.preCalcNote = precalcNote(voice.baseNote, patch.tune);
}
voice.lastPeriod = calcNote(voice);
} else if (channel.isAltered || channel.modulation)
@@ -329,7 +330,7 @@ void MaxTrax::killVoice(byte num) {
voice.flags = 0;
voice.hasPortamento = false;
voice.priority = 0;
- voice.uinqueId = 0;
+ //voice.uinqueId = 0;
// "stop" voice, set period to 1, vol to 0
Paula::disableChannel(num);
@@ -385,9 +386,7 @@ uint16 MaxTrax::calcNote(const VoiceContext &voice, int32 *offset) {
const ChannelContext &channel = *voice.channel;
int16 bend = channel.pitchReal;
if (voice.hasPortamento)
- bend = (int16)(((int8)(voice.endNote - voice.baseNote)) * voice.portaTicks) / channel.portamentoTime;
-
- const Patch &patch = *voice.patch;
+ bend += (int16)(((int8)(voice.endNote - voice.baseNote)) * voice.portaTicks) / channel.portamentoTime;
// 0x9fd77 ~ log2(1017) MIDI F5 ?
// 0x8fd77 ~ log2(508.5) MIDI F4 ?
@@ -396,11 +395,12 @@ uint16 MaxTrax::calcNote(const VoiceContext &voice, int32 *offset) {
// tone = voice.baseNote << 8 + microtonal
// bend = channelPitch + porta + modulation
- int32 tone = K_VALUE + 0x3C000 - ((voice.baseNote << 14) + (bend << 6) + (patch.tune << 14) / 24) / 3;
+
+ int32 tone = voice.preCalcNote + (bend << 6) / 3;
// calculate which sample to use
if (offset) {
- *offset = (tone <= PREF_PERIOD) ? 0 : MIN((int32)((tone + 0xFFFF - PREF_PERIOD) >> 16), (int32)(patch.sampleOctaves - 1)) << 16;
+ *offset = (tone <= PREF_PERIOD) ? 0 : MIN((int32)((tone + 0xFFFF - PREF_PERIOD) >> 16), (int32)(voice.patch->sampleOctaves - 1)) << 16;
tone -= *offset;
} else
tone -= voice.periodOffset;
@@ -432,6 +432,7 @@ int8 MaxTrax::noteOn(ChannelContext &channel, const byte note, uint16 volume, ui
// reset previous porta
if (voice->hasPortamento)
voice->baseNote = voice->endNote;
+ voice->preCalcNote = precalcNote(voice->baseNote, patch.tune);
voice->portaTicks = 0;
voice->hasPortamento = true;
voice->endNote = channel.lastNote = note;
@@ -450,6 +451,7 @@ int8 MaxTrax::noteOn(ChannelContext &channel, const byte note, uint16 volume, ui
voice.channel = &channel;
voice.patch = &patch;
voice.baseNote = note;
+ voice.preCalcNote = precalcNote(voice.baseNote, patch.tune);
voice.hasPortamento = false;
@@ -507,6 +509,7 @@ int8 MaxTrax::noteOn(ChannelContext &channel, const byte note, uint16 volume, ui
voice.portaTicks = 0;
voice.endNote = voice.baseNote;
voice.baseNote = channel.lastNote;
+ voice.preCalcNote = precalcNote(voice.baseNote, patch.tune);
voice.hasPortamento = true;
}
channel.lastNote = note;
diff --git a/sound/mods/maxtrax.h b/sound/mods/maxtrax.h
index 2884186caa..7c3f2c337b 100644
--- a/sound/mods/maxtrax.h
+++ b/sound/mods/maxtrax.h
@@ -147,8 +147,8 @@ public:
ChannelContext *channel;
const Patch *patch;
const Envelope *envelope;
- uint32 uinqueId;
- uint32 lastTicks;
+// uint32 uinqueId;
+ int32 preCalcNote;
uint32 ticksLeft;
int32 portaTicks;
int32 incrVolume;
@@ -213,6 +213,10 @@ public:
_playerCtx.tickUnit = (int32)(((uint32)(tempo & 0xFFF0) << 8) / (uint16)(5 * _playerCtx.vBlankFreq));
}
+ static int32 precalcNote(byte baseNote, int16 tune) {
+ return 0x9fd77 + 0x3C000 - ((baseNote << 14) + (tune << 11) / 3) / 3;
+ }
+
static void outPutEvent(const Event &ev, int num = -1) {
struct {
byte cmd;