00001 #ifndef INCLUDE_ASSOCIATEBANDWIDTH_H 00002 #define INCLUDE_ASSOCIATEBANDWIDTH_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 * AssociateBandwidth.h 00026 * 00027 * Definition of a class representing a policy for associating noise 00028 * (bandwidth) energy with reassigned spectral peaks to be used in 00029 * Partial formation. 00030 * 00031 * Kelly Fitz, 20 Jan 2000 00032 * loris@cerlsoundgroup.org 00033 * 00034 * http://www.cerlsoundgroup.org/Loris/ 00035 * 00036 */ 00037 00038 #include "SpectralPeaks.h" 00039 00040 #include <vector> 00041 00042 // begin namespace 00043 namespace Loris { 00044 00045 class Breakpoint; 00046 00047 // --------------------------------------------------------------------------- 00048 // class AssociateBandwidth 00049 // 00050 // In the new strategy, Breakpoints are extracted and accumulated 00051 // as sinusoids. Spectral peaks that are not extracted (don't exceed 00052 // the amplitude floor) or are rejected for certain reasons, are 00053 // accumulated diectly as noise (surplus). After all spectral peaks 00054 // have been accumulated as noise or sinusoids, the noise is distributed 00055 // as bandwidth. 00056 // 00057 class AssociateBandwidth 00058 { 00059 // -- instance variables -- 00060 std::vector< double > _weights; // weights vector for recording 00061 // frequency distribution of retained 00062 // sinusoids 00063 std::vector< double > _surplus; // surplus (noise) energy vector for 00064 // accumulating the distribution of 00065 // spectral energy to be distributed 00066 // as noise 00067 00068 double _regionRate; // inverse of region center spacing 00069 00070 // -- public interface -- 00071 public: 00072 // construction: 00073 AssociateBandwidth( double regionWidth, double srate ); 00074 ~AssociateBandwidth( void ); 00075 00076 // Perform bandwidth association on a collection of reassigned spectral peaks 00077 // or ridges. The range [begin, rejected) spans the Peaks selected to form 00078 // Partials. The range [rejected, end) spans the Peaks that were found in 00079 // the reassigned spectrum, but rejected as too weak or too close (in 00080 // frequency) to another stronger Peak. 00081 void associateBandwidth( Peaks::iterator begin, // beginning of Peaks 00082 Peaks::iterator rejected, // first rejected Peak 00083 Peaks::iterator end ); // end of Peaks 00084 00085 00086 // -- private helpers -- 00087 private: 00088 double computeNoiseEnergy( double freq, double amp ); 00089 00090 // These four formerly comprised the public interface 00091 // to this policy, now they are all hidden behind a 00092 // single call to associateBandwidth. 00093 00094 // energy accumulation: 00095 void accumulateNoise( double freq, double amp ); 00096 void accumulateSinusoid( double freq, double amp ); 00097 00098 // bandwidth assocation: 00099 void associate( SpectralPeak & pk ); 00100 00101 // call this to wipe out the accumulated energy to 00102 // prepare for the next frame (yuk): 00103 void reset( void ); 00104 00105 }; // end of class AssociateBandwidth 00106 00107 } // end of namespace Loris 00108 00109 #endif /* ndef INCLUDE_ASSOCIATEBANDWIDTH_H */