libsidplayfp 2.15.0
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
30namespace reSIDfp
31{
32
36class Voice
37{
38private:
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
49public:
64 RESID_INLINE
65 float output()
66 {
67 unsigned int const wav = waveformGenerator.output();
68 unsigned int const env = envelopeGenerator.output();
69
70 // DAC imperfections are emulated by using the digital output
71 // as an index into a DAC lookup table.
72 return wavDAC[wav] * envDAC[env];
73 }
74
81 void setWavDAC(float* dac) { wavDAC = dac; }
82
89 void setEnvDAC(float* dac) { envDAC = dac; }
90
96 void setOtherVoices(Voice& prev, Voice& next)
97 {
98 waveformGenerator.setOtherWaveforms(prev.wave(), next.wave());
99 }
100
101 WaveformGenerator* wave() { return &waveformGenerator; }
102
103 EnvelopeGenerator* envelope() { return &envelopeGenerator; }
104
110 void writeCONTROL_REG(unsigned char control)
111 {
112 waveformGenerator.writeCONTROL_REG(control);
113 envelopeGenerator.writeCONTROL_REG(control);
114 }
115
119 void reset()
120 {
121 waveformGenerator.reset();
122 envelopeGenerator.reset();
123 }
124};
125
126} // namespace reSIDfp
127
128#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
void writeCONTROL_REG(unsigned char control)
Definition Voice.h:110
void reset()
Definition Voice.h:119
void setEnvDAC(float *dac)
Definition Voice.h:89
RESID_INLINE float output()
Definition Voice.h:65
void setWavDAC(float *dac)
Definition Voice.h:81
void setOtherVoices(Voice &prev, Voice &next)
Definition Voice.h:96
Definition WaveformGenerator.h:94
void writeCONTROL_REG(unsigned char control)
Definition WaveformGenerator.cpp:354
unsigned int output()
Definition WaveformGenerator.h:352
void reset()
Definition WaveformGenerator.cpp:453