DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/mt32/TVA.h
00001 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
00002  * Copyright (C) 2011, 2012, 2013 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
00003  *
00004  *  This program is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 2.1 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef MT32EMU_TVA_H
00019 #define MT32EMU_TVA_H
00020 
00021 namespace MT32Emu {
00022 
00023 class Part;
00024 
00025 // Note that when entering nextPhase(), newPhase is set to phase + 1, and the descriptions/names below refer to
00026 // newPhase's value.
00027 enum {
00028         // In this phase, the base amp (as calculated in calcBasicAmp()) is targeted with an instant time.
00029         // This phase is entered by reset() only if time[0] != 0.
00030         TVA_PHASE_BASIC = 0,
00031 
00032         // In this phase, level[0] is targeted within time[0], and velocity potentially affects time
00033         TVA_PHASE_ATTACK = 1,
00034 
00035         // In this phase, level[1] is targeted within time[1]
00036         TVA_PHASE_2 = 2,
00037 
00038         // In this phase, level[2] is targeted within time[2]
00039         TVA_PHASE_3 = 3,
00040 
00041         // In this phase, level[3] is targeted within time[3]
00042         TVA_PHASE_4 = 4,
00043 
00044         // In this phase, immediately goes to PHASE_RELEASE unless the poly is set to sustain.
00045         // Aborts the partial if level[3] is 0.
00046         // Otherwise level[3] is continued, no phase change will occur until some external influence (like pedal release)
00047         TVA_PHASE_SUSTAIN = 5,
00048 
00049         // In this phase, 0 is targeted within time[4] (the time calculation is quite different from the other phases)
00050         TVA_PHASE_RELEASE = 6,
00051 
00052         // It's PHASE_DEAD, Jim.
00053         TVA_PHASE_DEAD = 7
00054 };
00055 
00056 class TVA {
00057 private:
00058         const Partial * const partial;
00059         LA32Ramp *ampRamp;
00060         const MemParams::System * const system;
00061 
00062         const Part *part;
00063         const TimbreParam::PartialParam *partialParam;
00064         const MemParams::PatchTemp *patchTemp;
00065         const MemParams::RhythmTemp *rhythmTemp;
00066 
00067         bool playing = false;
00068 
00069         int biasAmpSubtraction = 0;
00070         int veloAmpSubtraction = 0;
00071         int keyTimeSubtraction = 0;
00072 
00073         Bit8u target = 0;
00074         int phase;
00075 
00076         void startRamp(Bit8u newTarget, Bit8u newIncrement, int newPhase);
00077         void end(int newPhase);
00078         void nextPhase();
00079 
00080 public:
00081         TVA(const Partial *usePartial, LA32Ramp *useAmpRamp);
00082         void reset(const Part *newPart, const TimbreParam::PartialParam *newPartialParam, const MemParams::RhythmTemp *newRhythmTemp);
00083         void handleInterrupt();
00084         void recalcSustain();
00085         void startDecay();
00086         void startAbort();
00087 
00088         bool isPlaying() const;
00089         int getPhase() const;
00090 
00091         void saveState( std::ostream &stream );
00092         void loadState( std::istream &stream );
00093 
00094         // savestate debugging
00095         void rawVerifyState( char *name, Synth *synth );
00096 };
00097 
00098 }
00099 
00100 #endif /* TVA_H_ */