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,
186 NOTE_ON_VELOCITY = 2,
187 NOTE_ON_KEY_NUMBER = 3,
189 CHANNEL_PRESSURE = 13,
191 PITCH_WHEEL_SENSITIVITY = 16,
211 Modulator(SFModulator mod);
214 class ModulatorItem {
216 Modulator ModSrcOper;
217 SFGenerator ModDestOper;
219 Modulator ModAmtSrcOper;
220 SFTransform ModTransOper;
222 ModulatorItem(ModList& mod);
226 typedef std::string String;
257 static void LoadString(uint32_t ChunkID,
RIFF::List* lstINFO, String& s);
270 ROM_MONO_SAMPLE = 0x8001,
271 ROM_RIGHT_SAMPLE = 0x8002,
272 ROM_LEFT_SAMPLE = 0x8004,
273 ROM_LINKED_SAMPLE = 0x8008
292 NullExtensionSize = 0;
300 String GetName() {
return Name; }
301 int GetChannelCount();
302 long GetTotalFrameCount();
305 bool IsUnpitched() {
return OriginalPitch == 255; }
308 buffer_t LoadSampleData(
unsigned long SampleCount);
309 buffer_t LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);
310 buffer_t LoadSampleDataWithNullSamplesExtension(
unsigned long SampleCount, uint NullSamplesCount);
312 void ReleaseSampleData();
313 unsigned long SetPos(
unsigned long SampleCount);
314 unsigned long GetPos();
315 unsigned long Read(
void* pBuffer,
unsigned long SampleCount);
316 unsigned long ReadNoClear(
void* pBuffer,
unsigned long SampleCount,
buffer_t& tempBuffer);
318 unsigned long ReadAndLoop (
320 unsigned long FrameCount,
338 uint8_t OriginalPitch;
339 uint8_t PitchCorrection;
359 int overridingRootKey;
360 int startAddrsOffset, startAddrsCoarseOffset, endAddrsOffset, endAddrsCoarseOffset;
361 int startloopAddrsOffset, startloopAddrsCoarseOffset, endloopAddrsOffset, endloopAddrsCoarseOffset;
363 int modEnvToPitch , modLfoToPitch, modEnvToFilterFc, modLfoToFilterFc;
364 int modLfoToVolume , freqModLfo ;
366 int vibLfoToPitch, freqVibLfo ;
368 int initialFilterFc , initialFilterQ ;
376 Instrument* pInstrument;
379 Sample* GetSample() {
return pSample; }
380 Region* GetParent() {
return this; }
390 std::vector<ModulatorItem> modulators;
394 int GetPan(
Region* pPresetRegion = NULL);
395 int GetFineTune(
Region* pPresetRegion = NULL);
396 int GetCoarseTune(
Region* pPresetRegion = NULL);
397 double GetEG1PreAttackDelay(
Region* pPresetRegion = NULL);
398 double GetEG1Attack(
Region* pPresetRegion = NULL);
399 double GetEG1Hold(
Region* pPresetRegion = NULL);
400 double GetEG1Decay(
Region* pPresetRegion = NULL);
401 int GetEG1Sustain(
Region* pPresetRegion = NULL);
402 double GetEG1Release(
Region* pPresetRegion = NULL);
404 double GetEG2PreAttackDelay(
Region* pPresetRegion = NULL);
405 double GetEG2Attack(
Region* pPresetRegion = NULL);
406 double GetEG2Hold(
Region* pPresetRegion = NULL);
407 double GetEG2Decay(
Region* pPresetRegion = NULL);
408 int GetEG2Sustain(
Region* pPresetRegion = NULL);
409 double GetEG2Release(
Region* pPresetRegion = NULL);
411 int GetModEnvToPitch(
Region* pPresetRegion = NULL);
412 int GetModLfoToPitch(
Region* pPresetRegion = NULL);
413 int GetModEnvToFilterFc(
Region* pPresetRegion = NULL);
414 int GetModLfoToFilterFc(
Region* pPresetRegion = NULL);
415 double GetModLfoToVolume(
Region* pPresetRegion = NULL);
416 double GetFreqModLfo(
Region* pPresetRegion = NULL);
417 double GetDelayModLfo(
Region* pPresetRegion = NULL);
418 int GetVibLfoToPitch(
Region* pPresetRegion = NULL);
419 double GetFreqVibLfo(
Region* pPresetRegion = NULL);
420 double GetDelayVibLfo(
Region* pPresetRegion = NULL);
421 int GetInitialFilterFc(
Region* pPresetRegion);
422 int GetInitialFilterQ(
Region* pPresetRegion);
424 friend class Instrument;
428 int EG1PreAttackDelay;
435 int EG2PreAttackDelay;
442 Instrument* pParentInstrument;
444 void SetGenerator(sf2::File* pFile, GenList& Gen);
445 void SetModulator(sf2::File* pFile, ModList& Mod);
448 class InstrumentBase {
453 InstrumentBase(sf2::File* pFile);
454 virtual ~InstrumentBase();
456 sf2::File* GetFile() {
return pFile; }
457 String GetName() {
return Name; }
459 int GetRegionCount();
460 Region* GetRegion(
int idx);
463 std::vector<Region*> regions;
472 Query(InstrumentBase& instrument);
476 InstrumentBase& instrument;
480 class Instrument :
public InstrumentBase {
485 void DeleteRegion(
Region* pRegion);
492 void LoadRegions(
int idx1,
int idx2);
497 class Preset :
public InstrumentBase {
510 uint16_t PresetBagNdx;
515 void LoadRegions(
int idx1,
int idx2);
527 int GetPresetCount();
528 Preset* GetPreset(
int idx);
529 int GetInstrumentCount();
530 Instrument* GetInstrument(
int idx);
531 void DeleteInstrument(Instrument* pInstrument);
532 int GetSampleCount();
533 Sample* GetSample(
int idx);
534 void DeleteSample(Sample* pSample);
538 friend class Instrument;
543 std::vector<PresetBag> PresetBags;
544 std::vector<ModList> PresetModLists;
545 std::vector<GenList> PresetGenLists;
546 std::vector<InstBag> InstBags;
547 std::vector<ModList> InstModLists;
548 std::vector<GenList> InstGenLists;
551 std::vector<Preset*> Presets;
552 std::vector<Instrument*> Instruments;
553 std::vector<Sample*> Samples;
560 #endif // __SF2_SF_H__
String libraryVersion()
Returns version of this C++ library.
String libraryName()
Returns the name of this C++ library.
unsigned long position
Current position within the sample.
SoundFont specific classes and definitions.
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...
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...
void * pStart
Points to the beginning of the buffer.
Pointer address and size of a buffer.
Instrument * GetParentInstrument()
Will be thrown whenever an error occurs while handling a RIFF file.
unsigned long Size
Size of the actual data in the buffer in bytes.
bool reverse
If playback direction is currently backwards (in case there is a pingpong or reverse loop defined)...