void TVA::recalcSustain() { // We get pinged periodically by the pitch code to recalculate our values when in sustain. // This is done so that the TVA will respond to things like MIDI expression and volume changes while it's sustaining, which it otherwise wouldn't do. // The check for envLevel[3] == 0 strikes me as slightly dumb. FIXME: Explain why if (phase != TVA_PHASE_SUSTAIN || partialParam->tva.envLevel[3] == 0) { return; } // We're sustaining. Recalculate all the values const Tables *tables = &Tables::getInstance(); int newTarget = calcBasicAmp(tables, partial, system, partialParam, patchTemp, rhythmTemp, biasAmpSubtraction, veloAmpSubtraction, part->getExpression(), partial->getSynth()->controlROMFeatures->quirkRingModulationNoMix); newTarget += partialParam->tva.envLevel[3]; // Although we're in TVA_PHASE_SUSTAIN at this point, we cannot be sure that there is no active ramp at the moment. // In case the channel volume or the expression changes frequently, the previously started ramp may still be in progress. // Real hardware units ignore this possibility and rely on the assumption that the target is the current amp. // This is OK in most situations but when the ramp that is currently in progress needs to change direction // due to a volume/expression update, this leads to a jump in the amp that is audible as an unpleasant click. // To avoid that, we compare the newTarget with the the actual current ramp value and correct the direction if necessary. int targetDelta = newTarget - target; // Calculate an increment to get to the new amp value in a short, more or less consistent amount of time Bit8u newIncrement; bool descending = targetDelta < 0; if (!descending) { newIncrement = tables->envLogarithmicTime[Bit8u(targetDelta)] - 2; } else { newIncrement = (tables->envLogarithmicTime[Bit8u(-targetDelta)] - 2) | 0x80; } if (part->getSynth()->isNiceAmpRampEnabled() && (descending != ampRamp->isBelowCurrent(newTarget))) { newIncrement ^= 0x80; } // Configure so that once the transition's complete and nextPhase() is called, we'll just re-enter sustain phase (or decay phase, depending on parameters at the time). startRamp(newTarget, newIncrement, TVA_PHASE_SUSTAIN - 1); }
void TVA::reset(const Part *newPart, const TimbreParam::PartialParam *newPartialParam, const MemParams::RhythmTemp *newRhythmTemp) { part = newPart; partialParam = newPartialParam; patchTemp = newPart->getPatchTemp(); rhythmTemp = newRhythmTemp; playing = true; const Tables *tables = &Tables::getInstance(); int key = partial->getPoly()->getKey(); int velocity = partial->getPoly()->getVelocity(); keyTimeSubtraction = calcKeyTimeSubtraction(partialParam->tva.envTimeKeyfollow, key); biasAmpSubtraction = calcBiasAmpSubtractions(partialParam, key); veloAmpSubtraction = calcVeloAmpSubtraction(partialParam->tva.veloSensitivity, velocity); int newTarget = calcBasicAmp(tables, partial, system, partialParam, patchTemp, newRhythmTemp, biasAmpSubtraction, veloAmpSubtraction, part->getExpression(), partial->getSynth()->controlROMFeatures->quirkRingModulationNoMix); int newPhase; if (partialParam->tva.envTime[0] == 0) { // Initially go to the TVA_PHASE_ATTACK target amp, and spend the next phase going from there to the TVA_PHASE_2 target amp // Note that this means that velocity never affects time for this partial. newTarget += partialParam->tva.envLevel[0]; newPhase = TVA_PHASE_ATTACK; // The first target used in nextPhase() will be TVA_PHASE_2 } else { // Initially go to the base amp determined by TVA level, part volume, etc., and spend the next phase going from there to the full TVA_PHASE_ATTACK target amp. newPhase = TVA_PHASE_BASIC; // The first target used in nextPhase() will be TVA_PHASE_ATTACK } ampRamp->reset();//currentAmp = 0; // "Go downward as quickly as possible". // Since the current value is 0, the LA32Ramp will notice that we're already at or below the target and trying to go downward, // and therefore jump to the target immediately and raise an interrupt. startRamp(Bit8u(newTarget), 0x80 | 127, newPhase); }
static bool isvalid(const char in) { const char ill[]=ILLEGAL; return (Bit8u(in)>0x1F) && (!strchr(ill,in)); }
static bool isvalid(const char in) { return (Bit8u(in) > 0x1F) && (!strchr(":.;,=+ \t/\"[]<>|", in)); }
Tables::Tables() { for (int lf = 0; lf <= 100; lf++) { // CONFIRMED:KG: This matches a ROM table found by Mok float fVal = (2.0f - LOG10F(float(lf) + 1.0f)) * 128.0f; int val = int(fVal + 1.0); if (val > 255) { val = 255; } levelToAmpSubtraction[lf] = Bit8u(val); } envLogarithmicTime[0] = 64; for (int lf = 1; lf <= 255; lf++) { // CONFIRMED:KG: This matches a ROM table found by Mok envLogarithmicTime[lf] = Bit8u(ceil(64.0f + LOG2F(float(lf)) * 8.0f)); } #if 0 // The table below is to be used in conjunction with emulation of VCA of newer generation units which is currently missing. // These relatively small values are rather intended to fine-tune the overall amplification of the VCA. // CONFIRMED: Based on a table found by Mok in the LAPC-I control ROM // Note that this matches the MT-32 table, but with the values clamped to a maximum of 8. memset(masterVolToAmpSubtraction, 8, 71); memset(masterVolToAmpSubtraction + 71, 7, 3); memset(masterVolToAmpSubtraction + 74, 6, 4); memset(masterVolToAmpSubtraction + 78, 5, 3); memset(masterVolToAmpSubtraction + 81, 4, 4); memset(masterVolToAmpSubtraction + 85, 3, 3); memset(masterVolToAmpSubtraction + 88, 2, 4); memset(masterVolToAmpSubtraction + 92, 1, 4); memset(masterVolToAmpSubtraction + 96, 0, 5); #else // CONFIRMED: Based on a table found by Mok in the MT-32 control ROM masterVolToAmpSubtraction[0] = 255; for (int masterVol = 1; masterVol <= 100; masterVol++) { masterVolToAmpSubtraction[masterVol] = Bit8u(106.31 - 16.0f * LOG2F(float(masterVol))); } #endif for (int i = 0; i <= 100; i++) { pulseWidth100To255[i] = Bit8u(i * 255 / 100.0f + 0.5f); //synth->printDebug("%d: %d", i, pulseWidth100To255[i]); } // The LA32 chip contains an exponent table inside. The table contains 12-bit integer values. // The actual table size is 512 rows. The 9 higher bits of the fractional part of the argument are used as a lookup address. // To improve the precision of computations, the lower bits are supposed to be used for interpolation as the LA32 chip also // contains another 512-row table with inverted differences between the main table values. for (int i = 0; i < 512; i++) { exp9[i] = Bit16u(8191.5f - EXP2F(13.0f + ~i / 512.0f)); } // There is a logarithmic sine table inside the LA32 chip. The table contains 13-bit integer values. for (int i = 1; i < 512; i++) { logsin9[i] = Bit16u(0.5f - LOG2F(sin((i + 0.5f) / 1024.0f * FLOAT_PI)) * 1024.0f); } // The very first value is clamped to the maximum possible 13-bit integer logsin9[0] = 8191; // found from sample analysis static const Bit8u resAmpDecayFactorTable[] = {31, 16, 12, 8, 5, 3, 2, 1}; resAmpDecayFactor = resAmpDecayFactorTable; }