CSL  5.2
SHARC.h
Go to the documentation of this file.
1 //
2 // SHARC.h -- SHARC (Sandell Harmonic Archive) timbre database sample classes
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 //
5 // SHARC is a collection of analyses of instrument (string, woodwind, and brass)
6 // tones taken from the McGill Univ. Master Sample CDs by Gregory Sandell.
7 //
8 // The top-level object, a SHARCLibrary, holds onto a collection is SHARCInstrument objects,
9 // and each of these has a number of SHARCSpectrum instances for the individual sample spectra.
10 //
11 // A SHARC spectrum is simply a list of partials, each of which has frequency, amplitude, and phase.
12 // The spectrum also has the actual pitch of the sampled note, the note's name, its MIDI pitch, and other useful data.
13 //
14 // A SHARC instrument is a spectrum collection.
15 // Each "instrument" represents a collection of spectra derived from samples of an orchestral instrument.
16 //
17 // The SHARCLibrary is the top-level library (instrument collection) class
18 // The top-level object, a SHARCLibrary, holds onto a collection is SHARCInstrument objects,
19 // and each of these has a number of SHARCSpectrum instances for the individual sample spectra.
20 //
21 // SHARC is a collection of analyses of instrument (string, woodwind, and brass) tones.
22 // The top-level directory has a subdirectory for each instrument.
23 // In each instrument directory, there is a table of contents file, and some number of spectrum files.
24 //
25 // SHARC CONTENTS files have a number of lines, each of which describes a single spectrum; the
26 // format of these lines is as follows:
27 //
28 // * Column 1: The note name string -- "c4" = middle C.
29 // * Column 2: The MIDI note number (where c4 = 48)
30 // * Column 3: Number of harmonics in the file
31 // * Column 4: The maximum absolute value of the sample segment.
32 // * Column 5: The nominal fundamental frequency for the pitch.
33 // * Column 6: The actual fundamental frequency.
34 // * Column 7: Volume number of the MUMS CDs from which this note comes
35 // * Column 8: MUMS track number
36 // * Column 9: MUMS index number
37 // * Column 10: Total duration (in seconds) of the performed note.
38 // * Column 11: The point in time from which the analysis was taken.
39 // * Column 12: the Spectral centroid in hertz
40 //
41 // Example CONTENTS file line
42 // a#3 46 43 6367 233.082 231.496 2 8 1 3.080 2.124 1316.400
43 //
44 // Each spectrum file has num_partials lines, each of which is simply a magnitude (in dB relative to the loudest
45 // partial) and a phase value. The frequency of the partial is simply the base frequency of the sample times
46 // the partial's row number.
47 //
48 // Example spectrum file excerpt
49 // 0.00000 -1.17861
50 // -40.89460 -2.59737
51 // -8.82998 -2.07608
52 // -47.88580 -1.99008
53 // -10.16250 -0.29849
54 //
55 // This structure is exactly mapped by the C++ implementation.
56 //
57 // Note: The implementation has UNIX-specific code in it.
58 //
59 
60 #ifndef INCLUDE_SHARC_H
61 #define INCLUDE_SHARC_H
62 
63 #include "CSL_Core.h"
64 #include "Oscillator.h"
65 
66 #define MAX_PARTIALS 128
67 #define MAX_SPECTRA 64
68 #define MAX_INSTRUMENTS 40
69 
70 namespace csl {
71 
72 ///
73 /// SHARC spectrum class
74 ///
75 
77 
78 public:
79  char * _note_name;
80  unsigned _midi_key;
81  float _nom_pitch;
83  unsigned _max_amp;
84  unsigned _num_partials;
86 
87  SHARCSpectrum(char * folder, char * name, unsigned m_key, float n_pitch, float a_pitch,
88  unsigned m_amp, unsigned n_partials);
90 
91  bool read_from_file(char * folder, char * name);
92  unsigned count_partials();
93  void dump_example();
94 };
95 
96 ///
97 /// SHARC instrument class
98 ///
99 
101 
102 public: // Data members
103  char * _name;
104  unsigned _num_spectra;
106  // Constructor
107  SHARCInstrument(char * folder, char * name);
109  // Accessing
110  char * * spectrum_names();
111  unsigned * spectrum_keys();
112  float * spectrum_frequencies();
113  SHARCSpectrum * spectrum_named(char * name);
114  SHARCSpectrum * spectrum_with_key(unsigned key);
116  // For debugging
117  unsigned count_spectra();
118  unsigned count_partials();
119  void dump_example();
120 
121 private:
122  // Load all the samples described in the given CONTENTS file
123  bool read_from_TOC(char * folder, char * name);
124 };
125 
126 ///
127 /// SHARC library class
128 ///
129 
131 
132 public: // Data members
135  // Constructor
136  SHARCLibrary();
137  SHARCLibrary(char * name);
138  ~SHARCLibrary();
139  // Accessing
140  char * * instrument_names();
141  SHARCInstrument * instrument_named(char * name);
142  SHARCSpectrum * spectrum_named(char * inst, char * spect);
143  void dump();
144  // For debugging
145  void dump_stats();
146  void dump_example();
147 
148  // statics
149  static SHARCLibrary* sSHARCLib; ///< The protected single instance of the HRTF Database
150  static void loadDefault();
151  static SHARCLibrary * library();
152  static SHARCInstrument * instrument(char * instr);
153  static SHARCInstrument * instrument(unsigned instr);
154  static SHARCSpectrum * spectrum(char * instr, char * note);
155  static SHARCSpectrum * spectrum(char * instr, unsigned note);
156  static SHARCSpectrum * spectrum(unsigned instr, unsigned note);
157 
158 private:
159  bool read_from_directory(char * name);
160 };
161 
162 }
163 
164 #endif