00001 // 00002 // SHARC.h -- SHARC (Sandell Harmonic Archive) timbre database sample classes 00003 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT 00004 // 00005 // SHARC is a collection of analyses of instrument (string, woodwind, and brass) 00006 // tones taken from the McGill Univ. Master Sample CDs by Gregory Sandell. 00007 // 00008 // The top-level object, a SHARC_Library, holds onto a collection is SHARC_Instrument objects, 00009 // and each of these has a number of SHARC_Spectrum instances for the individual sample spectra. 00010 // 00011 // A SHARC spectrum is simply a list of partials, each of which has frequency, amplitude, and phase. 00012 // The spectrum also has the actual pitch of the sampled note, the note's name, its MIDI pitch, and other useful data. 00013 // 00014 // A SHARC instrument is a spectrum collection. 00015 // Each "instrument" represents a collection of spectra derived from samples of an orchestral instrument. 00016 // 00017 // The SHARC_Library is the top-level library (instrument collection) class 00018 // The top-level object, a SHARC_Library, holds onto a collection is SHARC_Instrument objects, 00019 // and each of these has a number of SHARC_Spectrum instances for the individual sample spectra. 00020 00021 /**************************************************************************** 00022 SHARC is a collection of analyses of instrument (string, woodwind, and brass) tones. 00023 The top-level directory has a subdirectory for each instrument. 00024 In each instrument directory, there is a table of contents file, and some number of spectrum files. 00025 00026 SHARC CONTENTS files have a number of lines, each of which describes a single spectrum; the 00027 format of these lines is as follows: 00028 00029 * Column 1: The note name string -- "c4" = middle C. 00030 * Column 2: The MIDI note number (where c4 = 48) 00031 * Column 3: Number of harmonics in the file 00032 * Column 4: The maximum absolute value of the sample segment. 00033 * Column 5: The nominal fundamental frequency for the pitch. 00034 * Column 6: The actual fundamental frequency. 00035 * Column 7: Volume number of the MUMS CDs from which this note comes 00036 * Column 8: MUMS track number 00037 * Column 9: MUMS index number 00038 * Column 10: Total duration (in seconds) of the performed note. 00039 * Column 11: The point in time from which the analysis was taken. 00040 * Column 12: the Spectral centroid in hertz 00041 00042 Example CONTENTS file line 00043 a#3 46 43 6367 233.082 231.496 2 8 1 3.080 2.124 1316.400 00044 00045 Each spectrum file has num_partials lines, each of which is simply a magnitude (in dB relative to the loudest 00046 partial) and a phase value. The frequency of the partial is simply the base frequency of the sample times 00047 the partial's row number. 00048 00049 Example spectrum file excerpt 00050 0.00000 -1.17861 00051 -40.89460 -2.59737 00052 -8.82998 -2.07608 00053 -47.88580 -1.99008 00054 -10.16250 -0.29849 00055 00056 This structure is exactly mapped by the C++ implementation. 00057 00058 ************************************************************************************/ 00059 00060 #ifndef INCLUDE_SHARC_H 00061 #define INCLUDE_SHARC_H 00062 00063 #include "CSL_Includes.h" 00064 #include "Oscillator.h" 00065 00066 #define MAX_PARTIALS 128 00067 #define MAX_SPECTRA 64 00068 #define MAX_INSTRUMENTS 40 00069 00070 namespace csl { 00071 00072 // SHARC spectrum class 00073 00074 class SHARC_Spectrum { 00075 00076 public: 00077 char * _note_name; 00078 unsigned _midi_key; 00079 float _nom_pitch; 00080 float _actual_pitch; 00081 unsigned _max_amp; 00082 unsigned _num_partials; 00083 Partial ** _partials; 00084 00085 SHARC_Spectrum(char * folder, char * name, unsigned m_key, float n_pitch, float a_pitch, 00086 unsigned m_amp, unsigned n_partials); 00087 ~SHARC_Spectrum(); 00088 00089 bool read_from_file(char * folder, char * name); 00090 unsigned count_partials(); 00091 void dump_example(); 00092 }; 00093 00094 // SHARC instrument class 00095 00096 class SHARC_Instrument { 00097 00098 public: // Data members 00099 char * _name; 00100 unsigned _num_spectra; 00101 SHARC_Spectrum ** _spectra; 00102 // Constructor 00103 SHARC_Instrument(char * folder, char * name); 00104 ~SHARC_Instrument(); 00105 // Accessing 00106 char * * spectrum_names(); 00107 unsigned * spectrum_keys(); 00108 float * spectrum_frequencies(); 00109 SHARC_Spectrum * spectrum_named(char * name); 00110 SHARC_Spectrum * spectrum_with_key(unsigned key); 00111 SHARC_Spectrum * spectrum_with_frequency(float freq); 00112 // For debugging 00113 unsigned count_spectra(); 00114 unsigned count_partials(); 00115 void dump_example(); 00116 00117 private: 00118 // Load all the samples described in the given CONTENTS file 00119 bool read_from_TOC(char * folder, char * name); 00120 }; 00121 00122 // SHARC library class 00123 00124 class SHARC_Library { 00125 00126 public: // Data members 00127 unsigned _num_instruments; 00128 SHARC_Instrument ** _instruments; 00129 // Constructor 00130 SHARC_Library(); 00131 SHARC_Library(char * name); 00132 ~SHARC_Library(); 00133 // Accessing 00134 char * * instrument_names(); 00135 SHARC_Instrument * instrument_named(char * name); 00136 SHARC_Spectrum * spectrum_named(char * inst, char * spect); 00137 // For debugging 00138 void dump_stats(); 00139 void dump_example(); 00140 00141 private: 00142 bool read_from_directory(char * name); 00143 }; 00144 00145 } 00146 00147 #endif
1.4.5-20051010