wavetable.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 1983-2013 Richard Dobson and Composers Desktop Project Ltd
  3. * http://people.bath.ac.uk/masrwd
  4. * http://www.composersdesktop.com
  5. * This file is part of the CDP System.
  6. * The CDP System is free software; you can redistribute it
  7. * and/or modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * The CDP System is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. * See the GNU Lesser General Public License for more details.
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with the CDP System; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. // wavetable.h: interface for the fast_lfo class.
  21. // Feb 2009 added gaussian option to random
  22. //FWD 3.20: eliminate warning of unused private var (phsmask)
  23. //////////////////////////////////////////////////////////////////////
  24. #if !defined(AFX_WAVETABLE_H__2F961225_3FF4_11D2_96D4_444553540000__INCLUDED_)
  25. #define AFX_WAVETABLE_H__2F961225_3FF4_11D2_96D4_444553540000__INCLUDED_
  26. #if _MSC_VER >= 1000
  27. #pragma once
  28. #endif // _MSC_VER >= 1000
  29. typedef enum lfowavetype {LFO_SINE,LFO_TRIANGLE,LFO_SAWUP,LFO_SAWDOWN,LFO_SQUARE,LFO_RANDOM,LFO_RND_SH,
  30. LFO_RAND_TPDF,LFO_RAND_GAUSS,LFO_RAND_EXP, LFO_RANDH_TPDF,
  31. /*LFO_RANDH_GAUSS,LFO_RANDH_EXP, */
  32. LFO_NUM_WAVES } LfoWaveType;
  33. enum {PVS_LFO_FREQ_LORANGE, PVS_LFO_FREQ_HIRANGE};
  34. typedef struct lfoparam
  35. {
  36. double freq;
  37. double modrange;
  38. } LfoParam;
  39. class fastlfo {
  40. typedef double (fastlfo:: *tickfunc)(void);
  41. public:
  42. fastlfo();
  43. virtual ~fastlfo() {}
  44. long init(double srate, double normphase = 0.0,long seedval = 0,unsigned long ksmps = 1);
  45. double tick(void) { return (this->*tf)(); }
  46. tickfunc tf;
  47. void set_freq(double freq) { param.freq = freq; }
  48. double get_freq(void) const { return param.freq; }
  49. void set_mod(double mod) { param.modrange = mod; }
  50. double get_mod(void) const { return param.modrange;}
  51. void reset(double phase);
  52. bool set_WaveType(LfoWaveType type);
  53. void set_tpdf() { tpdf = true; gauss = biexp = false;}
  54. void set_white() { tpdf = gauss = biexp = false;}
  55. void set_biexp() { tpdf = gauss = false; biexp = true;}
  56. void set_flat() { tpdf = gauss = biexp = false;}
  57. void set_gaussian() { tpdf = biexp = false; gauss = true;}
  58. void sync_phase(double phase, double offset, double phaseincr);
  59. void set_sync(bool onoff) { b_sync = onoff;}
  60. double csrand();
  61. private:
  62. double sinetick(void);
  63. double tritick(void);
  64. double squaretick(void);
  65. double sawuptick(void);
  66. double sawdowntick(void);
  67. double randomtick(void);
  68. double randhtick(void);
  69. double rand_tpdf_tick(void);
  70. double rand_gauss_tick(void);
  71. double rand_exp_tick(void);
  72. double randh_tpdf_tick(void);
  73. // double randh_gauss_tick(void);
  74. // double randh_exp_tick(void);
  75. long randint31(long seed31);
  76. double m_srate, m_inv_srate;
  77. double twopiovrsr;
  78. double curfreq;
  79. double curphase;
  80. double incr;
  81. LfoParam param;
  82. LfoWaveType m_cur_WaveType;
  83. /* vars for random oscs, with a little help from Csound!*/
  84. long phs;
  85. long kicvt;
  86. // long phsmask; // currently not used
  87. long rand;
  88. double num1,num2;
  89. double dfdmax;
  90. /* for krate output */
  91. unsigned long ksamps;
  92. unsigned long kcount;
  93. double lastval;
  94. bool tpdf;
  95. bool gauss;
  96. bool biexp;
  97. // for lfo sync
  98. bool b_sync;
  99. double offset;
  100. // for random oscs
  101. long curphs;
  102. long phs_incr;
  103. long phs_offset;
  104. /* for csrand */
  105. long csseed;
  106. };
  107. #endif // !defined(AFX_WAVETABLE_H__2F961225_3FF4_11D2_96D4_444553540000__INCLUDED_)