00001 #ifndef INCLUDE_PARTIALBUILDER_H 00002 #define INCLUDE_PARTIALBUILDER_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 * PartialBuilder.h 00026 * 00027 * Implementation of a class representing a policy for connecting peaks 00028 * extracted from a reassigned time-frequency spectrum to form ridges 00029 * and construct Partials. 00030 * 00031 * This strategy attemps to follow a reference frequency envelope when 00032 * forming Partials, by prewarping all peak frequencies according to the 00033 * (inverse of) frequency reference envelope. At the end of the analysis, 00034 * Partial frequencies need to be un-warped by calling fixPartialFrequencies(). 00035 * 00036 * Kelly Fitz, 28 May 2003 00037 * loris@cerlsoundgroup.org 00038 * 00039 * http://www.cerlsoundgroup.org/Loris/ 00040 * 00041 */ 00042 00043 #include "Partial.h" 00044 #include "PartialList.h" 00045 #include "PartialPtrs.h" 00046 #include "SpectralPeaks.h" 00047 00048 #include <memory> 00049 00050 // begin namespace 00051 namespace Loris { 00052 00053 class Envelope; 00054 00055 // --------------------------------------------------------------------------- 00056 // class PartialBuilder 00057 // 00058 // A class representing the process of connecting peaks (ridges) on a 00059 // reassigned time-frequency surface to form Partials. 00060 // 00061 class PartialBuilder 00062 { 00063 // --- public interface --- 00064 00065 public: 00066 00067 // constructor 00068 // 00069 // Construct a new builder that constrains Partial frequnecy 00070 // drift by the specified drift value in Hz. 00071 PartialBuilder( double drift ); 00072 00073 // constructor 00074 // 00075 // Construct a new builder that constrains Partial frequnecy 00076 // drift by the specified drift value in Hz. The frequency 00077 // warping envelope is applied to the spectral peak frequencies 00078 // and the frequency drift parameter in each frame before peaks 00079 // are linked to eligible Partials. All the Partial frequencies 00080 // need to be un-warped at the ned of the building process, by 00081 // calling finishBuilding(). 00082 PartialBuilder( double drift, const Envelope & freqWarpEnv ); 00083 00084 // buildPartials 00085 // 00086 // Append spectral peaks, extracted from a reassigned time-frequency 00087 // spectrum, to eligible Partials, where possible. Peaks that cannot 00088 // be used to extend eliglble Partials spawn new Partials. 00089 // 00090 // This is similar to the basic MQ partial formation strategy, except that 00091 // before matching, all frequencies are normalized by the value of the 00092 // warping envelope at the time of the current frame. This means that 00093 // the frequency envelopes of all the Partials are warped, and need to 00094 // be un-normalized by calling finishBuilding at the end of the building 00095 // process. 00096 void buildPartials( Peaks & peaks, double frameTime ); 00097 00098 // finishBuilding 00099 // 00100 // Un-do the frequency warping performed in buildPartials, and return 00101 // the Partials that were built. After calling finishBuilding, the 00102 // builder is returned to its initial state, and ready to build another 00103 // set of Partials. Partials are returned by appending them to the 00104 // supplied PartialList. 00105 void finishBuilding( PartialList & product ); 00106 00107 private: 00108 00109 // --- auxiliary member functions --- 00110 00111 double freq_distance( const Partial & partial, const SpectralPeak & pk ); 00112 00113 bool better_match( const Partial & part, const SpectralPeak & pk1, 00114 const SpectralPeak & pk2 ); 00115 bool better_match( const Partial & part1, 00116 const Partial & part2, const SpectralPeak & pk ); 00117 00118 00119 // --- collected partials --- 00120 00121 PartialList mCollectedPartials; // collect partials here 00122 00123 // --- builder state variables --- 00124 00125 PartialPtrs mEligiblePartials; 00126 PartialPtrs mNewlyEligible; // keep track of eligible partials here 00127 00128 // --- parameters --- 00129 00130 std::auto_ptr< Envelope > mFreqWarping; // reference envelope 00131 00132 double mFreqDrift; 00133 00134 // --- disallow copy and assignment --- 00135 00136 PartialBuilder( const PartialBuilder & ); 00137 PartialBuilder& operator=( const PartialBuilder & ); 00138 00139 }; // end of class PartialBuilder 00140 00141 } // end of namespace Loris 00142 00143 #endif /* ndef INCLUDE_PARTIALBUILDER_H */