This file is indexed.

/usr/include/libgig/SF.h is in libgig-dev 4.1.0~repack-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/***************************************************************************
 *                                                                         *
 *   libsf2 - C++ cross-platform SF2 format file access library            *
 *                                                                         *
 *   Copyright (C) 2009-2010 by Grigor Iliev  <grigor@grigoriliev.com>     *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This library is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this library; if not, write to the Free Software           *
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
 *   MA  02111-1307  USA                                                   *
 ***************************************************************************/

#ifndef __SF2_SF_H__
#define __SF2_SF_H__

#include "RIFF.h"

#include <vector>


#define RIFF_ID(x) (*((uint32_t*) x))


#define RIFF_TYPE_SF2   RIFF_ID("sfbk")

// Level 0
#define LIST_TYPE_SDTA  RIFF_ID("sdta")
#define LIST_TYPE_PDTA  RIFF_ID("pdta")

// Level 1
//<INFO-list>
#define CHUNK_ID_IFIL   RIFF_ID("ifil")
#define CHUNK_ID_ISNG   RIFF_ID("isng")
#define CHUNK_ID_IROM   RIFF_ID("irom")
#define CHUNK_ID_IVER   RIFF_ID("iver")

//<sdta-list>
#define CHUNK_ID_SM24   RIFF_ID("sm24")

//<pdta-list>
#define CHUNK_ID_PHDR   RIFF_ID("phdr")
#define CHUNK_ID_PBAG   RIFF_ID("pbag")
#define CHUNK_ID_PMOD   RIFF_ID("pmod")
#define CHUNK_ID_PGEN   RIFF_ID("pgen")
#define CHUNK_ID_INST   RIFF_ID("inst")
#define CHUNK_ID_IBAG   RIFF_ID("ibag")
#define CHUNK_ID_IMOD   RIFF_ID("imod")
#define CHUNK_ID_IGEN   RIFF_ID("igen")
#define CHUNK_ID_SHDR   RIFF_ID("shdr")

/** SoundFont specific classes and definitions */
namespace sf2 {

    static uint NONE = 0x1ffffff;

    double ToSeconds(int Timecents);
    double ToRatio(int Centibels);
    double ToHz(int cents);

    typedef struct _PresetBag {
        uint16_t GenNdx;
        uint16_t ModNdx;
    } PresetBag;

    typedef uint16_t SFModulator;
    typedef uint16_t SFGenerator;
    typedef uint16_t SFTransform;

    typedef struct _ModList {
        SFModulator  ModSrcOper;
        SFGenerator  ModDestOper;
        uint16_t     ModAmount;
        SFModulator  ModAmtSrcOper;
        SFTransform  ModTransOper;
    } ModList;

    typedef struct _RangesType {
        #if WORDS_BIGENDIAN
        uint8_t byHi;
        uint8_t byLo;
        #else
        uint8_t byLo;
        uint8_t byHi;
        #endif
    } RangesType;

    typedef union _GenAmountType {
        RangesType  ranges;
        short       shAmount;
        uint16_t    wAmount;
    } GenAmountType;

    typedef struct _GenList {
        SFGenerator    GenOper;
        GenAmountType  GenAmount;
    } GenList;

    typedef struct _InstBag {
        uint16_t InstGenNdx;
        uint16_t InstModNdx;
    } InstBag;

