/[svn]/libgig/trunk/src/gig.h
ViewVC logotype

Diff of /libgig/trunk/src/gig.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 11 by schoenebeck, Sun Nov 16 17:47:00 2003 UTC revision 24 by schoenebeck, Fri Dec 26 16:15:31 2003 UTC
# Line 57  Line 57 
57  #endif // WORDS_BIGENDIAN  #endif // WORDS_BIGENDIAN
58    
59  /** (so far) every exponential paramater in the gig format has a basis of 1.000000008813822 */  /** (so far) every exponential paramater in the gig format has a basis of 1.000000008813822 */
60  #define GIG_EXP_DECODE(x)                       (pow(1.000000008813822, x))  #define GIG_EXP_DECODE(x)                                       (pow(1.000000008813822, x))
61  #define GIG_PITCH_TRACK_EXTRACT(x)              (!(x & 0x01))  #define GIG_PITCH_TRACK_EXTRACT(x)                              (!(x & 0x01))
62  #define GIG_VCF_RESONANCE_CTRL_EXTRACT(x)       ((x >> 4) & 0x03)  #define GIG_VCF_RESONANCE_CTRL_EXTRACT(x)                       ((x >> 4) & 0x03)
63  #define GIG_EG_CTR_ATTACK_INFLUENCE_EXTRACT(x)  ((x >> 1) & 0x03)  #define GIG_EG_CTR_ATTACK_INFLUENCE_EXTRACT(x)                  ((x >> 1) & 0x03)
64  #define GIG_EG_CTR_DECAY_INFLUENCE_EXTRACT(x)   ((x >> 3) & 0x03)  #define GIG_EG_CTR_DECAY_INFLUENCE_EXTRACT(x)                   ((x >> 3) & 0x03)
65  #define GIG_EG_CTR_RELEASE_INFLUENCE_EXTRACT(x) ((x >> 5) & 0x03)  #define GIG_EG_CTR_RELEASE_INFLUENCE_EXTRACT(x)                 ((x >> 5) & 0x03)
66    //TODO: the transformation functions are not very accurate compared to the original ones
67    #define GIG_VELOCITY_TRANSFORM_NONLINEAR(x,dynamic,scale)       ((1.0-1.0/pow(x,1.0/(129.0-x))) * (1.0+scale/20.0) + (5.0-dynamic)*pow(x/300.0* (1.0+2.0*scale/128.0),2))
68    #define GIG_VELOCITY_TRANSFORM_LINEAR(x,dynamic,scale)          ((1.0+scale*3.0/128.0)/110.0*x+(5.0-dynamic)/5.0+(5.0-dynamic)*scale)
69    #define GIG_VELOCITY_TRANSFORM_SPECIAL(x,dynamic,scale)         ((1.0+9.0*scale/129.0)*(1.0-1.0/pow(x,1.0/(129.0-x))+pow(3.0*x/pow(129,2),2)+pow((5.0-dynamic)*x/500.0,2)))
70    
71  /** Gigasampler specific classes and definitions */  /** Gigasampler specific classes and definitions */
72  namespace gig {  namespace gig {
# Line 278  namespace gig { Line 282  namespace gig {
282          #endif // WORDS_BIGENDIAN          #endif // WORDS_BIGENDIAN
283      };      };
284    
285        /** Reflects the current playback state for a sample. */
286        struct playback_state_t {
287            unsigned long position;          ///< Current position within the sample.
288            bool          reverse;           ///< If playback direction is currently backwards (in case there is a pingpong or reverse loop defined).
289            unsigned long loop_cycles_left;  ///< How many times the loop has still to be passed, this value will be decremented with each loop cycle.
290        };
291    
292      // just symbol prototyping      // just symbol prototyping
293      class File;      class File;
294      class Instrument;      class Instrument;
# Line 362  namespace gig { Line 373  namespace gig {
373              // Key Velocity Transformations              // Key Velocity Transformations
374              curve_type_t       VelocityResponseCurve;         ///< Defines a transformation curve to the incoming velocity values affecting amplitude.              curve_type_t       VelocityResponseCurve;         ///< Defines a transformation curve to the incoming velocity values affecting amplitude.
375              uint8_t            VelocityResponseDepth;         ///< Dynamic range of velocity affecting amplitude (0 - 4).              uint8_t            VelocityResponseDepth;         ///< Dynamic range of velocity affecting amplitude (0 - 4).
376              uint8_t            VelocityResponseCurveScaling;              uint8_t            VelocityResponseCurveScaling;  ///< 0 - 127
377              curve_type_t       ReleaseVelocityResponseCurve;  ///< Defines a transformation curve to the incoming release veloctiy values affecting envelope times.              curve_type_t       ReleaseVelocityResponseCurve;  ///< Defines a transformation curve to the incoming release veloctiy values affecting envelope times.
378              uint8_t            ReleaseVelocityResponseDepth;  ///< Dynamic range of release velocity affecting envelope time (0 - 4).              uint8_t            ReleaseVelocityResponseDepth;  ///< Dynamic range of release velocity affecting envelope time (0 - 4).
379              uint8_t            ReleaseTriggerDecay;           ///< 0 - 8              uint8_t            ReleaseTriggerDecay;           ///< 0 - 8
# Line 386  namespace gig { Line 397  namespace gig {
397              DLS::Sampler::SampleLoops;              DLS::Sampler::SampleLoops;
398              DLS::Sampler::pSampleLoops;              DLS::Sampler::pSampleLoops;
399    
400                // Methods
401                double GetVelocityAttenuation(uint8_t MIDIKeyVelocity);
402            protected:
403              DimensionRegion(RIFF::List* _3ewl);              DimensionRegion(RIFF::List* _3ewl);
404               ~DimensionRegion();
405                friend class Region;
406            private:
407                typedef std::map<uint32_t, double*> VelocityTableMap;
408    
409                static uint              Instances;                  ///< Number of DimensionRegion instances.
410                static VelocityTableMap* pVelocityTables;            ///< Contains the tables corresponding to the various velocity parameters (VelocityResponseCurve and VelocityResponseDepth).
411                double*                  pVelocityAttenuationTable;  ///< Points to the velocity table corresponding to the velocity parameters of this DimensionRegion.
412      };      };
413    
414      /** Encapsulates sample waves used for playback. */      /** Encapsulates sample waves used for playback. */
# Line 397  namespace gig { Line 419  namespace gig {
419              uint32_t       Product;           ///< Specifies the MIDI model ID defined by the manufacturer corresponding to the Manufacturer field. If no particular manufacturer's product is to be specified, a value of 0 should be used.              uint32_t       Product;           ///< Specifies the MIDI model ID defined by the manufacturer corresponding to the Manufacturer field. If no particular manufacturer's product is to be specified, a value of 0 should be used.
420              uint32_t       SamplePeriod;      ///< Specifies the duration of time that passes during the playback of one sample in nanoseconds (normally equal to 1 / Samplers Per Second, where Samples Per Second is the value found in the format chunk).              uint32_t       SamplePeriod;      ///< Specifies the duration of time that passes during the playback of one sample in nanoseconds (normally equal to 1 / Samplers Per Second, where Samples Per Second is the value found in the format chunk).
421              uint32_t       MIDIUnityNote;     ///< Specifies the musical note at which the sample will be played at it's original sample rate.              uint32_t       MIDIUnityNote;     ///< Specifies the musical note at which the sample will be played at it's original sample rate.
422              uint32_t       MIDIPitchFraction; ///< Specifies the fraction of a semitone up from the specified MIDI unity note field. A value of 0x80000000 means 1/2 semitone (50 cents) and a value of 0x00000000 means no fine tuning between semitones.              uint32_t       FineTune;          ///< Specifies the fraction of a semitone up from the specified MIDI unity note field. A value of 0x80000000 means 1/2 semitone (50 cents) and a value of 0x00000000 means no fine tuning between semitones.
423              smpte_format_t SMPTEFormat;       ///< Specifies the Society of Motion Pictures and Television E time format used in the following <i>SMPTEOffset</i> field. If a value of 0 is set, <i>SMPTEOffset</i> should also be set to 0.              smpte_format_t SMPTEFormat;       ///< Specifies the Society of Motion Pictures and Television E time format used in the following <i>SMPTEOffset</i> field. If a value of 0 is set, <i>SMPTEOffset</i> should also be set to 0.
424              uint32_t       SMPTEOffset;       ///< The SMPTE Offset value specifies the time offset to be used for the synchronization / calibration to the first sample in the waveform. This value uses a format of 0xhhmmssff where hh is a signed value that specifies the number of hours (-23 to 23), mm is an unsigned value that specifies the number of minutes (0 to 59), ss is an unsigned value that specifies the number of seconds (0 to 59) and ff is an unsigned value that specifies the number of frames (0 to -1).              uint32_t       SMPTEOffset;       ///< The SMPTE Offset value specifies the time offset to be used for the synchronization / calibration to the first sample in the waveform. This value uses a format of 0xhhmmssff where hh is a signed value that specifies the number of hours (-23 to 23), mm is an unsigned value that specifies the number of minutes (0 to 59), ss is an unsigned value that specifies the number of seconds (0 to 59) and ff is an unsigned value that specifies the number of frames (0 to -1).
425              uint32_t       Loops;             ///< Number of defined sample loops (so far only seen single loops in gig files - please report me if you encounter more!).              uint32_t       Loops;             ///< Number of defined sample loops (so far only seen single loops in gig files - please report me if you encounter more!).
426              uint32_t       LoopID;            ///< Specifies the unique ID that corresponds to one of the defined cue points in the cue point list (only if Loops > 0).              uint32_t       LoopID;            ///< Specifies the unique ID that corresponds to one of the defined cue points in the cue point list (only if Loops > 0), as the Gigasampler format only allows one loop definition at the moment, this attribute isn't really useful for anything.
427              loop_type_t    LoopType;          ///< The type field defines how the waveform samples will be looped (only if Loops > 0).              loop_type_t    LoopType;          ///< The type field defines how the waveform samples will be looped (only if Loops > 0).
428              uint32_t       LoopStart;         ///< The start value specifies the byte offset into the waveform data of the first sample to be played in the loop (only if Loops > 0).              uint32_t       LoopStart;         ///< The start value specifies the offset (in sample points) in the waveform data of the first sample to be played in the loop (only if Loops > 0).
429              uint32_t       LoopEnd;           ///< The end value specifies the byte offset into the waveform data of the last sample to be played in the loop (only if Loops > 0).              uint32_t       LoopEnd;           ///< The end value specifies the offset (in sample points) in the waveform data which represents the end of the loop (only if Loops > 0).
430                uint32_t       LoopSize;          ///< Length of the looping area (in sample points) which is equivalent to <i>LoopEnd - LoopStart</i>.
431              uint32_t       LoopFraction;      ///< The fractional value specifies a fraction of a sample at which to loop (only if Loops > 0). This allows a loop to be fine tuned at a resolution greater than one sample. A value of 0 means no fraction, a value of 0x80000000 means 1/2 of a sample length. 0xFFFFFFFF is the smallest fraction of a sample that can be represented.              uint32_t       LoopFraction;      ///< The fractional value specifies a fraction of a sample at which to loop (only if Loops > 0). This allows a loop to be fine tuned at a resolution greater than one sample. A value of 0 means no fraction, a value of 0x80000000 means 1/2 of a sample length. 0xFFFFFFFF is the smallest fraction of a sample that can be represented.
432              uint32_t       LoopPlayCount;     ///< Number of times the loop should be played (only if Loops > 0, a value of 0 = infinite).              uint32_t       LoopPlayCount;     ///< Number of times the loop should be played (only if Loops > 0, a value of 0 = infinite).
433              bool           Compressed;        ///< If the sample wave is compressed (probably just interesting for instrument and sample editors, as this library already handles the decompression in it's sample access methods anyway).              bool           Compressed;        ///< If the sample wave is compressed (probably just interesting for instrument and sample editors, as this library already handles the decompression in it's sample access methods anyway).
# Line 420  namespace gig { Line 443  namespace gig {
443              unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start);              unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start);
444              unsigned long GetPos();              unsigned long GetPos();
445              unsigned long Read(void* pBuffer, unsigned long SampleCount);              unsigned long Read(void* pBuffer, unsigned long SampleCount);
446                unsigned long ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState);
447          protected:          protected:
448              static unsigned int  Instances;               ///< Number of instances of class Sample.              static unsigned int  Instances;               ///< Number of instances of class Sample.
449              static unsigned long DecompressionBufferSize; ///< Current size of the decompression buffer.              static unsigned long DecompressionBufferSize; ///< Current size of the decompression buffer.
# Line 431  namespace gig { Line 455  namespace gig {
455    
456              Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset);              Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset);
457             ~Sample();             ~Sample();
458                /**
459                 * Swaps the order of the data words in the given memory area
460                 * with a granularity given by \a WordSize.
461                 *
462                 * @param pData    - pointer to the memory area to be swapped
463                 * @param AreaSize - size of the memory area to be swapped (in bytes)
464                 * @param WordSize - size of the data words (in bytes)
465                 */
466                inline void SwapMemoryArea(void* pData, unsigned long AreaSize, uint WordSize) {
467                    switch (WordSize) { // TODO: unefficient
468                        case 1: {
469                            uint8_t* pDst = (uint8_t*) pData;
470                            uint8_t  cache;
471                            unsigned long lo = 0, hi = AreaSize - 1;
472                            for (; lo < hi; hi--, lo++) {
473                                cache    = pDst[lo];
474                                pDst[lo] = pDst[hi];
475                                pDst[hi] = cache;
476                            }
477                            break;
478                        }
479                        case 2: {
480                            uint16_t* pDst = (uint16_t*) pData;
481                            uint16_t  cache;
482                            unsigned long lo = 0, hi = (AreaSize >> 1) - 1;
483                            for (; lo < hi; hi--, lo++) {
484                                cache    = pDst[lo];
485                                pDst[lo] = pDst[hi];
486                                pDst[hi] = cache;
487                            }
488                            break;
489                        }
490                        case 4: {
491                            uint32_t* pDst = (uint32_t*) pData;
492                            uint32_t  cache;
493                            unsigned long lo = 0, hi = (AreaSize >> 2) - 1;
494                            for (; lo < hi; hi--, lo++) {
495                                cache    = pDst[lo];
496                                pDst[lo] = pDst[hi];
497                                pDst[hi] = cache;
498                            }
499                            break;
500                        }
501                        default: {
502                            uint8_t* pCache = new uint8_t[WordSize]; // TODO: unefficient
503                            unsigned long lo = 0, hi = AreaSize - WordSize;
504                            for (; lo < hi; hi -= WordSize, lo += WordSize) {
505                                memcpy(pCache, (uint8_t*) pData + lo, WordSize);
506                                memcpy((uint8_t*) pData + lo, (uint8_t*) pData + hi, WordSize);
507                                memcpy((uint8_t*) pData + hi, pCache, WordSize);
508                            }
509                            delete[] pCache;
510                            break;
511                        }
512                    }
513                }
514                inline long Min(long A, long B) {
515                    return (A > B) ? B : A;
516                }
517                inline long Abs(long val) { return (val > 0) ? val : -val; }
518          private:          private:
519              void ScanCompressedSample();              void ScanCompressedSample();
520              friend class File;              friend class File;
# Line 517  namespace gig { Line 601  namespace gig {
601              Sample*     GetNextSample();      ///< Returns a pointer to the next <i>Sample</i> object of the file, <i>NULL</i> otherwise.              Sample*     GetNextSample();      ///< Returns a pointer to the next <i>Sample</i> object of the file, <i>NULL</i> otherwise.
602              Instrument* GetFirstInstrument(); ///< Returns a pointer to the first <i>Instrument</i> object of the file, <i>NULL</i> otherwise.              Instrument* GetFirstInstrument(); ///< Returns a pointer to the first <i>Instrument</i> object of the file, <i>NULL</i> otherwise.
603              Instrument* GetNextInstrument();  ///< Returns a pointer to the next <i>Instrument</i> object of the file, <i>NULL</i> otherwise.              Instrument* GetNextInstrument();  ///< Returns a pointer to the next <i>Instrument</i> object of the file, <i>NULL</i> otherwise.
604                Instrument* GetInstrument(uint index);
605             ~File() {};             ~File() {};
606          protected:          protected:
607              typedef std::list<Sample*>     SampleList;              typedef std::list<Sample*>     SampleList;

Legend:
Removed from v.11  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC