1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/*
* Modification History
*
* 2004-August-22 Jason Rohrer
* Created.
*/
#ifndef MUSIC_NOTE_WAVE_TABLE_INCLUDED
#define MUSIC_NOTE_WAVE_TABLE_INCLUDED
/**
* Class representing a note that can be mapped into the wave table.
*/
class MusicNote {
public:
/**
* Constructs a note.
*
* @param inFrequencyIndex the frequency parameter in the wave table.
* @param inLengthIndex the length parameter in the wave table.
* @param inReversed true if this note's samples should be played
* in reverse. Defaults to false.
*/
MusicNote( int inFrequencyIndex, int inLengthIndex,
char inReversed = false );
/**
* Makes a copy of this note.
*
* @return a copy.
* Must be destroyed by caller.
*/
MusicNote *copy();
int mFrequencyIndex;
int mLengthIndex;
char mReversed;
};
/**
* Class that contains pre-rendered sample table for each possible
* note waveform.
*
* @author Jason Rohrer
*/
class MusicNoteWaveTable {
public:
/**
* Constructs a wave table.
* Reads configuration using the LevelDirectoryManager.
*
* @param inSamplesPerSecond the sample rate.
*/
MusicNoteWaveTable( unsigned long inSamplesPerSecond );
~MusicNoteWaveTable();
/**
* Gets the number of frequencies contained in this table.
*
* @return the number of frequencies.
*/
int getFrequencyCount();
/**
* Gets the number of lengths contained in this table.
*
* @return the number of lengths.
*/
int getLengthCount();
/**
* Gets the length associated with a length index.
*
* @param inLengthIndex the index to map.
*
* @return the length in seconds.
*/
double getLengthInSeconds( int inLengthIndex );
/**
* Maps freqency and length index parameters to wave samples.
*
* @param inFrequencyIndex the frequency index, in the range
* [ 0, getFrequencyCount() ).
* @param inLengthIndex the length index, in the range
* [ 0, getLengthCount() ).
* @param outNumSamples pointer to where the number of samples
* should be returned (the size of the returned array).
*
* @return an array of samples. Will be destroyed by this
* class. Should not be modified by caller.
*/
float *mapParametersToSamples( int inFrequencyIndex,
int inLengthIndex,
unsigned long *outNumSamples );
/**
* Maps a note to wave samples.
*
* @param inNote the note to map.
* Must be destroyed by caller.
* @param outNumSamples pointer to where the number of samples
* should be returned (the size of the returned array).
*
* @return an array of samples. Will be destroyed by this
* class. Should not be modified by caller.
*/
float *mapNoteToSamples( MusicNote *inNote,
unsigned long *outNumSamples );
protected:
int mFrequencyCount;
int mLengthCount;
float ***mSampleTable;
unsigned long *mSampleCounts;
double *mLengthsInSeconds;
};
#endif
|