ScummVM API documentation
TVA.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_TVA_H
19 #define MT32EMU_TVA_H
20 
21 #include "globals.h"
22 #include "Types.h"
23 #include "Structures.h"
24 
25 namespace MT32Emu {
26 
27 class LA32Ramp;
28 class Part;
29 class Partial;
30 
31 // Note that when entering nextPhase(), newPhase is set to phase + 1, and the descriptions/names below refer to
32 // newPhase's value.
33 enum {
34  // In this phase, the base amp (as calculated in calcBasicAmp()) is targeted with an instant time.
35  // This phase is entered by reset() only if time[0] != 0.
36  TVA_PHASE_BASIC = 0,
37 
38  // In this phase, level[0] is targeted within time[0], and velocity potentially affects time
39  TVA_PHASE_ATTACK = 1,
40 
41  // In this phase, level[1] is targeted within time[1]
42  TVA_PHASE_2 = 2,
43 
44  // In this phase, level[2] is targeted within time[2]
45  TVA_PHASE_3 = 3,
46 
47  // In this phase, level[3] is targeted within time[3]
48  TVA_PHASE_4 = 4,
49 
50  // In this phase, immediately goes to PHASE_RELEASE unless the poly is set to sustain.
51  // Aborts the partial if level[3] is 0.
52  // Otherwise level[3] is continued, no phase change will occur until some external influence (like pedal release)
53  TVA_PHASE_SUSTAIN = 5,
54 
55  // In this phase, 0 is targeted within time[4] (the time calculation is quite different from the other phases)
56  TVA_PHASE_RELEASE = 6,
57 
58  // It's PHASE_DEAD, Jim.
59  TVA_PHASE_DEAD = 7
60 };
61 
62 class TVA {
63 private:
64  const Partial * const partial;
65  LA32Ramp *ampRamp;
66  const MemParams::System * const system;
67 
68  const Part *part;
69  const TimbreParam::PartialParam *partialParam;
70  const MemParams::RhythmTemp *rhythmTemp;
71 
72  bool playing;
73 
74  int biasAmpSubtraction;
75  int veloAmpSubtraction;
76  int keyTimeSubtraction;
77 
78  Bit8u target;
79  int phase;
80 
81  void startRamp(Bit8u newTarget, Bit8u newIncrement, int newPhase);
82  void end(int newPhase);
83  void nextPhase();
84 
85 public:
86  TVA(const Partial *partial, LA32Ramp *ampRamp);
87  void reset(const Part *part, const TimbreParam::PartialParam *partialParam, const MemParams::RhythmTemp *rhythmTemp);
88  void handleInterrupt();
89  void recalcSustain();
90  void startDecay();
91  void startAbort();
92 
93  bool isPlaying() const;
94  int getPhase() const;
95 }; // class TVA
96 
97 } // namespace MT32Emu
98 
99 #endif // #ifndef MT32EMU_TVA_H
Definition: Analog.h:26
Definition: Partial.h:40
Definition: TVA.h:62
Definition: Structures.h:160
Definition: LA32Ramp.h:26
Definition: Structures.h:143
Definition: Part.h:47
Definition: Structures.h:56