00001 /***************************************************************************
00002 modulator.cpp
00003 -----------
00004
00005 begin : Fri Sep 15 12:22:12 CEST 2000
00006 author : (C) 2000 by Michael Peeters
00007 email : Michael.Peeters@vub.ac.be
00008 ***************************************************************************/
00009
00010 /***************************************************************************
00011 * *
00012 * This program is free software; you can redistribute it and/or modify *
00013 * it under the terms of the GNU General Public License as published by *
00014 * the Free Software Foundation; either version 2 of the License, or *
00015 * (at your option) any later version. *
00016 * *
00017 ***************************************************************************/
00018
00019 #include "modulator.h"
00020
00021 namespace MODEL
00022 {
00023 number
00024 LinearMod::modulate()
00025 {
00026 time t=get_time();
00027
00028 if (t<f) return st;
00029 if ((t>f)&(t<u)) {
00030 time pos=(t-f)/du; // where in the period from 0 to 1 am I ?
00031 return st+d*pos;
00032 }
00033 if (t>u) {
00034 time pos=(t-f-u)/du;
00035 return en-d*pos;
00036 }
00037
00038 return en;
00039 }
00040
00041 number
00042 TriangleFadeMod::modulate()
00043 {
00044 // We have faded out
00045 if (st>en) return 0.;
00046
00047 time t=get_time();
00048 time dt=t-last_t;
00049 last_t=t;
00050
00051 in_t += dt;
00052
00053 // Not an easy task: first check if we crossed a timeperiod boundary
00054 // We assume this never happens twice in one timestep
00055 if ( in_t>= (s*p) )
00056 {
00057 in_t-=s*p;
00058 st +=dp;
00059 en -=dp;
00060 d=en-st;
00061 if (st>en) return 0.;
00062 }
00063
00064 time du=p/2.;
00065 time in_p = in_t-integer(in_t/p)*p;
00066
00067 if (in_p <= du) {
00068 time pos=in_p/du; // where in the period from 0 to 1 am I ?
00069 return st+d*pos;
00070 }
00071 if (in_p > du) {
00072 time pos=in_p/du - 1.;
00073 return en-d*pos;
00074 }
00075
00076 return 0.;
00077 }
00078
00079 number
00080 BlockMod::modulate(void)
00081 {
00082 time t=get_time();
00083
00084 time v=integer(t/p);
00085 time now=(t-p*v)/p;
00086
00087 if (now<0.5) return l;
00088 else return h;
00089 }
00090
00091 number StepMod::modulate()
00092 {
00093 time t=get_time();
00094 if (t<a) return st; else return en;
00095 }
00096
00097 } // end namespace
00098
00099 /*********************************************************************
00100 $Id: modulator.cpp,v 1.1 2001/05/22 10:54:55 mpeeters Exp $
00101 **********************************************************************
00102
00103 $Log: modulator.cpp,v $
00104 Revision 1.1 2001/05/22 10:54:55 mpeeters
00105 Moved sources and headers for libModel to model/ subdirectory, in an attempt to rationalize the source tree. This should make things "netter".
00106
00107 Revision 1.2 2000/09/15 10:26:31 mpeeters
00108 Cleaned out header and added CVS tails to files, removed superfuous
00109 @author comments, inserted dates
00110
00111 *********************************************************************/
More Info? Michael Peeters. Also, check our research website: www.alna.vub.ac.be
Last update: June 2002.