    typedef enum {
        START_ADDRS_OFFSET = 0,
        END_ADDRS_OFFSET,
        STARTLOOP_ADDRS_OFFSET,
        ENDLOOP_ADDRS_OFFSET ,
        START_ADDRS_COARSE_OFFSET,
        MOD_LFO_TO_PITCH,
        VIB_LFO_TO_PITCH,
        MOD_ENV_TO_PITCH,
        INITIAL_FILTER_FC,
        INITIAL_FILTER_Q,
        MOD_LFO_TO_FILTER_FC, // 10
        MOD_ENV_TO_FILTER_FC,
        END_ADDRS_COARSE_OFFSET,
        MOD_LFO_TO_VOLUME,
        UNUSED1,
        CHORUS_EFFECTS_SEND,
        REVERB_EFFECTS_SEND,
        PAN,
        UNUSED2,
        UNUSED3,
        UNUSED4, //20
        DELAY_MOD_LFO,
        FREQ_MOD_LFO,
        DELAY_VIB_LFO,
        FREQ_VIB_LFO,
        DELAY_MOD_ENV,
        ATTACK_MOD_ENV,
        HOLD_MOD_ENV,
        DECAY_MOD_ENV,
        SUSTAIN_MOD_ENV,
        RELEASE_MOD_ENV, // 30
        KEYNUM_TO_MOD_ENV_HOLD,
        KEYNUM_TO_MOD_ENV_DECAY,
        DELAY_VOL_ENV,
        ATTACK_VOL_ENV,
        HOLD_VOL_ENV,
        DECAY_VOL_ENV,
        SUSTAIN_VOL_ENV,
        RELEASE_VOL_ENV,
        KEYNUM_TO_VOL_ENV_HOLD,
        KEYNUM_TO_VOL_ENV_DECAY, //40
        INSTRUMENT,
        RESERVED1,
        KEY_RANGE,
        VEL_RANGE,
        STARTLOOP_ADDRS_COARSE_OFFSET,
        KEYNUM,
        VELOCITY,
        INITIAL_ATTENUATION,
        RESERVED2,
        ENDLOOP_ADDRS_COARSE_OFFSET, // 50
        COARSE_TUNE,
        FINE_TUNE,
        SAMPLE_ID,
        SAMPLE_MODES,
        RESERVED3,
        SCALE_TUNING,
        EXCLUSIVE_CLASS,
        OVERRIDING_ROOT_KEY,
        UNUSED5,
        END_OPER
    } SFGeneratorType;

    class Modulator {
        public:

            /**
             * General Controller palette of controllers.
             * Controller sources.
             */
            enum {
                NO_CONTROLLER = 0,
                NOTE_ON_VELOCITY = 2,
                NOTE_ON_KEY_NUMBER = 3,
                POLY_PRESSURE = 10,
                CHANNEL_PRESSURE = 13,
                PITCH_WHEEL = 14,
                PITCH_WHEEL_SENSITIVITY = 16,
                LINK = 127
            };

            /**
             * Controller type
             */
            enum {
                LINEAR = 0,
                CONCAVE,
                CONVEX,
                SWITCH
            };

            int  Type;
            bool MidiPalete;
            bool Direction;
            bool Polarity;
            int  Index;

            Modulator(SFModulator mod);
    };

    class ModulatorItem {
        public:
            Modulator    ModSrcOper;
            SFGenerator  ModDestOper;
            uint16_t     ModAmount;
            Modulator    ModAmtSrcOper;
            SFTransform  ModTransOper;

            ModulatorItem(ModList& mod);
    };


    typedef std::string String;

    class Exception : public RIFF::Exception {
        public: Exception(String Message) : RIFF::Exception(Message) { }
    };

    class Version {
        public:
            int Major;
            int Minor;

            Version(RIFF::Chunk* ck);
    };

    class Info {
        public:
            Version*  pVer;          ///< <ifil-ck>   ; Refers to the version of the Sound Font RIFF file
            String    SoundEngine;   ///< <isng-ck>   ; Refers to the target Sound Engine
            String    BankName;      ///< <INAM-ck>   ; Refers to the Sound Font Bank Name
            String    RomName;       ///< [<irom-ck>] ; Refers to the Sound ROM Name
            Version*  pRomVer;       ///< [<iver-ck>] ; Refers to the Sound ROM Version
            String    CreationDate;  ///< [<ICRD-ck>] ; Refers to the Date of Creation of the Bank
            String    Engineers;     ///< [<IENG-ck>] ; Sound Designers and Engineers for the Bank
            String    Product;       ///< [<IPRD-ck>] ; Product for which the Bank was intended
            String    Copyright;     ///< [<ICOP-ck>] ; Contains any Copyright message
            String    Comments;      ///< [<ICMT-ck>] ; Contains any Comments on the Bank
            String    Software;      ///< [<ISFT-ck>] ; The SoundFont tools used to create and alter the bank

