31 #define RIFF_ID(x) (*((uint32_t*) x))
34 #define RIFF_TYPE_SF2 RIFF_ID("sfbk")
37 #define LIST_TYPE_SDTA RIFF_ID("sdta")
38 #define LIST_TYPE_PDTA RIFF_ID("pdta")
42 #define CHUNK_ID_IFIL RIFF_ID("ifil")
43 #define CHUNK_ID_ISNG RIFF_ID("isng")
44 #define CHUNK_ID_IROM RIFF_ID("irom")
45 #define CHUNK_ID_IVER RIFF_ID("iver")
48 #define CHUNK_ID_SM24 RIFF_ID("sm24")
51 #define CHUNK_ID_PHDR RIFF_ID("phdr")
52 #define CHUNK_ID_PBAG RIFF_ID("pbag")
53 #define CHUNK_ID_PMOD RIFF_ID("pmod")
54 #define CHUNK_ID_PGEN RIFF_ID("pgen")
55 #define CHUNK_ID_INST RIFF_ID("inst")
56 #define CHUNK_ID_IBAG RIFF_ID("ibag")
57 #define CHUNK_ID_IMOD RIFF_ID("imod")
58 #define CHUNK_ID_IGEN RIFF_ID("igen")
59 #define CHUNK_ID_SHDR RIFF_ID("shdr")
64 static uint NONE = 0x1ffffff;
66 double ToSeconds(
int Timecents);
67 double ToRatio(
int Centibels);
68 double ToHz(
int cents);
70 typedef struct _PresetBag {
75 typedef uint16_t SFModulator;
76 typedef uint16_t SFGenerator;
77 typedef uint16_t SFTransform;
79 typedef struct _ModList {
80 SFModulator ModSrcOper;
81 SFGenerator ModDestOper;
83 SFModulator ModAmtSrcOper;
84 SFTransform ModTransOper;
87 typedef struct _RangesType {
97 typedef union _GenAmountType {
103 typedef struct _GenList {
105 GenAmountType GenAmount;
108 typedef struct _InstBag {
114 START_ADDRS_OFFSET = 0,
116 STARTLOOP_ADDRS_OFFSET,
117 ENDLOOP_ADDRS_OFFSET ,
118 START_ADDRS_COARSE_OFFSET,
124 MOD_LFO_TO_FILTER_FC,
125 MOD_ENV_TO_FILTER_FC,
126 END_ADDRS_COARSE_OFFSET,
145 KEYNUM_TO_MOD_ENV_HOLD,
146 KEYNUM_TO_MOD_ENV_DECAY,
153 KEYNUM_TO_VOL_ENV_HOLD,
154 KEYNUM_TO_VOL_ENV_DECAY,
159 STARTLOOP_ADDRS_COARSE_OFFSET,
164 ENDLOOP_ADDRS_COARSE_OFFSET,
189 NOTE_ON_VELOCITY = 2,
190 NOTE_ON_KEY_NUMBER = 3,
192 CHANNEL_PRESSURE = 13,
194 PITCH_WHEEL_SENSITIVITY = 16,
214 Modulator(SFModulator mod);
217 class ModulatorItem {
219 Modulator ModSrcOper;
220 SFGenerator ModDestOper;
222 Modulator ModAmtSrcOper;
223 SFTransform ModTransOper;
225 ModulatorItem(ModList& mod);
229 typedef std::string String;
260 static void LoadString(uint32_t ChunkID,
RIFF::List* lstINFO, String& s);
273 ROM_MONO_SAMPLE = 0x8001,
274 ROM_RIGHT_SAMPLE = 0x8002,
275 ROM_LEFT_SAMPLE = 0x8004,
276 ROM_LINKED_SAMPLE = 0x8008
303 String GetName() {
return Name; }
304 int GetChannelCount();
305 long GetTotalFrameCount();
308 bool IsUnpitched() {
return OriginalPitch == 255; }
309 File* GetFile() {
return pFile; }
311 buffer_t LoadSampleData();
312 buffer_t LoadSampleData(
unsigned long SampleCount);
313 buffer_t LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);
314 buffer_t LoadSampleDataWithNullSamplesExtension(
unsigned long SampleCount, uint NullSamplesCount);
316 void ReleaseSampleData();
317 unsigned long SetPos(
unsigned long SampleCount);
318 unsigned long GetPos();
319 unsigned long Read(
void* pBuffer,
unsigned long SampleCount);
320 unsigned long ReadNoClear(
void* pBuffer,
unsigned long SampleCount, buffer_t& tempBuffer);
322 unsigned long ReadAndLoop (
324 unsigned long FrameCount,
325 PlaybackState* pPlaybackState,
342 uint8_t OriginalPitch;
343 uint8_t PitchCorrection;
362 int overridingRootKey;
363 int startAddrsOffset, startAddrsCoarseOffset, endAddrsOffset, endAddrsCoarseOffset;
364 int startloopAddrsOffset, startloopAddrsCoarseOffset, endloopAddrsOffset, endloopAddrsCoarseOffset;
366 int modEnvToPitch , modLfoToPitch, modEnvToFilterFc, modLfoToFilterFc;
367 int modLfoToVolume , freqModLfo ;
369 int vibLfoToPitch, freqVibLfo ;
371 int initialFilterFc , initialFilterQ ;
379 Instrument* pInstrument;
382 Sample* GetSample() {
return pSample; }
383 Region* GetParent() {
return this; }
393 std::vector<ModulatorItem> modulators;
397 int GetPan(
Region* pPresetRegion = NULL);
398 int GetFineTune(
Region* pPresetRegion = NULL);
399 int GetCoarseTune(
Region* pPresetRegion = NULL);
400 double GetEG1PreAttackDelay(
Region* pPresetRegion = NULL);
401 double GetEG1Attack(
Region* pPresetRegion = NULL);
402 double GetEG1Hold(
Region* pPresetRegion = NULL);
403 double GetEG1Decay(
Region* pPresetRegion = NULL);
404 int GetEG1Sustain(
Region* pPresetRegion = NULL);
405 double GetEG1Release(
Region* pPresetRegion = NULL);
407 double GetEG2PreAttackDelay(
Region* pPresetRegion = NULL);
408 double GetEG2Attack(
Region* pPresetRegion = NULL);
409 double GetEG2Hold(
Region* pPresetRegion = NULL);
410 double GetEG2Decay(
Region* pPresetRegion = NULL);
411 int GetEG2Sustain(
Region* pPresetRegion = NULL);
412 double GetEG2Release(
Region* pPresetRegion = NULL);
414 int GetModEnvToPitch(
Region* pPresetRegion = NULL);
415 int GetModLfoToPitch(
Region* pPresetRegion = NULL);
416 int GetModEnvToFilterFc(
Region* pPresetRegion = NULL);
417 int GetModLfoToFilterFc(
Region* pPresetRegion = NULL);
418 double GetModLfoToVolume(
Region* pPresetRegion = NULL);
419 double GetFreqModLfo(
Region* pPresetRegion = NULL);
420 double GetDelayModLfo(
Region* pPresetRegion = NULL);
421 int GetVibLfoToPitch(
Region* pPresetRegion = NULL);
422 double GetFreqVibLfo(
Region* pPresetRegion = NULL);
423 double GetDelayVibLfo(
Region* pPresetRegion = NULL);
424 int GetInitialFilterFc(
Region* pPresetRegion);
425 int GetInitialFilterQ(
Region* pPresetRegion);
427 friend class Instrument;
431 int EG1PreAttackDelay;
438 int EG2PreAttackDelay;
445 Instrument* pParentInstrument;
447 void SetGenerator(sf2::File* pFile, GenList& Gen);
448 void SetModulator(sf2::File* pFile, ModList& Mod);
451 class InstrumentBase {
454 Region* pGlobalRegion;
456 InstrumentBase(sf2::File* pFile);
457 virtual ~InstrumentBase();
459 sf2::File* GetFile() {
return pFile; }
460 String GetName() {
return Name; }
462 int GetRegionCount();
463 Region* GetRegion(
int idx);
466 std::vector<Region*> regions;
475 Query(InstrumentBase& instrument);
479 InstrumentBase& instrument;
483 class Instrument :
public InstrumentBase {
488 void DeleteRegion(Region* pRegion);
495 void LoadRegions(
int idx1,
int idx2);
497 Region* CreateRegion();
500 class Preset :
public InstrumentBase {
513 uint16_t PresetBagNdx;
518 void LoadRegions(
int idx1,
int idx2);
520 Region* CreateRegion();
530 int GetPresetCount();
531 Preset* GetPreset(
int idx);
532 int GetInstrumentCount();
533 Instrument* GetInstrument(
int idx);
534 void DeleteInstrument(Instrument* pInstrument);
535 int GetSampleCount();
536 Sample* GetSample(
int idx);
537 void DeleteSample(Sample* pSample);
542 friend class Instrument;
547 std::vector<PresetBag> PresetBags;
548 std::vector<ModList> PresetModLists;
549 std::vector<GenList> PresetGenLists;
550 std::vector<InstBag> InstBags;
551 std::vector<ModList> InstModLists;
552 std::vector<GenList> InstGenLists;
555 std::vector<Preset*> Presets;
556 std::vector<Instrument*> Instruments;
557 std::vector<Sample*> Samples;
Will be thrown whenever an error occurs while handling a RIFF file.
Instrument * GetParentInstrument()
Reflects the current playback state for a sample.
unsigned long loop_cycles_left
How many times the loop has still to be passed, this value will be decremented with each loop cycle.
bool reverse
If playback direction is currently backwards (in case there is a pingpong or reverse loop defined).
unsigned long position
Current position within the sample.
SoundFont specific classes and definitions.
String libraryVersion()
Returns version of this C++ library.
String libraryName()
Returns the name of this C++ library.
Pointer address and size of a buffer.
unsigned long Size
Size of the actual data in the buffer in bytes.
void * pStart
Points to the beginning of the buffer.
unsigned long NullExtensionSize
The buffer might be bigger than the actual data, if that's the case that unused space at the end of t...