ScummVM API documentation
Partial.h
1 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
2  * Copyright (C) 2011-2022 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MT32EMU_PARTIAL_H
19 #define MT32EMU_PARTIAL_H
20 
21 #include "globals.h"
22 #include "internals.h"
23 #include "Types.h"
24 #include "Structures.h"
25 #include "LA32Ramp.h"
26 #include "LA32WaveGenerator.h"
27 #include "LA32FloatWaveGenerator.h"
28 
29 namespace MT32Emu {
30 
31 class Part;
32 class Poly;
33 class Synth;
34 class TVA;
35 class TVF;
36 class TVP;
37 struct ControlROMPCMStruct;
38 
39 // A partial represents one of up to four waveform generators currently playing within a poly.
40 class Partial {
41 private:
42  Synth *synth;
43  const int partialIndex; // Index of this Partial in the global partial table
44  // Number of the sample currently being rendered by produceOutput(), or 0 if no run is in progress
45  // This is only kept available for debugging purposes.
46  Bit32u sampleNum;
47 
48  // Actually, LA-32 receives only 3 bits as a pan setting, but we abuse these to emulate
49  // the inverted partial mixing as well. Also we double the values (making them correspond
50  // to the panpot range) to enable NicePanning mode, with respect to MoK.
51  Bit32s leftPanValue, rightPanValue;
52 
53  int ownerPart; // -1 if unassigned
54  int mixType;
55  int structurePosition; // 0 or 1 of a structure pair
56 
57  // Only used for PCM partials
58  int pcmNum;
59  // FIXME: Give this a better name (e.g. pcmWaveInfo)
60  PCMWaveEntry *pcmWave;
61 
62  // Final pulse width value, with velfollow applied, matching what is sent to the LA32.
63  // Range: 0-255
64  int pulseWidthVal;
65 
66  Poly *poly;
67  Partial *pair;
68 
69  TVA *tva;
70  TVP *tvp;
71  TVF *tvf;
72 
73  LA32Ramp ampRamp;
74  LA32Ramp cutoffModifierRamp;
75 
76  // TODO: This should be owned by PartialPair
77  LA32PartialPair *la32Pair;
78  const bool floatMode;
79 
80  const PatchCache *patchCache;
81  PatchCache cachebackup;
82 
83  Bit32u getAmpValue();
84  Bit32u getCutoffValue();
85 
86  template <class Sample, class LA32PairImpl>
87  bool doProduceOutput(Sample *leftBuf, Sample *rightBuf, Bit32u length, LA32PairImpl *la32PairImpl);
88  bool canProduceOutput();
89  template <class LA32PairImpl>
90  bool generateNextSample(LA32PairImpl *la32PairImpl);
91  void produceAndMixSample(IntSample *&leftBuf, IntSample *&rightBuf, LA32IntPartialPair *la32IntPair);
92  void produceAndMixSample(FloatSample *&leftBuf, FloatSample *&rightBuf, LA32FloatPartialPair *la32FloatPair);
93 
94 public:
95  bool alreadyOutputed;
96 
97  Partial(Synth *synth, int debugPartialNum);
98  ~Partial();
99 
100  int debugGetPartialNum() const;
101  Bit32u debugGetSampleNum() const;
102 
103  int getOwnerPart() const;
104  const Poly *getPoly() const;
105  bool isActive() const;
106  void activate(int part);
107  void deactivate(void);
108  void startPartial(const Part *part, Poly *usePoly, const PatchCache *useCache, const MemParams::RhythmTemp *rhythmTemp, Partial *pairPartial);
109  void startAbort();
110  void startDecayAll();
111  bool shouldReverb();
112  bool isRingModulatingNoMix() const;
113  bool hasRingModulatingSlave() const;
114  bool isRingModulatingSlave() const;
115  bool isPCM() const;
116  const ControlROMPCMStruct *getControlROMPCMStruct() const;
117  Synth *getSynth() const;
118  TVA *getTVA() const;
119 
120  void backupCache(const PatchCache &cache);
121 
122  // Returns true only if data written to buffer
123  // These functions produce processed stereo samples
124  // made from combining this single partial with its pair, if it has one.
125  bool produceOutput(IntSample *leftBuf, IntSample *rightBuf, Bit32u length);
126  bool produceOutput(FloatSample *leftBuf, FloatSample *rightBuf, Bit32u length);
127 }; // class Partial
128 
129 } // namespace MT32Emu
130 
131 #endif // #ifndef MT32EMU_PARTIAL_H
Definition: LA32WaveGenerator.h:230
Definition: LA32WaveGenerator.h:206
Definition: Analog.h:26
Definition: Structures.h:231
Definition: TVP.h:30
Definition: Structures.h:238
Definition: Partial.h:40
Definition: TVA.h:62
Definition: Structures.h:246
Definition: Synth.h:131
Definition: LA32Ramp.h:26
Definition: Poly.h:30
Definition: TVF.h:30
Definition: Structures.h:143
Definition: LA32FloatWaveGenerator.h:97
Definition: Part.h:47