libresidfp  1.2.3
Voice.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2025 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 #include <cstdint>
31 
32 namespace reSIDfp
33 {
34 
38 class Voice
39 {
40 private:
41  WaveformGenerator waveformGenerator;
42 
43  EnvelopeGenerator envelopeGenerator;
44 
46  float* wavDAC; //-V730_NOINIT this is initialized in the SID constructor
47 
49  float* envDAC; //-V730_NOINIT this is initialized in the SID constructor
50 
51 public:
66  RESIDFP_INLINE
67  float output()
68  {
69  uint32_t wav = waveformGenerator.output();
70  int env = envelopeGenerator.output();
71 
72  // DAC imperfections are emulated by using the digital output
73  // as an index into a DAC lookup table.
74  return wavDAC[wav] * envDAC[env];
75  }
76 
83  void setWavDAC(float* dac) { wavDAC = dac; }
84 
91  void setEnvDAC(float* dac) { envDAC = dac; }
92 
98  void setOtherVoices(Voice& prev, Voice& next)
99  {
100  waveformGenerator.setOtherWaveforms(prev.wave(), next.wave());
101  }
102 
103  WaveformGenerator* wave() { return &waveformGenerator; }
104 
105  EnvelopeGenerator* envelope() { return &envelopeGenerator; }
106 
107  const WaveformGenerator* wave() const { return &waveformGenerator; }
108 
109  const EnvelopeGenerator* envelope() const { return &envelopeGenerator; }
110 
116  void writeCONTROL_REG(uint8_t control)
117  {
118  waveformGenerator.writeCONTROL_REG(control);
119  envelopeGenerator.writeCONTROL_REG(control);
120  }
121 
125  void reset()
126  {
127  waveformGenerator.reset();
128  envelopeGenerator.reset();
129  }
130 };
131 
132 } // namespace reSIDfp
133 
134 #endif
void writeCONTROL_REG(uint8_t control)
Definition: Voice.h:116
Definition: Voice.h:38
void writeCONTROL_REG(uint8_t control)
Definition: EnvelopeGenerator.cpp:87
void reset()
Definition: EnvelopeGenerator.cpp:62
Definition: Dac.cpp:27
uint8_t output() const
Definition: EnvelopeGenerator.h:134
void setOtherVoices(Voice &prev, Voice &next)
Definition: Voice.h:98
uint32_t output()
Definition: WaveformGenerator.h:380
RESIDFP_INLINE float output()
Definition: Voice.h:67
void setWavDAC(float *dac)
Definition: Voice.h:83
void reset()
Definition: Voice.h:125
Definition: EnvelopeGenerator.h:45
void writeCONTROL_REG(uint8_t control)
Definition: WaveformGenerator.cpp:354
void reset()
Definition: WaveformGenerator.cpp:431
void setEnvDAC(float *dac)
Definition: Voice.h:91
Definition: WaveformGenerator.h:91