Voice.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2022 Leandro Nini <drfiemost@users.sourceforge.net>
* Copyright 2007-2010 Antti Lankila
* Copyright 2004 Dag Lem <resid@nimrod.no>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef VOICE_H
#define VOICE_H
#include <memory>
#include "siddefs-fp.h"
#include "WaveformGenerator.h"
#include "EnvelopeGenerator.h"
#include "sidcxx11.h"
namespace reSIDfp
{
class Voice
{
private:
std::unique_ptr<WaveformGenerator> const waveformGenerator;
std::unique_ptr<EnvelopeGenerator> const envelopeGenerator;
float* wavDAC; //-V730_NOINIT this is initialized in the SID constructor
float* envDAC; //-V730_NOINIT this is initialized in the SID constructor
public:
RESID_INLINE
int output(const WaveformGenerator* ringModulator) const
{
unsigned int const wav = waveformGenerator->output(ringModulator);
unsigned int const env = envelopeGenerator->output();
// DAC imperfections are emulated by using the digital output
// as an index into a DAC lookup table.
return static_cast<int>(wavDAC[wav] * envDAC[env]);
}
Voice() :
waveformGenerator(new WaveformGenerator()),
envelopeGenerator(new EnvelopeGenerator()) {}
void setWavDAC(float* dac) { wavDAC = dac; }
void setEnvDAC(float* dac) { envDAC = dac; }
WaveformGenerator* wave() const { return waveformGenerator.get(); }
EnvelopeGenerator* envelope() const { return envelopeGenerator.get(); }
void writeCONTROL_REG(unsigned char control)
{
waveformGenerator->writeCONTROL_REG(control);
envelopeGenerator->writeCONTROL_REG(control);
}
void reset()
{
waveformGenerator->reset();
envelopeGenerator->reset();
}
};
} // namespace reSIDfp
#endif
reSIDfp::EnvelopeGenerator
Definition EnvelopeGenerator.h:44
reSIDfp::Voice
Definition Voice.h:41
reSIDfp::Voice::Voice
Voice()
Definition Voice.h:83
reSIDfp::Voice::writeCONTROL_REG
void writeCONTROL_REG(unsigned char control)
Definition Voice.h:112
reSIDfp::Voice::reset
void reset()
Definition Voice.h:121
reSIDfp::Voice::setEnvDAC
void setEnvDAC(float *dac)
Definition Voice.h:101
reSIDfp::Voice::setWavDAC
void setWavDAC(float *dac)
Definition Voice.h:93
reSIDfp::Voice::output
RESID_INLINE int output(const WaveformGenerator *ringModulator) const
Definition Voice.h:70
reSIDfp::WaveformGenerator
Definition WaveformGenerator.h:94