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 SHARCLibrary, holds onto a collection is SHARCInstrument objects, 00009 // and each of these has a number of SHARCSpectrum 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 SHARCLibrary is the top-level library (instrument collection) class 00018 // The top-level object, a SHARCLibrary, holds onto a collection is SHARCInstrument objects, 00019 // and each of these has a number of SHARCSpectrum instances for the individual sample spectra. 00020 // 00021 // SHARC is a collection of analyses of instrument (string, woodwind, and brass) tones. 00022 // The top-level directory has a subdirectory for each instrument. 00023 // In each instrument directory, there is a table of contents file, and some number of spectrum files. 00024 // 00025 // SHARC CONTENTS files have a number of lines, each of which describes a single spectrum; the 00026 // format of these lines is as follows: 00027 // 00028 // * Column 1: The note name string -- "c4" = middle C. 00029 // * Column 2: The MIDI note number (where c4 = 48) 00030 // * Column 3: Number of harmonics in the file 00031 // * Column 4: The maximum absolute value of the sample segment. 00032 // * Column 5: The nominal fundamental frequency for the pitch. 00033 // * Column 6: The actual fundamental frequency. 00034 // * Column 7: Volume number of the MUMS CDs from which this note comes 00035 // * Column 8: MUMS track number 00036 // * Column 9: MUMS index number 00037 // * Column 10: Total duration (in seconds) of the performed note. 00038 // * Column 11: The point in time from which the analysis was taken. 00039 // * Column 12: the Spectral centroid in hertz 00040 // 00041 // Example CONTENTS file line 00042 // a#3 46 43 6367 233.082 231.496 2 8 1 3.080 2.124 1316.400 00043 // 00044 // Each spectrum file has num_partials lines, each of which is simply a magnitude (in dB relative to the loudest 00045 // partial) and a phase value. The frequency of the partial is simply the base frequency of the sample times 00046 // the partial's row number. 00047 // 00048 // Example spectrum file excerpt 00049 // 0.00000 -1.17861 00050 // -40.89460 -2.59737 00051 // -8.82998 -2.07608 00052 // -47.88580 -1.99008 00053 // -10.16250 -0.29849 00054 // 00055 // This structure is exactly mapped by the C++ implementation. 00056 // 00057 // Note: The implementation has UNIX-specific code in it. 00058 // 00059 00060 #ifndef INCLUDE_SHARC_H 00061 #define INCLUDE_SHARC_H 00062 00063 #include "CSL_Core.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 00075 00076 class SHARCSpectrum { 00077 00078 public: 00079 char * _note_name; 00080 unsigned _midi_key; 00081 float _nom_pitch; 00082 float _actual_pitch; 00083 unsigned _max_amp; 00084 unsigned _num_partials; 00085 Partial ** _partials; 00086 00087 SHARCSpectrum(char * folder, char * name, unsigned m_key, float n_pitch, float a_pitch, 00088 unsigned m_amp, unsigned n_partials); 00089 ~SHARCSpectrum(); 00090 00091 bool read_from_file(char * folder, char * name); 00092 unsigned count_partials(); 00093 void dump_example(); 00094 }; 00095 00099 00100 class SHARCInstrument { 00101 00102 public: // Data members 00103 char * _name; 00104 unsigned _num_spectra; 00105 SHARCSpectrum ** _spectra; 00106 // Constructor 00107 SHARCInstrument(char * folder, char * name); 00108 ~SHARCInstrument(); 00109 // Accessing 00110 char * * spectrum_names(); 00111 unsigned * spectrum_keys(); 00112 float * spectrum_frequencies(); 00113 SHARCSpectrum * spectrum_named(char * name); 00114 SHARCSpectrum * spectrum_with_key(unsigned key); 00115 SHARCSpectrum * spectrum_with_frequency(float freq); 00116 // For debugging 00117 unsigned count_spectra(); 00118 unsigned count_partials(); 00119 void dump_example(); 00120 00121 private: 00122 // Load all the samples described in the given CONTENTS file 00123 bool read_from_TOC(char * folder, char * name); 00124 }; 00125 00129 00130 class SHARCLibrary { 00131 00132 public: // Data members 00133 unsigned _num_instruments; 00134 SHARCInstrument ** _instruments; 00135 // Constructor 00136 SHARCLibrary(); 00137 SHARCLibrary(char * name); 00138 ~SHARCLibrary(); 00139 // Accessing 00140 char * * instrument_names(); 00141 SHARCInstrument * instrument_named(char * name); 00142 SHARCSpectrum * spectrum_named(char * inst, char * spect); 00143 void dump(); 00144 // For debugging 00145 void dump_stats(); 00146 void dump_example(); 00147 00148 // statics 00149 static SHARCLibrary* sSHARCLib; 00150 static void loadDefault(); 00151 static SHARCLibrary * library(); 00152 static SHARCInstrument * instrument(char * instr); 00153 static SHARCInstrument * instrument(unsigned instr); 00154 static SHARCSpectrum * spectrum(char * instr, char * note); 00155 static SHARCSpectrum * spectrum(char * instr, unsigned note); 00156 static SHARCSpectrum * spectrum(unsigned instr, unsigned note); 00157 00158 private: 00159 bool read_from_directory(char * name); 00160 }; 00161 00162 } 00163 00164 #endif
1.4.5-20051010