00001 #ifndef INCLUDE_SPECTRALPEAKS_H 00002 #define INCLUDE_SPECTRALPEAKS_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 * SpectralPeaks.h 00026 * 00027 * Definition of a type representing a collection (vector) of 00028 * reassigned spectral peaks or ridges. Shared by analysis policies. 00029 * 00030 * Kelly Fitz, 29 May 2003 00031 * loris@cerlsoundgroup.org 00032 * 00033 * http://www.cerlsoundgroup.org/Loris/ 00034 * 00035 */ 00036 00037 #include "Breakpoint.h" 00038 00039 #include <vector> 00040 00041 // begin namespace 00042 namespace Loris { 00043 00044 // define a spectral peak data structure 00045 // 00046 // HEY 00047 // Clean this mess up! Upgrade this struct into a class that can 00048 // store more kinds of information (like reassignment values), and 00049 // creates a Breakpoint when needed. 00050 00051 class SpectralPeak 00052 { 00053 private: 00054 00055 double m_time; 00056 Breakpoint m_breakpoint; 00057 00058 public: 00059 00060 // --- lifecycle --- 00061 00062 SpectralPeak( double t, const Breakpoint & bp ) : m_time( t ), m_breakpoint( bp ) {} 00063 00064 00065 // --- access --- 00066 00067 double time( void ) const { return m_time; } 00068 00069 double amplitude( void ) const { return m_breakpoint.amplitude(); } 00070 double frequency( void ) const { return m_breakpoint.frequency(); } 00071 double bandwidth( void ) const { return m_breakpoint.bandwidth(); } 00072 00073 // --- mutation --- 00074 00075 void setAmplitude( double x ) { m_breakpoint.setAmplitude(x); } 00076 void setBandwidth( double x ) { m_breakpoint.setBandwidth(x); } 00077 00078 // this REALLY shouldn't be in here... 00079 void addNoiseEnergy( double enoise ) { m_breakpoint.addNoiseEnergy(enoise); } 00080 00081 // --- Breakpoint creation --- 00082 00083 Breakpoint createBreakpoint( void ) const { return m_breakpoint; } 00084 00085 // --- comparitors --- 00086 00087 // Comparitor for sorting spectral peaks in order of 00088 // increasing frequency, or finding maximum frequency. 00089 00090 static bool sort_increasing_freq( const SpectralPeak & lhs, 00091 const SpectralPeak & rhs ) 00092 { 00093 return lhs.frequency() < rhs.frequency(); 00094 } 00095 00096 // predicate used for sorting peaks in order of decreasing amplitude: 00097 static bool sort_greater_amplitude( const SpectralPeak & lhs, 00098 const SpectralPeak & rhs ) 00099 { 00100 return lhs.amplitude() > rhs.amplitude(); 00101 } 00102 }; 00103 00104 // define the structure used to collect spectral peaks: 00105 typedef std::vector< SpectralPeak > Peaks; 00106 00107 00108 00109 } // end of namespace Loris 00110 00111 #endif /* ndef INCLUDE_SPECTRALPEAKS_H */