Loris 1.5

Envelope.h

00001 #ifndef INCLUDE_ENVELOPE_H
00002 #define INCLUDE_ENVELOPE_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  * Envelope.h
00026  *
00027  * Definition of abstract interface class Envelope.
00028  *
00029  * Kelly Fitz, 21 July 2000
00030  * loris@cerlsoundgroup.org
00031  *
00032  * http://www.cerlsoundgroup.org/Loris/
00033  *
00034  */
00035 
00036 #include <memory>   //   for autoptr
00037 
00038 //  begin namespace
00039 namespace Loris {
00040 
00041 // ---------------------------------------------------------------------------
00042 //  class Envelope
00043 //
00056 //
00057 class Envelope
00058 {
00059 //  -- public interface --
00060 public:
00061 //  -- construction --
00062 
00063     // allow compiler to generate constructors
00064 
00066     virtual ~Envelope( void );
00067 
00068 //  -- Envelope interface --
00069 
00072     virtual Envelope * clone( void ) const = 0;
00073 
00075     virtual double valueAt( double x ) const = 0;   
00076     
00077 };  //  end of abstract class Envelope
00078 
00079 
00080 // ---------------------------------------------------------------------------
00081 //  class ScaleAndOffsetEnvelope
00082 //
00085 
00086 class ScaleAndOffsetEnvelope : public Envelope
00087 {
00088 //  -- public interface --
00089 public:
00090 //  -- construction --
00091 
00094     ScaleAndOffsetEnvelope( const Envelope & e, double scale, double offset ) :
00095         m_env( e.clone() ),
00096         m_scale( scale ),
00097         m_offset( offset )
00098     {
00099     }
00100 
00102     ScaleAndOffsetEnvelope( const ScaleAndOffsetEnvelope & rhs ) :
00103         m_env( rhs.m_env->clone() ),
00104         m_scale( rhs.m_scale ),
00105         m_offset( rhs.m_offset )
00106     {
00107     }
00108 
00110     ScaleAndOffsetEnvelope & 
00111     operator=( const ScaleAndOffsetEnvelope & rhs )
00112     {
00113         if ( &rhs != this )
00114         {
00115             m_env.reset( rhs.m_env->clone() );
00116             m_scale = rhs.m_scale;
00117             m_offset = rhs.m_offset;
00118         }
00119         return *this;
00120     }
00121 
00122 //  -- Envelope interface --
00123 
00126     ScaleAndOffsetEnvelope * clone( void ) const 
00127     {
00128         return new ScaleAndOffsetEnvelope( *this );
00129     }
00130 
00132     virtual double valueAt( double x ) const
00133     {
00134         return m_offset + ( m_scale * m_env->valueAt( x ) );
00135     }
00136     
00137 //  -- private member variables --
00138 
00139 private:
00140 
00141     std::auto_ptr< Envelope > m_env;    
00142     double m_scale, m_offset;
00143     
00144 };  //  end of class ScaleAndOffsetEnvelope
00145 
00146 
00147 // ---------------------------------------------------------------------------
00148 //  math operators
00149 // ---------------------------------------------------------------------------
00150 
00151 inline
00152 ScaleAndOffsetEnvelope
00153 operator*( const Envelope & e, double x )
00154 {
00155     return ScaleAndOffsetEnvelope( e, x, 0 );
00156 }
00157 
00158 inline
00159 ScaleAndOffsetEnvelope
00160 operator*( double x, const Envelope & e )
00161 {
00162     return e * x;
00163 }
00164 
00165 
00166 
00167 
00168 }   //  end of namespace Loris
00169 
00170 #endif /* ndef INCLUDE_ENVELOPE_H */
 All Classes Functions Variables Typedefs Enumerator Friends