BreakpointUtils.h

00001 #ifndef INCLUDE_BREAKPOINTUTILS_H
00002 #define INCLUDE_BREAKPOINTUTILS_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-2007 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  * BreakpointUtils.h
00026  *
00027  * Breakpoint utility functions collected in namespace BreakpointUtils.
00028  *
00029  * Kelly Fitz, 6 July 2000
00030  * loris@cerlsoundgroup.org
00031  *
00032  * http://www.cerlsoundgroup.org/Loris/
00033  *
00034  */
00035 
00036 #include "Breakpoint.h"
00037 #include <algorithm>
00038 #include <functional>
00039 
00040 //  begin namespace
00041 namespace Loris {
00042 
00043 namespace BreakpointUtils {
00044 
00045 //  -- free functions --
00046 
00047 // ---------------------------------------------------------------------------
00048 //  addNoiseEnergy
00049 // ---------------------------------------------------------------------------
00057 //
00058 inline void addNoiseEnergy( Breakpoint & bp, double enoise ) 
00059 { 
00060     bp.addNoiseEnergy(enoise); 
00061 }
00062  
00063 // ---------------------------------------------------------------------------
00064 //  makeNullBefore
00065 // ---------------------------------------------------------------------------
00074 //
00075 Breakpoint makeNullBefore( const Breakpoint & bp, double fadeTime ); // see BreakpointUtils.C
00076 
00077 
00078 // ---------------------------------------------------------------------------
00079 //  addNoiseEnergy
00080 // ---------------------------------------------------------------------------
00089 //
00090 Breakpoint makeNullAfter( const Breakpoint & bp, double fadeTime ); // see BreakpointUtils.C
00091 
00092 //  -- predicates --
00093 
00094 // ---------------------------------------------------------------------------
00095 //  isFrequencyBetween
00096 //  
00099 //
00100 class isFrequencyBetween : 
00101     public std::unary_function< const Breakpoint, bool >
00102 {
00103 public:
00106     bool operator()( const Breakpoint & b )  const
00107     { 
00108         return (b.frequency() > _fmin) && 
00109                (b.frequency() < _fmax); 
00110     }
00111     
00112 //  constructor:
00113 
00115     isFrequencyBetween( double x, double y ) : 
00116         _fmin( x ), _fmax( y ) 
00117     { 
00118         if (x>y) std::swap(x,y); 
00119     }
00120         
00121 //  bounds:
00122 private:
00123     double _fmin, _fmax;
00124 };
00125 
00128 typedef isFrequencyBetween frequency_between;
00129 
00130 // ---------------------------------------------------------------------------
00131 //  isNonNull
00132 //
00135 //
00136 static bool isNonNull( const Breakpoint & bp )
00137 {
00138     return bp.amplitude() != 0.;
00139 }
00140 
00141 // ---------------------------------------------------------------------------
00142 //  isNull
00143 //
00146 //
00147 static bool isNull( const Breakpoint & bp )
00148 {
00149     return ! isNonNull( bp );
00150 }
00151 
00152 //  -- comparitors --
00153 
00154 // ---------------------------------------------------------------------------
00155 //  compareFrequencyLess
00156 //  
00160 //
00161 class compareFrequencyLess : 
00162     public std::binary_function< const Breakpoint, const Breakpoint, bool >
00163 {
00164 public:
00167     bool operator()( const Breakpoint & lhs, const Breakpoint & rhs ) const
00168         { return lhs.frequency() < rhs.frequency(); }
00169 };
00170 
00173 typedef compareFrequencyLess less_frequency;
00174 
00175 // ---------------------------------------------------------------------------
00176 //  compareAmplitudeGreater
00177 //  
00181 //
00182 class compareAmplitudeGreater : 
00183     public std::binary_function< const Breakpoint, const Breakpoint, bool >
00184 {
00185 public:
00188     bool operator()( const Breakpoint & lhs, const Breakpoint & rhs ) const
00189         { return lhs.amplitude() > rhs.amplitude(); }
00190 };  
00191 
00194 typedef compareAmplitudeGreater greater_amplitude;
00195 
00196 // ---------------------------------------------------------------------------
00197 //  compareAmplitudeLess
00198 //  
00202 //
00203 class compareAmplitudeLess : 
00204     public std::binary_function< const Breakpoint, const Breakpoint, bool >
00205 {
00206 public:
00209     bool operator()( const Breakpoint & lhs, const Breakpoint & rhs ) const
00210         { return lhs.amplitude() < rhs.amplitude(); }
00211 };  
00212 
00213 }   //  end of namespace BreakpointUtils
00214 
00215 }   //  end of namespace Loris
00216 
00217 #endif /* ndef INCLUDE_BREAKPOINTUTILS_H */

Generated on Sat Jan 19 19:02:50 2008 for Loris by  doxygen 1.5.2