|
Loris 1.5
|
00001 #ifndef INCLUDE_LINEARENVELOPE_H 00002 #define INCLUDE_LINEARENVELOPE_H 00003 /* 00004 * This is the Loris C++ Class Library, implementing analysis, 00005 * manipulation, and synthesis of digitized sounds using the Reassigned 00006 * Bandwidth-Enhanced Additive Sound Model. 00007 * 00008 * Loris is Copyright (c) 1999-2010 by Kelly Fitz and Lippold Haken 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY, without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 * 00024 * 00025 * LinearEnvelope.h 00026 * 00027 * Definition of class LinearEnvelope. 00028 * 00029 * Kelly Fitz, 23 April 2005 00030 * loris@cerlsoundgroup.org 00031 * 00032 * http://www.cerlsoundgroup.org/Loris/ 00033 * 00034 */ 00035 00036 #include "Envelope.h" 00037 #include <map> 00038 00039 // begin namespace 00040 namespace Loris { 00041 00042 // --------------------------------------------------------------------------- 00043 // class LinearEnvelope 00044 // 00068 // 00069 class LinearEnvelope : public Envelope, private std::map< double, double > 00070 { 00071 // -- public interface -- 00072 public: 00073 // -- construction -- 00074 00077 LinearEnvelope( void ); 00078 00085 explicit LinearEnvelope( double initialValue ); 00086 00087 // compiler-generated copy, assignment, and destruction are OK. 00088 00089 // -- Envelope interface -- 00090 00093 virtual LinearEnvelope * clone( void ) const; 00094 00100 virtual double valueAt( double t ) const; 00101 00102 00103 // -- envelope composition -- 00104 00112 void insert( double time, double value ); 00113 00120 void insertBreakpoint( double time, double value ) 00121 { insert( time, value ); } 00122 00123 00128 LinearEnvelope & operator+=( double offset ); 00129 00134 LinearEnvelope & operator-=( double offset ) 00135 { 00136 return operator+=( -offset ); 00137 } 00138 00144 LinearEnvelope & operator*=( double scale ); 00145 00151 LinearEnvelope & operator/=( double div ) 00152 { 00153 return operator*=( 1.0 / div ); 00154 } 00155 00156 // -- interface inherited from std::map -- 00157 00158 using std::map< double, double >::size; 00159 using std::map< double, double >::empty; 00160 using std::map< double, double >::clear; 00161 using std::map< double, double >::begin; 00162 using std::map< double, double >::end; 00163 using std::map< double, double >::size_type; 00164 using std::map< double, double >::value_type; 00165 using std::map< double, double >::iterator; 00166 using std::map< double, double >::const_iterator; 00167 00168 }; // end of class LinearEnvelope 00169 00170 00171 // -- binary operators (inline nonmembers) -- 00172 00175 inline 00176 LinearEnvelope operator+( LinearEnvelope env, double offset ) 00177 { 00178 env += offset; 00179 return env; 00180 } 00181 00184 inline 00185 LinearEnvelope operator+( double offset, LinearEnvelope env ) 00186 { 00187 env += offset; 00188 return env; 00189 } 00190 00192 inline 00193 LinearEnvelope operator+( const LinearEnvelope & e1, const LinearEnvelope & e2 ) 00194 { 00195 LinearEnvelope ret; 00196 00197 // For each breakpoint in e1, insert a breakpoint having a value 00198 // equal to the sum of the two envelopes at that time. 00199 for ( LinearEnvelope::const_iterator it = e1.begin(); it != e1.end(); ++it ) 00200 { 00201 double t = it->first; 00202 double v = it->second; 00203 00204 ret.insert( t, v + e2.valueAt( t ) ); 00205 } 00206 00207 // For each breakpoint in e2, insert a breakpoint having a value 00208 // equal to the sum of the two envelopes at that time. 00209 for ( LinearEnvelope::const_iterator it = e2.begin(); it != e2.end(); ++it ) 00210 { 00211 double t = it->first; 00212 double v = it->second; 00213 00214 ret.insert( t, v + e1.valueAt( t ) ); 00215 } 00216 00217 return ret; 00218 } 00219 00222 inline 00223 LinearEnvelope operator-( LinearEnvelope env, double offset ) 00224 { 00225 env -= offset; 00226 return env; 00227 } 00228 00231 inline 00232 LinearEnvelope operator-( double offset, LinearEnvelope env ) 00233 { 00234 env *= -1.0; 00235 env += offset; 00236 return env; 00237 } 00238 00240 inline 00241 LinearEnvelope operator-( const LinearEnvelope & e1, const LinearEnvelope & e2 ) 00242 { 00243 LinearEnvelope ret; 00244 00245 // For each breakpoint in e1, insert a breakpoint having a value 00246 // equal to the difference between the two envelopes at that time. 00247 for ( LinearEnvelope::const_iterator it = e1.begin(); it != e1.end(); ++it ) 00248 { 00249 double t = it->first; 00250 double v = it->second; 00251 00252 ret.insert( t, v - e2.valueAt( t ) ); 00253 } 00254 00255 // For each breakpoint in e2, insert a breakpoint having a value 00256 // equal to the difference between the two envelopes at that time. 00257 for ( LinearEnvelope::const_iterator it = e2.begin(); it != e2.end(); ++it ) 00258 { 00259 double t = it->first; 00260 double v = it->second; 00261 00262 ret.insert( t, e1.valueAt( t ) - v ); 00263 } 00264 00265 return ret; 00266 } 00267 00270 inline 00271 LinearEnvelope operator*( LinearEnvelope env, double scale ) 00272 { 00273 env *= scale; 00274 return env; 00275 } 00276 00279 inline 00280 LinearEnvelope operator*( double scale, LinearEnvelope env ) 00281 { 00282 env *= scale; 00283 return env; 00284 } 00285 00288 inline 00289 LinearEnvelope operator/( LinearEnvelope env, double div ) 00290 { 00291 env /= div; 00292 return env; 00293 } 00294 00298 LinearEnvelope operator/( double scale, LinearEnvelope env ); 00299 00300 00301 } // end of namespace Loris 00302 00303 #endif /* ndef INCLUDE_LINEARENVELOPE_H */