Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef MARSYAS_BLITOSC_H 00020 #define MARSYAS_BLITOSC_H 00021 00022 #include <marsyas/system/MarSystem.h> 00023 00024 namespace Marsyas 00025 { 00046 class BlitOsc: public MarSystem 00047 { 00048 private: 00049 00050 class LeakyIntegrator 00051 { 00052 private: 00053 mrs_real y1; 00054 mrs_real le; 00055 public: 00056 LeakyIntegrator() : le(0.005) { } 00057 00058 void set_le_amount(mrs_real l) 00059 { 00060 le = l; 00061 } 00062 00063 mrs_real operator()(mrs_real x) 00064 { 00065 mrs_real y = x + ((1 - le) * y1); 00066 y1 = y; 00067 return y; 00068 } 00069 }; 00070 00071 class Allpass 00072 { 00073 private: 00074 mrs_real x1; 00075 mrs_real x2; 00076 mrs_real y1; 00077 mrs_real y2; 00078 mrs_real a1; 00079 mrs_real a2; 00080 mrs_real d; 00081 public: 00082 00083 void set_delay(mrs_real d) 00084 { 00085 a1 = -2 * ((d - 2) / (d + 1)); 00086 a2 = ((d - 1)*(d - 2))/((d + 1)*(d + 2)); 00087 x1 = 0; 00088 x2 = 0; 00089 y1 = 0; 00090 y2 = 0; 00091 } 00092 00093 mrs_real operator()(mrs_real x) 00094 { 00095 mrs_real y = (a2 * x) + (a1 * x1) + (x2) - (a1 * y1) - (a2 * y2); 00096 x2 = x1; 00097 x1 = x; 00098 y2 = y1; 00099 y1 = y; 00100 return y; 00101 } 00102 }; 00103 00104 //Add specific controls needed by this MarSystem. 00105 void addControls(); 00106 void myUpdate(MarControlPtr sender); 00107 00108 mrs_real frequency_; // the oscillator frequency 00109 mrs_real israte_; // sample rate of the system 00110 mrs_bool noteon_; // is our note on? 00111 mrs_natural phase_; // the current phase 00112 mrs_natural N_; // the maximum of the phase counter 00113 mrs_real delay_; // The delay of the Allpass filter 00114 mrs_real dc_; // The DC offset for the saw form 00115 mrs_real inv_; // Used to create a bipolar impulse train for square form 00116 mrs_natural type_; // The oscillator type 00117 00118 mrs_real frac_; 00119 00120 Allpass ap1; // The Tuning filter 00121 Allpass ap2; // The antialiasing filter 00122 LeakyIntegrator le; 00123 00124 public: 00125 BlitOsc(std::string name); 00126 BlitOsc(const BlitOsc& a); 00127 ~BlitOsc(); 00128 MarSystem* clone() const; 00129 00130 void myProcess(realvec& in, realvec& out); 00131 }; 00132 00133 }//namespace Marsyas 00134 00135 #endif