            Info(RIFF::List* list);
            ~Info();
        private:
            static void LoadString(uint32_t ChunkID, RIFF::List* lstINFO, String& s);
    };

    class Region;

    class Sample {
        public:

            typedef enum {
                MONO_SAMPLE       = 1,
                RIGHT_SAMPLE      = 2,
                LEFT_SAMPLE       = 4,
                LINKED_SAMPLE     = 8,
                ROM_MONO_SAMPLE   = 0x8001,
                ROM_RIGHT_SAMPLE  = 0x8002,
                ROM_LEFT_SAMPLE   = 0x8004,
                ROM_LINKED_SAMPLE = 0x8008
            } Link;

            /** Reflects the current playback state for a sample. */
            class PlaybackState {
                public:
                    unsigned long position;          ///< Current position within the sample.
                    bool          reverse;           ///< If playback direction is currently backwards (in case there is a pingpong or reverse loop defined).
                    unsigned long loop_cycles_left;  ///< How many times the loop has still to be passed, this value will be decremented with each loop cycle.
            };

            /** Pointer address and size of a buffer. */
            struct buffer_t {
                void*         pStart;            ///< Points to the beginning of the buffer.
                unsigned long Size;              ///< Size of the actual data in the buffer in bytes.
                unsigned long NullExtensionSize; ///< The buffer might be bigger than the actual data, if that's the case that unused space at the end of the buffer is filled with NULLs and NullExtensionSize reflects that unused buffer space in bytes. Those NULL extensions are mandatory for differential algorithms that have to take the following data words into account, thus have to access past the buffer's boundary. If you don't know what I'm talking about, just forget this variable. :)
                buffer_t() {
                    pStart            = NULL;
                    Size              = 0;
                    NullExtensionSize = 0;
                }
            };

            String Name;

            Sample(RIFF::Chunk* ck, RIFF::Chunk* pCkSmpl, RIFF::Chunk* pCkSm24);

            String  GetName() { return Name; }
            int     GetChannelCount();
            long    GetTotalFrameCount();
            int     GetFrameSize();
            bool    HasLoops();
            bool    IsUnpitched() { return OriginalPitch == 255; }

            buffer_t  LoadSampleData();
            buffer_t  LoadSampleData(unsigned long SampleCount);
            buffer_t  LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);
            buffer_t  LoadSampleDataWithNullSamplesExtension(unsigned long SampleCount, uint NullSamplesCount);
            buffer_t  GetCache();
            void      ReleaseSampleData();
            unsigned long SetPos(unsigned long SampleCount);
            unsigned long GetPos();
            unsigned long Read(void* pBuffer, unsigned long SampleCount);
            unsigned long ReadNoClear(void* pBuffer, unsigned long SampleCount, buffer_t& tempBuffer);

            unsigned long ReadAndLoop (
                void*           pBuffer,
                unsigned long   FrameCount,
                PlaybackState*  pPlaybackState,
                Region*         pRegion
            );

        //protected:
            buffer_t      RAMCache;   ///< Buffers samples (already uncompressed) in RAM.
            RIFF::Chunk*  pCkSmpl;
            RIFF::Chunk*  pCkSm24;

        //private:
            int ChannelCount; // 2 for left and right samples

