diff options
Diffstat (limited to 'audio/softsynth/mt32/TVP.cpp')
-rwxr-xr-x[-rw-r--r--] | audio/softsynth/mt32/TVP.cpp | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/audio/softsynth/mt32/TVP.cpp b/audio/softsynth/mt32/TVP.cpp index a8003d96dc..dca0003843 100644..100755 --- a/audio/softsynth/mt32/TVP.cpp +++ b/audio/softsynth/mt32/TVP.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher - * Copyright (C) 2011, 2012, 2013, 2014 Dean Beeler, Jerome Fisher, Sergey V. Mikayev + * Copyright (C) 2011-2016 Dean Beeler, Jerome Fisher, Sergey V. Mikayev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -15,12 +15,17 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -//#include <cmath> -//#include <cstdlib> +#include <cstdlib> -#include "mt32emu.h" #include "internals.h" +#include "TVP.h" +#include "Part.h" +#include "Partial.h" +#include "Poly.h" +#include "Synth.h" +#include "TVA.h" + namespace MT32Emu { // FIXME: Add Explanation @@ -47,7 +52,7 @@ static Bit16u keyToPitchTable[] = { }; TVP::TVP(const Partial *usePartial) : - partial(usePartial), system_(&usePartial->getSynth()->mt32ram.system) { + partial(usePartial), system(&usePartial->getSynth()->mt32ram.system) { // We want to do processing 4000 times per second. FIXME: This is pretty arbitrary. maxCounter = SAMPLE_RATE / 4000; // The timer runs at 500kHz. We only need to bother updating it every maxCounter samples, before we do processing. @@ -58,7 +63,7 @@ TVP::TVP(const Partial *usePartial) : static Bit16s keyToPitch(unsigned int key) { // We're using a table to do: return round_to_nearest_or_even((key - 60) * (4096.0 / 12.0)) // Banker's rounding is just slightly annoying to do in C++ - int k = (int)key; + int k = int(key); Bit16s pitch = keyToPitchTable[abs(k - 60)]; return key < 60 ? -pitch : pitch; } @@ -82,7 +87,7 @@ static Bit32u calcBasePitch(const Partial *partial, const TimbreParam::PartialPa const ControlROMPCMStruct *controlROMPCMStruct = partial->getControlROMPCMStruct(); if (controlROMPCMStruct != NULL) { - basePitch += (Bit32s)((((Bit32s)controlROMPCMStruct->pitchMSB) << 8) | (Bit32s)controlROMPCMStruct->pitchLSB); + basePitch += (Bit32s(controlROMPCMStruct->pitchMSB) << 8) | Bit32s(controlROMPCMStruct->pitchLSB); } else { if ((partialParam->wg.waveform & 1) == 0) { basePitch += 37133; // This puts Middle C at around 261.64Hz (assuming no other modifications, masterTune of 64, etc.) @@ -98,7 +103,7 @@ static Bit32u calcBasePitch(const Partial *partial, const TimbreParam::PartialPa if (basePitch > 59392) { basePitch = 59392; } - return (Bit32u)basePitch; + return Bit32u(basePitch); } static Bit32u calcVeloMult(Bit8u veloSensitivity, unsigned int velocity) { @@ -119,7 +124,7 @@ static Bit32u calcVeloMult(Bit8u veloSensitivity, unsigned int velocity) { static Bit32s calcTargetPitchOffsetWithoutLFO(const TimbreParam::PartialParam *partialParam, int levelIndex, unsigned int velocity) { int veloMult = calcVeloMult(partialParam->pitchEnv.veloSensitivity, velocity); int targetPitchOffsetWithoutLFO = partialParam->pitchEnv.level[levelIndex] - 50; - targetPitchOffsetWithoutLFO = (Bit32s)(targetPitchOffsetWithoutLFO * veloMult) >> (16 - partialParam->pitchEnv.depth); // PORTABILITY NOTE: Assumes arithmetic shift + targetPitchOffsetWithoutLFO = (targetPitchOffsetWithoutLFO * veloMult) >> (16 - partialParam->pitchEnv.depth); // PORTABILITY NOTE: Assumes arithmetic shift return targetPitchOffsetWithoutLFO; } @@ -140,7 +145,7 @@ void TVP::reset(const Part *usePart, const TimbreParam::PartialParam *usePartial phase = 0; if (partialParam->pitchEnv.timeKeyfollow) { - timeKeyfollowSubtraction = (key - 60) >> (5 - partialParam->pitchEnv.timeKeyfollow); // PORTABILITY NOTE: Assumes arithmetic shift + timeKeyfollowSubtraction = Bit32s(key - 60) >> (5 - partialParam->pitchEnv.timeKeyfollow); // PORTABILITY NOTE: Assumes arithmetic shift } else { timeKeyfollowSubtraction = 0; } @@ -163,7 +168,7 @@ void TVP::updatePitch() { if (!partial->isPCM() || (partial->getControlROMPCMStruct()->len & 0x01) == 0) { // FIXME: Use !partial->pcmWaveEntry->unaffectedByMasterTune instead // FIXME: masterTune recalculation doesn't really happen here, and there are various bugs not yet emulated // 171 is ~half a semitone. - newPitch += ((system_->masterTune - 64) * 171) >> 6; // PORTABILITY NOTE: Assumes arithmetic shift. + newPitch += ((system->masterTune - 64) * 171) >> 6; // PORTABILITY NOTE: Assumes arithmetic shift. } if ((partialParam->wg.pitchBenderEnabled & 1) != 0) { newPitch += part->getPitchBend(); @@ -172,14 +177,13 @@ void TVP::updatePitch() { newPitch = 0; } -// Note: Temporary #ifdef until we have proper "quirk" configuration -// This is about right emulation of MT-32 GEN0 quirk exploited in Colonel's Bequest timbre "Lightning" -#ifndef MT32EMU_QUIRK_PITCH_ENVELOPE_OVERFLOW_MT32 - if (newPitch > 59392) { - newPitch = 59392; + // Skipping this check seems about right emulation of MT-32 GEN0 quirk exploited in Colonel's Bequest timbre "Lightning" + if (partial->getSynth()->controlROMFeatures->quirkPitchEnvelopeOverflow == 0) { + if (newPitch > 59392) { + newPitch = 59392; + } } -#endif - pitch = (Bit16u)newPitch; + pitch = Bit16u(newPitch); // FIXME: We're doing this here because that's what the CM-32L does - we should probably move this somewhere more appropriate in future. partial->getTVA()->recalcSustain(); @@ -317,10 +321,10 @@ void TVP::process() { negativeBigTicksRemaining = negativeBigTicksRemaining >> rightShifts; // PORTABILITY NOTE: Assumes arithmetic shift rightShifts = 13; } - int newResult = ((Bit32s)(negativeBigTicksRemaining * pitchOffsetChangePerBigTick)) >> rightShifts; // PORTABILITY NOTE: Assumes arithmetic shift + int newResult = (negativeBigTicksRemaining * pitchOffsetChangePerBigTick) >> rightShifts; // PORTABILITY NOTE: Assumes arithmetic shift newResult += targetPitchOffsetWithoutLFO + lfoPitchOffset; currentPitchOffset = newResult; updatePitch(); } -} +} // namespace MT32Emu |