DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
src/mt32/TVP.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_TVP_H
00019 #define MT32EMU_TVP_H
00020 
00021 namespace MT32Emu {
00022 
00023 class TVP {
00024 private:
00025         const Partial * const partial;
00026         const MemParams::System * const system; // FIXME: Only necessary because masterTune calculation is done in the wrong place atm.
00027 
00028         const Part *part;
00029         const TimbreParam::PartialParam *partialParam;
00030         const MemParams::PatchTemp *patchTemp;
00031 
00032         int maxCounter;
00033         int processTimerIncrement;
00034         int counter;
00035         Bit32u timeElapsed;
00036 
00037         int phase;
00038         Bit32u basePitch;
00039         Bit32s targetPitchOffsetWithoutLFO;
00040         Bit32s currentPitchOffset;
00041 
00042         Bit16s lfoPitchOffset;
00043         // In range -12 - 36
00044         Bit8s timeKeyfollowSubtraction;
00045 
00046         Bit16s pitchOffsetChangePerBigTick;
00047         Bit16u targetPitchOffsetReachedBigTick;
00048         unsigned int shifts;
00049 
00050         Bit16u pitch;
00051 
00052         void updatePitch();
00053         void setupPitchChange(int targetPitchOffset, Bit8u changeDuration);
00054         void targetPitchOffsetReached();
00055         void nextPhase();
00056         void process();
00057 public:
00058         TVP(const Partial *partial);
00059         void reset(const Part *part, const TimbreParam::PartialParam *partialParam);
00060         Bit32u getBasePitch() const;
00061         Bit16u nextPitch();
00062         void startDecay();
00063 
00064         void saveState( std::ostream &stream );
00065         void loadState( std::istream &stream );
00066 
00067         // savestate debugging
00068         void rawVerifyState( char *name, Synth *synth );
00069 };
00070 
00071 }
00072 
00073 #endif