00001 /* 00002 * This is the Loris C++ Class Library, implementing analysis, 00003 * manipulation, and synthesis of digitized sounds using the Reassigned 00004 * Bandwidth-Enhanced Additive Sound Model. 00005 * 00006 * Loris is Copyright (c) 1999-2004 by Kelly Fitz and Lippold Haken 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY, without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 * 00023 * SdifFile.h 00024 * 00025 * Definition of SdifFile class for Partial import and export in Loris. 00026 * 00027 * Kelly Fitz, 8 Jan 2003 00028 * loris@cerlsoundgroup.org 00029 * 00030 * http://www.cerlsoundgroup.org/Loris/ 00031 * 00032 */ 00033 00034 #include "Marker.h" 00035 #include "Partial.h" 00036 #include "PartialList.h" 00037 00038 #include <string> 00039 #include <vector> 00040 00041 // begin namespace 00042 namespace Loris { 00043 00044 // --------------------------------------------------------------------------- 00045 // class SdifFile 00046 // 00047 // Class SdifFile represents reassigned bandwidth-enhanced Partial 00048 // data in a SDIF-format data file. Construction of an SdifFile 00049 // from a stream or filename automatically imports the Partial 00050 // data. 00051 // 00052 // Loris stores partials in SDIF RBEP and RBEL frames. The RBEP and RBEL 00053 // frame and matrix definitions are included in the SDIF file's header. 00054 // Each RBEP frame contains one RBEP matrix, and each row in a RBEP matrix 00055 // describes one breakpoint in a Loris partial. The data in RBEP matrices 00056 // are SDIF 32-bit floats. 00057 // 00058 // The six columns in an RBEP matrix are: partialIndex, frequency, 00059 // amplitude, phase, noise, timeOffset. The partialIndex uniquely 00060 // identifies a partial. When Loris exports SDIF data, each partial is 00061 // assigned a unique partialIndex. The frequency (Hz), amplitude (0..1), 00062 // phase (radians), and noise (bandwidth) are encoded the same as Loris 00063 // breakpoints. The timeOffset is an offset from the RBEP frame time, 00064 // specifying the exact time of the breakpoint. Loris always specifies 00065 // positive timeOffsets, and the breakpoint's exact time is always be 00066 // earlier than the next RBEP frame's time. 00067 // 00068 // Since reassigned bandwidth-enhanced partial breakpoints are 00069 // non-uniformly spaced in time, the RBEP frame times are also 00070 // non-uniformly spaced. Each RBEP frame will contain at most one 00071 // breakpoint for any given partial. A partial may extend over a RBEP frame 00072 // and have no breakpoint specified by the RBEP frame, as happens when one 00073 // active partial has a lower temporal density of breakpoints than other 00074 // active partials. 00075 // 00076 // If partials have nonzero labels in Loris, then a RBEL frame describing 00077 // the labeling of the partials will precede the first RBEP frame in the 00078 // SDIF file. The RBEL frame contains a single, two-column RBEL matrix The 00079 // first column is the partialIndex, and the second column specifies the 00080 // label for the partial. 00081 // 00082 // If markers are associated with the partials in Loris, then a RBEM frame 00083 // describing the markers will precede the first RBEP frame in the SDIF 00084 // file. The RBEM frame contains two single-column RBEM matrices. The 00085 // first matrix contains 32-bit floats indicating the time (in seconds) 00086 // for each marker. The second matrix contains UTF-8 data, the names of 00087 // each of the markers separated by '\0'. 00088 // 00089 // In addition to RBEP frames, Loris can also read and write SDIF 1TRC 00090 // frames (refer to IRCAM's SDIF web site, www.ircam.fr/sdif/, for 00091 // definitions of standard SDIF description types). Since 1TRC frames do 00092 // not represent bandwidth-enhancement or the exact timing of Loris 00093 // breakpoints, their use is not recommended. 1TRC capabilities are 00094 // provided in Loris to allow interchange with programs that are unable to 00095 // interpret RBEP frames. 00096 // 00097 class SdifFile 00098 { 00099 // -- public interface -- 00100 public: 00101 00102 // -- types -- 00103 typedef std::vector< Marker > markers_type; 00104 typedef PartialList partials_type; 00105 00106 // -- construction -- 00107 explicit SdifFile( const std::string & filename ); 00108 /* Initialize an instance of SdifFile by importing Partial data from 00109 the file having the specified filename or path. 00110 */ 00111 00112 #if !defined(NO_TEMPLATE_MEMBERS) 00113 template<typename Iter> 00114 SdifFile( Iter begin_partials, Iter end_partials ); 00115 #else 00116 SdifFile( PartialList::const_iterator begin_partials, 00117 PartialList::const_iterator end_partials ); 00118 #endif 00119 /* Initialize an instance of SdifFile with copies of the Partials 00120 on the specified half-open (STL-style) range. 00121 00122 If compiled with NO_TEMPLATE_MEMBERS defined, this member accepts 00123 only PartialList::const_iterator arguments. 00124 */ 00125 00126 SdifFile( void ); 00127 /* Initialize an empty instance of SdifFile having no Partials. 00128 */ 00129 00130 // copy, assign, and delete are compiler-generated 00131 00132 // -- access -- 00133 markers_type & markers( void ); 00134 const markers_type & markers( void ) const; 00135 /* Return a reference to the MarkerContainer (see Marker.h) 00136 for this SdifFile. 00137 */ 00138 00139 partials_type & partials( void ); 00140 const partials_type & partials( void ) const; 00141 /* Return a reference (or const reference) to the bandwidth-enhanced 00142 Partials represented by this SdifFile. 00143 */ 00144 00145 // -- mutation -- 00146 void addPartial( const Loris::Partial & p ); 00147 /* Add a copy of the specified Partial to this SdifFile. 00148 */ 00149 00150 #if !defined(NO_TEMPLATE_MEMBERS) 00151 template<typename Iter> 00152 void addPartials( Iter begin_partials, Iter end_partials ); 00153 #else 00154 void addPartials( PartialList::const_iterator begin_partials, 00155 PartialList::const_iterator end_partials ); 00156 #endif 00157 /* Add a copy of each Partial on the specified half-open (STL-style) 00158 range to this SdifFile. 00159 00160 If compiled with NO_TEMPLATE_MEMBERS defined, this member accepts 00161 only PartialList::const_iterator arguments. 00162 */ 00163 00164 // -- export -- 00165 void write( const std::string & path ); 00166 /* Export the envelope Partials represented by this SdifFile to 00167 the file having the specified filename or path. 00168 */ 00169 00170 void write1TRC( const std::string & path ); 00171 /* Export the envelope Partials represented by this SdifFile to 00172 the file having the specified filename or path in the 1TRC 00173 format, resampled, and without phase or bandwidth information. 00174 */ 00175 00176 // -- legacy export -- 00177 static void Export( const std::string & filename, 00178 const PartialList & plist, 00179 const bool enhanced = true ); 00180 /* Export the Partials in the specified PartialList to a SDIF file having 00181 the specified file name or path. If enhanced is true (the default), 00182 reassigned bandwidth-enhanced Partial data are exported in the 00183 six-column RBEP format. Otherwise, the Partial data is exported as 00184 resampled sinusoidal analysis data in the 1TRC format. 00185 Provided for backwards compatability. 00186 */ 00187 00188 private: 00189 // -- implementation -- 00190 partials_type partials_; // Partials to store in SDIF format 00191 markers_type markers_; // AIFF Markers 00192 00193 }; // end of class SdifFile 00194 00195 #pragma mark -- template members -- 00196 00197 // --------------------------------------------------------------------------- 00198 // constructor from Partial range 00199 // --------------------------------------------------------------------------- 00200 // Initialize an instance of SdifFile with copies of the Partials 00201 // on the specified half-open (STL-style) range. 00202 // 00203 // If compiled with NO_TEMPLATE_MEMBERS defined, this member accepts 00204 // only PartialList::const_iterator arguments. 00205 // 00206 #if !defined(NO_TEMPLATE_MEMBERS) 00207 template< typename Iter > 00208 SdifFile::SdifFile( Iter begin_partials, Iter end_partials ) 00209 #else 00210 SdifFile::SdifFile( PartialList::const_iterator begin_partials, 00211 PartialList::const_iterator end_partials ) 00212 #endif 00213 { 00214 addPartials( begin_partials, end_partials ); 00215 } 00216 00217 // --------------------------------------------------------------------------- 00218 // addPartials 00219 // --------------------------------------------------------------------------- 00220 // Add a copy of each Partial on the specified half-open (STL-style) 00221 // range to this SdifFile. 00222 // 00223 // If compiled with NO_TEMPLATE_MEMBERS defined, this member accepts 00224 // only PartialList::const_iterator arguments. 00225 // 00226 #if !defined(NO_TEMPLATE_MEMBERS) 00227 template<typename Iter> 00228 void SdifFile::addPartials( Iter begin_partials, Iter end_partials ) 00229 #else 00230 void SdifFile::addPartials( PartialList::const_iterator begin_partials, 00231 PartialList::const_iterator end_partials ) 00232 #endif 00233 { 00234 partials_.insert( partials_.end(), begin_partials, end_partials ); 00235 } 00236 00237 } // end of namespace Loris 00238
1.3.4