DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/reSID/voice.h
00001 //  ---------------------------------------------------------------------------
00002 //  This file is part of reSID, a MOS6581 SID emulator engine.
00003 //  Copyright (C) 2004  Dag Lem <resid@nimrod.no>
00004 //
00005 //  This program is free software; you can redistribute it and/or modify
00006 //  it under the terms of the GNU General Public License as published by
00007 //  the Free Software Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //
00010 //  This program is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //  GNU General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU General Public License along
00016 //  with this program; if not, write to the Free Software Foundation, Inc.,
00017 //  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 //  ---------------------------------------------------------------------------
00019 
00020 #ifndef __VOICE_H__
00021 #define __VOICE_H__
00022 
00023 #include "siddefs.h"
00024 #include "wave.h"
00025 #include "envelope.h"
00026 
00027 class Voice
00028 {
00029 public:
00030   Voice();
00031 
00032   void set_chip_model(chip_model model);
00033   void set_sync_source(Voice*);
00034   void reset();
00035 
00036   void writeCONTROL_REG(reg8);
00037 
00038   // Amplitude modulated waveform output.
00039   // Range [-2048*255, 2047*255].
00040   RESID_INLINE sound_sample output();
00041 
00042         void SaveState( std::ostream& stream );
00043         void LoadState( std::istream& stream );
00044 
00045 protected:
00046   WaveformGenerator wave;
00047   EnvelopeGenerator envelope;
00048 
00049   // Waveform D/A zero level.
00050   sound_sample wave_zero;
00051 
00052   // Multiplying D/A DC offset.
00053   sound_sample voice_DC;
00054 
00055 friend class SID2;
00056 };
00057 
00058 
00059 // ----------------------------------------------------------------------------
00060 // Inline functions.
00061 // The following function is defined inline because it is called every
00062 // time a sample is calculated.
00063 // ----------------------------------------------------------------------------
00064 
00065 #if RESID_INLINING || defined(__VOICE_CC__)
00066 
00067 // ----------------------------------------------------------------------------
00068 // Amplitude modulated waveform output.
00069 // Ideal range [-2048*255, 2047*255].
00070 // ----------------------------------------------------------------------------
00071 RESID_INLINE
00072 sound_sample Voice::output()
00073 {
00074   // Multiply oscillator output with envelope output.
00075   return ((sound_sample)wave.output() - (sound_sample)wave_zero)*(sound_sample)envelope.output() + (sound_sample)voice_DC;
00076 }
00077 
00078 #endif // RESID_INLINING || defined(__VOICE_CC__)
00079 
00080 #endif // not __VOICE_H__