ScummVM API documentation
LA32FloatWaveGenerator.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_LA32_FLOAT_WAVE_GENERATOR_H
19 #define MT32EMU_LA32_FLOAT_WAVE_GENERATOR_H
20 
21 #include "globals.h"
22 #include "internals.h"
23 #include "Types.h"
24 #include "LA32WaveGenerator.h"
25 
26 namespace MT32Emu {
27 
37  //***************************************************************************
38  // The local copy of partial parameters below
39  //***************************************************************************
40 
41  bool active;
42 
43  // True means the resulting square wave is to be multiplied by the synchronous cosine
44  bool sawtoothWaveform;
45 
46  // Values in range [1..31]
47  // Value 1 correspong to the minimum resonance
48  Bit8u resonance;
49 
50  // Processed value in range [0..255]
51  // Values in range [0..128] have no effect and the resulting wave remains symmetrical
52  // Value 255 corresponds to the maximum possible asymmetric of the resulting wave
53  Bit8u pulseWidth;
54 
55  // Logarithmic PCM sample start address
56  const Bit16s *pcmWaveAddress;
57 
58  // Logarithmic PCM sample length
59  Bit32u pcmWaveLength;
60 
61  // true for looped logarithmic PCM samples
62  bool pcmWaveLooped;
63 
64  // false for slave PCM partials in the structures with the ring modulation
65  bool pcmWaveInterpolated;
66 
67  //***************************************************************************
68  // Internal variables below
69  //***************************************************************************
70 
71  float wavePos;
72  float lastFreq;
73  float pcmPosition;
74 
75  float getPCMSample(unsigned int position);
76 
77 public:
78  // Initialise the WG engine for generation of synth partial samples and set up the invariant parameters
79  void initSynth(const bool sawtoothWaveform, const Bit8u pulseWidth, const Bit8u resonance);
80 
81  // Initialise the WG engine for generation of PCM partial samples and set up the invariant parameters
82  void initPCM(const Bit16s * const pcmWaveAddress, const Bit32u pcmWaveLength, const bool pcmWaveLooped, const bool pcmWaveInterpolated);
83 
84  // Update parameters with respect to TVP, TVA and TVF, and generate next sample
85  float generateNextSample(const Bit32u amp, const Bit16u pitch, const Bit32u cutoff);
86 
87  // Deactivate the WG engine
88  void deactivate();
89 
90  // Return active state of the WG engine
91  bool isActive() const;
92 
93  // Return true if the WG engine generates PCM wave samples
94  bool isPCMWave() const;
95 }; // class LA32FloatWaveGenerator
96 
100  bool ringModulated;
101  bool mixed;
102  float masterOutputSample;
103  float slaveOutputSample;
104 
105 public:
106  // ringModulated should be set to false for the structures with mixing or stereo output
107  // ringModulated should be set to true for the structures with ring modulation
108  // mixed is used for the structures with ring modulation and indicates whether the master partial output is mixed to the ring modulator output
109  void init(const bool ringModulated, const bool mixed);
110 
111  // Initialise the WG engine for generation of synth partial samples and set up the invariant parameters
112  void initSynth(const PairType master, const bool sawtoothWaveform, const Bit8u pulseWidth, const Bit8u resonance);
113 
114  // Initialise the WG engine for generation of PCM partial samples and set up the invariant parameters
115  void initPCM(const PairType master, const Bit16s * const pcmWaveAddress, const Bit32u pcmWaveLength, const bool pcmWaveLooped);
116 
117  // Update parameters with respect to TVP, TVA and TVF, and generate next sample
118  void generateNextSample(const PairType master, const Bit32u amp, const Bit16u pitch, const Bit32u cutoff);
119 
120  // Perform mixing / ring modulation and return the result
121  float nextOutSample();
122 
123  // Deactivate the WG engine
124  void deactivate(const PairType master);
125 
126  // Return active state of the WG engine
127  bool isActive(const PairType master) const;
128 }; // class LA32FloatPartialPair
129 
130 } // namespace MT32Emu
131 
132 #endif // #ifndef MT32EMU_LA32_FLOAT_WAVE_GENERATOR_H
Definition: LA32WaveGenerator.h:206
Definition: Analog.h:26
Definition: LA32FloatWaveGenerator.h:97
Definition: LA32FloatWaveGenerator.h:36