libsidplayfp  2.4.0
Voice.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2022 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright 2004 Dag Lem <resid@nimrod.no>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef VOICE_H
24 #define VOICE_H
25 
26 #include <memory>
27 
28 #include "siddefs-fp.h"
29 #include "WaveformGenerator.h"
30 #include "EnvelopeGenerator.h"
31 
32 #include "sidcxx11.h"
33 
34 namespace reSIDfp
35 {
36 
40 class Voice
41 {
42 private:
43  std::unique_ptr<WaveformGenerator> const waveformGenerator;
44 
45  std::unique_ptr<EnvelopeGenerator> const envelopeGenerator;
46 
48  float* wavDAC; //-V730_NOINIT this is initialized in the SID constructor
49 
51  float* envDAC; //-V730_NOINIT this is initialized in the SID constructor
52 
53 public:
69  RESID_INLINE
70  int output(const WaveformGenerator* ringModulator) const
71  {
72  unsigned int const wav = waveformGenerator->output(ringModulator);
73  unsigned int const env = envelopeGenerator->output();
74 
75  // DAC imperfections are emulated by using the digital output
76  // as an index into a DAC lookup table.
77  return static_cast<int>(wavDAC[wav] * envDAC[env]);
78  }
79 
83  Voice() :
84  waveformGenerator(new WaveformGenerator()),
85  envelopeGenerator(new EnvelopeGenerator()) {}
86 
93  void setWavDAC(float* dac) { wavDAC = dac; }
94 
101  void setEnvDAC(float* dac) { envDAC = dac; }
102 
103  WaveformGenerator* wave() const { return waveformGenerator.get(); }
104 
105  EnvelopeGenerator* envelope() const { return envelopeGenerator.get(); }
106 
112  void writeCONTROL_REG(unsigned char control)
113  {
114  waveformGenerator->writeCONTROL_REG(control);
115  envelopeGenerator->writeCONTROL_REG(control);
116  }
117 
121  void reset()
122  {
123  waveformGenerator->reset();
124  envelopeGenerator->reset();
125  }
126 };
127 
128 } // namespace reSIDfp
129 
130 #endif
Definition: EnvelopeGenerator.h:44
Definition: Voice.h:41
Voice()
Definition: Voice.h:83
void writeCONTROL_REG(unsigned char control)
Definition: Voice.h:112
void reset()
Definition: Voice.h:121
void setEnvDAC(float *dac)
Definition: Voice.h:101
void setWavDAC(float *dac)
Definition: Voice.h:93
RESID_INLINE int output(const WaveformGenerator *ringModulator) const
Definition: Voice.h:70
Definition: WaveformGenerator.h:87