            uint32_t Start;     // in sample data points (frames) from the begining of the sample data field
            uint32_t End;       // in sample data points (frames) from the begining of the sample data field
            uint32_t StartLoop; // in sample data points (frames) from the begining of the sample data field
            uint32_t EndLoop;   // in sample data points (frames) from the begining of the sample data field
            uint32_t SampleRate;
            uint8_t  OriginalPitch;
            uint8_t  PitchCorrection;
            uint16_t SampleLink; /* If sfSampleType indicates a left or right sample, the
                                  * sample header index of the associated right or left stereo
                                  * sample respectively; zero otherwise. */
            uint16_t SampleType;
    };

    class File;
    class Instrument;

    /**
     * Instrument zone
     */
    class Region {
        public:
            int loKey, hiKey;
            int minVel, maxVel;
            int pan; // -64 - +63
            int fineTune; // -99 - +99
            int coarseTune; // TODO:
            int overridingRootKey; // represents the MIDI key number at which the sample is to be played back at its original sample rate.
            int startAddrsOffset, startAddrsCoarseOffset, endAddrsOffset, endAddrsCoarseOffset;
            int startloopAddrsOffset, startloopAddrsCoarseOffset, endloopAddrsOffset, endloopAddrsCoarseOffset;

            int modEnvToPitch , modLfoToPitch, modEnvToFilterFc, modLfoToFilterFc; // in cents
            int modLfoToVolume /* in centibels */, freqModLfo /* in absolute cents */;
            int delayModLfo; // in absolute timecents
            int vibLfoToPitch, freqVibLfo /* in absolute cents */;
            int delayVibLfo; // in absolute timecents
            int initialFilterFc  /* in absolute cents */, initialFilterQ /* in centibels */;

            uint exclusiveClass; // exclusive group

            Sample* pSample;
            bool    HasLoop;
            uint    LoopStart; // index (in frames) from the beginning of the sample
            uint    LoopEnd;   // index (in frames) from the beginning of the sample
            Instrument* pInstrument; // used when the region belongs to preset

            Region();
            Sample* GetSample() { return pSample; }
            Region* GetParent() { return this; }

            int GetUnityNote();

            /**
             * @returns The instrument to which this region belongs, or
             * NULL if it's preset region.
             */
            Instrument* GetParentInstrument() { return pParentInstrument; }

            std::vector<ModulatorItem> modulators;


            // Instrument can be referenced by more than one presets so we need to calculate values on the fly
            int    GetPan(Region* pPresetRegion = NULL); // -64 - +63
            int    GetFineTune(Region* pPresetRegion = NULL); // -99 - +99
            int    GetCoarseTune(Region* pPresetRegion = NULL); // -120 - +120
            double GetEG1PreAttackDelay(Region* pPresetRegion = NULL); // in seconds
            double GetEG1Attack(Region* pPresetRegion = NULL); // in seconds
            double GetEG1Hold(Region* pPresetRegion = NULL); // in seconds
            double GetEG1Decay(Region* pPresetRegion = NULL); // in seconds
            int    GetEG1Sustain(Region* pPresetRegion = NULL); // Sustain value of the sample amplitude EG (the decrease in level, expressed in centibels)
            double GetEG1Release(Region* pPresetRegion = NULL); // in seconds

            double GetEG2PreAttackDelay(Region* pPresetRegion = NULL); // in seconds
            double GetEG2Attack(Region* pPresetRegion = NULL); // in seconds
            double GetEG2Hold(Region* pPresetRegion = NULL); // in seconds
            double GetEG2Decay(Region* pPresetRegion = NULL); // in seconds
            int    GetEG2Sustain(Region* pPresetRegion = NULL); // Sustain value of the filter cutoff EG (in permilles)
            double GetEG2Release(Region* pPresetRegion = NULL); // in seconds

            int    GetModEnvToPitch(Region* pPresetRegion = NULL); // in cents
            int    GetModLfoToPitch(Region* pPresetRegion = NULL); // in cents
            int    GetModEnvToFilterFc(Region* pPresetRegion = NULL); // in cents
            int    GetModLfoToFilterFc(Region* pPresetRegion = NULL); // in cents
            double GetModLfoToVolume(Region* pPresetRegion = NULL); // in centibels
            double GetFreqModLfo(Region* pPresetRegion = NULL); // in Hz
            double GetDelayModLfo(Region* pPresetRegion = NULL); // in seconds
            int    GetVibLfoToPitch(Region* pPresetRegion = NULL); // in cents
            double GetFreqVibLfo(Region* pPresetRegion = NULL); // in Hz
            double GetDelayVibLfo(Region* pPresetRegion = NULL); // in seconds
            int    GetInitialFilterFc(Region* pPresetRegion); // in absolute cents
            int    GetInitialFilterQ(Region* pPresetRegion); // in centibels

            friend class Instrument;
            friend class Preset;

        private:
            int EG1PreAttackDelay; // in timecents
            int EG1Attack; // in timecents
            int EG1Hold; // in timecents
            int EG1Decay; // in timecents
            int EG1Sustain; // Sustain value (the decrease in level, expressed in centibels)
            int EG1Release; // in timecents

            int EG2PreAttackDelay; // in timecents
            int EG2Attack; // in timecents
            int EG2Hold; // in timecents
            int EG2Decay; // in timecents
            int EG2Sustain; // Sustain value of the filter cutoff EG (in permilles)
            int EG2Release; // in timecents

            Instrument* pParentInstrument;

            void SetGenerator(sf2::File* pFile, GenList& Gen);
            void SetModulator(sf2::File* pFile, ModList& Mod);
    };

    class InstrumentBase {
        public:
            String   Name;
            Region*  pGlobalRegion;

            InstrumentBase(sf2::File* pFile);
            virtual ~InstrumentBase();

            sf2::File* GetFile() { return pFile; }
            String     GetName() { return Name; }

            int      GetRegionCount();
            Region*  GetRegion(int idx);

        protected:
            std::vector<Region*> regions;
            sf2::File* pFile;
    };

    class Query {
        public:
            int key;
            uint8_t vel;

            Query(InstrumentBase& instrument);
            Region* next();

        private:
            InstrumentBase& instrument;
            int i;
    };

    class Instrument : public InstrumentBase {
        public:
            Instrument(sf2::File* pFile, RIFF::Chunk* ck);
            ~Instrument();

            void DeleteRegion(Region* pRegion);
        //private:
            uint16_t InstBagNdx;

            /**
             * Load all regions (zones, bags) in the range idx1 - idx2
             */
            void LoadRegions(int idx1, int idx2);

            Region* CreateRegion();
    };

    class Preset : public InstrumentBase {
        public:
            uint16_t  PresetNum;
            uint16_t  Bank;
            uint32_t  Library;
            uint32_t  Genre;
            uint32_t  Morphology;

            Preset(sf2::File* pFile, RIFF::Chunk* ck);
            ~Preset();

        //private:
            sf2::File*  pFile;
            uint16_t    PresetBagNdx;

            /**
             * Load all regions (zones, bags) in the range idx1 - idx2
             */
            void LoadRegions(int idx1, int idx2);

            Region* CreateRegion();
    };

    class File {
        public:
            Info* pInfo;

            File(RIFF::File* pRIFF);
            ~File();

            int          GetPresetCount();
            Preset*      GetPreset(int idx);
            int          GetInstrumentCount();
            Instrument*  GetInstrument(int idx);
            void         DeleteInstrument(Instrument* pInstrument);
            int          GetSampleCount();
            Sample*      GetSample(int idx);
            void         DeleteSample(Sample* pSample);
            bool         HasSamples();

            friend class Region;
            friend class Instrument;
            friend class Preset;

        protected:
            RIFF::File*             pRIFF;
            std::vector<PresetBag>  PresetBags;
            std::vector<ModList>    PresetModLists;
            std::vector<GenList>    PresetGenLists;
            std::vector<InstBag>    InstBags;
            std::vector<ModList>    InstModLists;
            std::vector<GenList>    InstGenLists;

        private:
            std::vector<Preset*> Presets;
            std::vector<Instrument*> Instruments;
            std::vector<Sample*> Samples;
    };

    String libraryName();
    String libraryVersion();

} // namespace sf2
#endif // __SF2_SF_H__