SHARC.h

Go to the documentation of this file.
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 /****************************************************************************
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_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                     // For debugging
00144     void dump_stats();
00145     void dump_example();
00146     
00147 private:
00148     bool read_from_directory(char * name);
00149 };
00150 
00151 }
00152 
00153 #endif

Generated on Thu Sep 17 23:14:16 2009 for CSL by  doxygen 1.5.8