libsidplayfp  2.0.2
Voice.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2015 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 
47 public:
62  RESID_INLINE
63  int output(const WaveformGenerator* ringModulator) const
64  {
65  return static_cast<int>(waveformGenerator->output(ringModulator) * envelopeGenerator->output());
66  }
67 
71  Voice() :
72  waveformGenerator(new WaveformGenerator()),
73  envelopeGenerator(new EnvelopeGenerator()) {}
74 
75  WaveformGenerator* wave() const { return waveformGenerator.get(); }
76 
77  EnvelopeGenerator* envelope() const { return envelopeGenerator.get(); }
78 
84  void writeCONTROL_REG(unsigned char control)
85  {
86  waveformGenerator->writeCONTROL_REG(control);
87  envelopeGenerator->writeCONTROL_REG(control);
88  }
89 
93  void reset()
94  {
95  waveformGenerator->reset();
96  envelopeGenerator->reset();
97  }
98 };
99 
100 } // namespace reSIDfp
101 
102 #endif
reSIDfp::Voice::Voice
Voice()
Definition: Voice.h:71
reSIDfp::Voice::reset
void reset()
Definition: Voice.h:93
reSIDfp::Voice::output
RESID_INLINE int output(const WaveformGenerator *ringModulator) const
Definition: Voice.h:63
reSIDfp::Voice
Definition: Voice.h:41
reSIDfp::Voice::writeCONTROL_REG
void writeCONTROL_REG(unsigned char control)
Definition: Voice.h:84
reSIDfp::EnvelopeGenerator
Definition: EnvelopeGenerator.h:44
reSIDfp::WaveformGenerator
Definition: WaveformGenerator.h:87