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-2004 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 * Some out-of-line functions are defined in BreakpointUtils.C. 00029 * 00030 * Kelly Fitz, 6 July 2000 00031 * loris@cerlsoundgroup.org 00032 * 00033 * http://www.cerlsoundgroup.org/Loris/ 00034 * 00035 */ 00036 00037 #include "Breakpoint.h" 00038 #include <algorithm> 00039 #include <functional> 00040 00041 // begin namespace 00042 namespace Loris { 00043 00044 // --------------------------------------------------------------------------- 00045 // class/namespace BreakpointUtils 00046 // 00047 // BreakpointUtils represents a collection of utility functions and 00048 // function objects for applying STL searching and sorting algorithms 00049 // to collections of Loris Breakpoints. BreakpointUtils is a namespace 00050 // within the Loris namespace, unless compiled with NO_NESTED_NAMESPACE, 00051 // in which case it is a class (having only static members and private 00052 // constructors). 00053 // 00054 // Lakos suggests protecting utility functions like this in a class 00055 // definition, but I think a namespace is better, since that is really 00056 // what is being constructed. 00057 // 00058 // 00059 #if !defined( NO_NESTED_NAMESPACE ) 00060 // BreakpointUtils is a namespace: 00061 namespace BreakpointUtils { 00062 #else 00063 // BreakpointUtils is a class: 00064 class BreakpointUtils 00065 { 00066 // unimplemented, cannot instantiate BreakpointUtils: 00067 BreakpointUtils(void); 00068 BreakpointUtils(const BreakpointUtils &); 00069 00070 // -- public interface -- 00071 public: 00072 #endif 00073 00074 // -- free functions -- 00075 #if defined( NO_NESTED_NAMESPACE ) 00076 static 00077 #endif 00078 inline void addNoiseEnergy( Breakpoint & bp, double enoise ) { bp.addNoiseEnergy(enoise); } 00079 /* Add noise (bandwidth) energy to a Breakpoint by computing new 00080 amplitude and bandwidth values. enoise may be negative, but 00081 noise energy cannot be removed (negative energy added) in excess 00082 of the current noise energy. 00083 00084 This operation is now part of the Breakpoint interface. 00085 */ 00086 00087 #if defined( NO_NESTED_NAMESPACE ) 00088 static 00089 #endif 00090 Breakpoint makeNullBefore( const Breakpoint & bp, double fadeTime ); // see BreakpointUtils.C 00091 /* Return a null (zero-amplitude) Breakpoint to preceed the specified 00092 Breakpoint, useful for fading in a Partial. 00093 */ 00094 00095 #if defined( NO_NESTED_NAMESPACE ) 00096 static 00097 #endif 00098 Breakpoint makeNullAfter( const Breakpoint & bp, double fadeTime ); // see BreakpointUtils.C 00099 /* Return a null (zero-amplitude) Breakpoint to succeed the specified 00100 Breakpoint, useful for fading out a Partial. 00101 */ 00102 00103 00104 // -- predicates -- 00105 /* Predicate functor returning true if its Breakpoint argument 00106 has frequency between specified bounds, and false otherwise. 00107 */ 00108 struct frequency_between : 00109 public std::unary_function< const Breakpoint, bool > 00110 { 00111 bool operator()( const Breakpoint & b ) const 00112 { 00113 return (b.frequency() > _fmin) && 00114 (b.frequency() < _fmax); 00115 } 00116 00117 // constructor: 00118 frequency_between( double x, double y ) : 00119 _fmin( x ), _fmax( y ) 00120 { if (x>y) std::swap(x,y); } 00121 00122 // bounds: 00123 private: 00124 double _fmin, _fmax; 00125 }; 00126 00127 // -- comparitors -- 00128 /* Comparitor (binary) functor returning true if its first Breakpoint 00129 argument has frequency less than that of its second Breakpoint argument, 00130 and false otherwise. 00131 */ 00132 struct less_frequency : 00133 public std::binary_function< const Breakpoint, const Breakpoint, bool > 00134 { 00135 bool operator()( const Breakpoint & lhs, const Breakpoint & rhs ) const 00136 { return lhs.frequency() < rhs.frequency(); } 00137 }; 00138 00139 /* Comparitor (binary) functor returning true if its first Breakpoint 00140 argument has amplitude greater than that of its second Breakpoint argument, 00141 and false otherwise. 00142 */ 00143 struct greater_amplitude : 00144 public std::binary_function< const Breakpoint, const Breakpoint, bool > 00145 { 00146 bool operator()( const Breakpoint & lhs, const Breakpoint & rhs ) const 00147 { return lhs.amplitude() > rhs.amplitude(); } 00148 }; 00149 00150 00151 #if !defined( NO_NESTED_NAMESPACE ) 00152 } // end of namespace BreakpointUtils 00153 #else 00154 }; // end of class BreakpointUtils 00155 #endif 00156 00157 } // end of namespace Loris 00158 00159 #endif /* ndef INCLUDE_BREAKPOINTUTILS_H */
1.3.4