DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/mt32/Partial.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_PARTIAL_H
00019 #define MT32EMU_PARTIAL_H
00020 
00021 #include "FileStream.h"
00022 
00023 namespace MT32Emu {
00024 
00025 class Synth;
00026 class Part;
00027 class TVA;
00028 struct ControlROMPCMStruct;
00029 
00030 struct StereoVolume {
00031         float leftVol;
00032         float rightVol;
00033 };
00034 
00035 // A partial represents one of up to four waveform generators currently playing within a poly.
00036 class Partial {
00037 private:
00038         Synth *synth;
00039         const int debugPartialNum; // Only used for debugging
00040         // Number of the sample currently being rendered by generateSamples(), or 0 if no run is in progress
00041         // This is only kept available for debugging purposes.
00042         unsigned long sampleNum;
00043 
00044         int ownerPart; // -1 if unassigned
00045         int mixType;
00046         int structurePosition; // 0 or 1 of a structure pair
00047         StereoVolume stereoVolume;
00048 
00049         Bit16s myBuffer[MAX_SAMPLES_PER_RUN];
00050 
00051         // Only used for PCM partials
00052         int pcmNum;
00053         // FIXME: Give this a better name (e.g. pcmWaveInfo)
00054         PCMWaveEntry *pcmWave;
00055 
00056         // Final pulse width value, with velfollow applied, matching what is sent to the LA32.
00057         // Range: 0-255
00058         int pulseWidthVal;
00059 
00060         Poly *poly;
00061 
00062         LA32Ramp ampRamp;
00063         LA32Ramp cutoffModifierRamp;
00064 
00065         // TODO: This should be owned by PartialPair
00066         LA32PartialPair la32Pair;
00067 
00068         Bit32u getAmpValue();
00069         Bit32u getCutoffValue();
00070 
00071 public:
00072         const PatchCache *patchCache;
00073         TVA *tva;
00074         TVP *tvp;
00075         TVF *tvf;
00076 
00077         PatchCache cachebackup;
00078 
00079         Partial *pair;
00080         bool alreadyOutputed;
00081 
00082         Partial(Synth *synth, int debugPartialNum);
00083         ~Partial();
00084 
00085         int debugGetPartialNum() const;
00086         unsigned long debugGetSampleNum() const;
00087 
00088         int getOwnerPart() const;
00089         const Poly *getPoly() const;
00090         bool isActive() const;
00091         void activate(int part);
00092         void deactivate(void);
00093         void startPartial(const Part *part, Poly *usePoly, const PatchCache *useCache, const MemParams::RhythmTemp *rhythmTemp, Partial *pairPartial);
00094         void startAbort();
00095         void startDecayAll();
00096         bool shouldReverb();
00097         bool hasRingModulatingSlave() const;
00098         bool isRingModulatingSlave() const;
00099         bool isPCM() const;
00100         const ControlROMPCMStruct *getControlROMPCMStruct() const;
00101         Synth *getSynth() const;
00102 
00103         // Returns true only if data written to buffer
00104         // This function (unlike the one below it) returns processed stereo samples
00105         // made from combining this single partial with its pair, if it has one.
00106         bool produceOutput(float *leftBuf, float *rightBuf, unsigned long length);
00107 
00108         // This function writes mono sample output to the provided buffer, and returns the number of samples written
00109         unsigned long generateSamples(Bit16s *partialBuf, unsigned long length);
00110 };
00111 
00112 }
00113 
00114 #endif