voice.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // ---------------------------------------------------------------------------
  2. // This file is part of reSID, a MOS6581 SID emulator engine.
  3. // Copyright (C) 2004 Dag Lem <resid@nimrod.no>
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. // ---------------------------------------------------------------------------
  19. #ifndef __VOICE_H__
  20. #define __VOICE_H__
  21. #include "siddefs.h"
  22. #include "wave.h"
  23. #include "envelope.h"
  24. class Voice
  25. {
  26. public:
  27. Voice();
  28. void set_chip_model(chip_model model);
  29. void set_sync_source(Voice*);
  30. void reset();
  31. void writeCONTROL_REG(reg8);
  32. // Amplitude modulated waveform output.
  33. // Range [-2048*255, 2047*255].
  34. RESID_INLINE sound_sample output();
  35. protected:
  36. WaveformGenerator wave;
  37. EnvelopeGenerator envelope;
  38. // Waveform D/A zero level.
  39. sound_sample wave_zero;
  40. // Multiplying D/A DC offset.
  41. sound_sample voice_DC;
  42. friend class cSID;
  43. };
  44. // ----------------------------------------------------------------------------
  45. // Inline functions.
  46. // The following function is defined inline because it is called every
  47. // time a sample is calculated.
  48. // ----------------------------------------------------------------------------
  49. #if RESID_INLINING || defined(__VOICE_CC__)
  50. // ----------------------------------------------------------------------------
  51. // Amplitude modulated waveform output.
  52. // Ideal range [-2048*255, 2047*255].
  53. // ----------------------------------------------------------------------------
  54. RESID_INLINE
  55. sound_sample Voice::output()
  56. {
  57. // Multiply oscillator output with envelope output.
  58. return (wave.output() - wave_zero)*envelope.output() + voice_DC;
  59. }
  60. #endif // RESID_INLINING || defined(__VOICE_CC__)
  61. #endif // not __VOICE_H__