libsidplayfp  2.12.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 "siddefs-fp.h"
27 #include "WaveformGenerator.h"
28 #include "EnvelopeGenerator.h"
29 
30 namespace reSIDfp
31 {
32 
36 class Voice
37 {
38 private:
39  WaveformGenerator waveformGenerator;
40 
41  EnvelopeGenerator envelopeGenerator;
42 
44  float* wavDAC; //-V730_NOINIT this is initialized in the SID constructor
45 
47  float* envDAC; //-V730_NOINIT this is initialized in the SID constructor
48 
49 public:
65  RESID_INLINE
66  float output(const WaveformGenerator* ringModulator)
67  {
68  unsigned int const wav = waveformGenerator.output(ringModulator);
69  unsigned int const env = envelopeGenerator.output();
70 
71  // DAC imperfections are emulated by using the digital output
72  // as an index into a DAC lookup table.
73  return wavDAC[wav] * envDAC[env];
74  }
75 
82  void setWavDAC(float* dac) { wavDAC = dac; }
83 
90  void setEnvDAC(float* dac) { envDAC = dac; }
91 
92  WaveformGenerator* wave() { return &waveformGenerator; }
93 
94  EnvelopeGenerator* envelope() { return &envelopeGenerator; }
95 
101  void writeCONTROL_REG(unsigned char control)
102  {
103  waveformGenerator.writeCONTROL_REG(control);
104  envelopeGenerator.writeCONTROL_REG(control);
105  }
106 
110  void reset()
111  {
112  waveformGenerator.reset();
113  envelopeGenerator.reset();
114  }
115 };
116 
117 } // namespace reSIDfp
118 
119 #endif
Definition: EnvelopeGenerator.h:44
unsigned int output() const
Definition: EnvelopeGenerator.h:130
void reset()
Definition: EnvelopeGenerator.cpp:62
void writeCONTROL_REG(unsigned char control)
Definition: EnvelopeGenerator.cpp:87
Definition: Voice.h:37
RESID_INLINE float output(const WaveformGenerator *ringModulator)
Definition: Voice.h:66
void writeCONTROL_REG(unsigned char control)
Definition: Voice.h:101
void reset()
Definition: Voice.h:110
void setEnvDAC(float *dac)
Definition: Voice.h:90
void setWavDAC(float *dac)
Definition: Voice.h:82
Definition: WaveformGenerator.h:94
unsigned int output(const WaveformGenerator *ringModulator)
Definition: WaveformGenerator.h:344
void writeCONTROL_REG(unsigned char control)
Definition: WaveformGenerator.cpp:354
void reset()
Definition: WaveformGenerator.cpp:453