/[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 2762 by schoenebeck, Sat May 2 11:32:27 2015 UTC revision 3140 by schoenebeck, Wed May 3 16:19:53 2017 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file access library    *   *   libgig - C++ cross-platform Gigasampler format file access library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2015 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2017 by Christian Schoenebeck                      *
6   *                              <cuse@users.sourceforge.net>               *   *                              <cuse@users.sourceforge.net>               *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
# Line 65  Line 65 
65  # define CHUNK_ID_SCSL  0x4c534353 // own gig format extension  # define CHUNK_ID_SCSL  0x4c534353 // own gig format extension
66  #endif // WORDS_BIGENDIAN  #endif // WORDS_BIGENDIAN
67    
68    // just symbol prototyping (since Serialization.h not included by default here)
69    namespace Serialization { class Archive; }
70    
71  /** Gigasampler/GigaStudio specific classes and definitions */  /** Gigasampler/GigaStudio specific classes and definitions */
72  namespace gig {  namespace gig {
73    
74      typedef std::string String;      typedef std::string String;
75      typedef RIFF::progress_t progress_t;      typedef RIFF::progress_t progress_t;
76        typedef RIFF::file_offset_t file_offset_t;
77    
78      /** Lower and upper limit of a range. */      /** Lower and upper limit of a range. */
79      struct range_t {      struct range_t {
# Line 80  namespace gig { Line 84  namespace gig {
84      /** Pointer address and size of a buffer. */      /** Pointer address and size of a buffer. */
85      struct buffer_t {      struct buffer_t {
86          void*         pStart;            ///< Points to the beginning of the buffer.          void*         pStart;            ///< Points to the beginning of the buffer.
87          unsigned long Size;              ///< Size of the actual data in the buffer in bytes.          file_offset_t Size;              ///< Size of the actual data in the buffer in bytes.
88          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. :)          file_offset_t 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. :)
89          buffer_t() {          buffer_t() {
90              pStart            = NULL;              pStart            = NULL;
91              Size              = 0;              Size              = 0;
# Line 190  namespace gig { Line 194  namespace gig {
194    
195          type_t type;              ///< Controller type          type_t type;              ///< Controller type
196          uint   controller_number; ///< MIDI controller number if this controller is a control change controller, 0 otherwise          uint   controller_number; ///< MIDI controller number if this controller is a control change controller, 0 otherwise
197    
198            void serialize(Serialization::Archive* archive);
199      };      };
200    
201      /**      /**
# Line 303  namespace gig { Line 309  namespace gig {
309          uint8_t out_start;  ///< Start position of fade out.          uint8_t out_start;  ///< Start position of fade out.
310          uint8_t out_end;    ///< End postition of fade out.          uint8_t out_end;    ///< End postition of fade out.
311          #endif // WORDS_BIGENDIAN          #endif // WORDS_BIGENDIAN
312    
313            void serialize(Serialization::Archive* archive);
314      };      };
315    
316      /** Reflects the current playback state for a sample. */      /** Reflects the current playback state for a sample. */
317      struct playback_state_t {      struct playback_state_t {
318          unsigned long position;          ///< Current position within the sample.          file_offset_t position;          ///< Current position within the sample.
319          bool          reverse;           ///< If playback direction is currently backwards (in case there is a pingpong or reverse loop defined).          bool          reverse;           ///< If playback direction is currently backwards (in case there is a pingpong or reverse loop defined).
320          unsigned long loop_cycles_left;  ///< How many times the loop has still to be passed, this value will be decremented with each loop cycle.          file_offset_t loop_cycles_left;  ///< How many times the loop has still to be passed, this value will be decremented with each loop cycle.
321      };      };
322    
323      // just symbol prototyping      // just symbol prototyping
# Line 485  namespace gig { Line 493  namespace gig {
493              DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src);              DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src);
494             ~DimensionRegion();             ~DimensionRegion();
495              void CopyAssign(const DimensionRegion* orig, const std::map<Sample*,Sample*>* mSamples);              void CopyAssign(const DimensionRegion* orig, const std::map<Sample*,Sample*>* mSamples);
496                void serialize(Serialization::Archive* archive);
497              friend class Region;              friend class Region;
498                friend class Serialization::Archive;
499          private:          private:
500              typedef enum { ///< Used to decode attenuation, EG1 and EG2 controller              typedef enum { ///< Used to decode attenuation, EG1 and EG2 controller
501                  // official leverage controllers as they were defined in the original Gigasampler/GigaStudio format:                  // official leverage controllers as they were defined in the original Gigasampler/GigaStudio format:
# Line 588  namespace gig { Line 598  namespace gig {
598              } _lev_ctrl_t;              } _lev_ctrl_t;
599              typedef std::map<uint32_t, double*> VelocityTableMap;              typedef std::map<uint32_t, double*> VelocityTableMap;
600    
601              static uint              Instances;                  ///< Number of DimensionRegion instances.              static size_t            Instances;                  ///< Number of DimensionRegion instances.
602              static VelocityTableMap* pVelocityTables;            ///< Contains the tables corresponding to the various velocity parameters (VelocityResponseCurve and VelocityResponseDepth).              static VelocityTableMap* pVelocityTables;            ///< Contains the tables corresponding to the various velocity parameters (VelocityResponseCurve and VelocityResponseDepth).
603              double*                  pVelocityAttenuationTable;  ///< Points to the velocity table corresponding to the velocity parameters of this DimensionRegion.              double*                  pVelocityAttenuationTable;  ///< Points to the velocity table corresponding to the velocity parameters of this DimensionRegion.
604              double*                  pVelocityReleaseTable;      ///< Points to the velocity table corresponding to the release velocity parameters of this DimensionRegion              double*                  pVelocityReleaseTable;      ///< Points to the velocity table corresponding to the release velocity parameters of this DimensionRegion
# Line 651  namespace gig { Line 661  namespace gig {
661    
662              // own methods              // own methods
663              buffer_t      LoadSampleData();              buffer_t      LoadSampleData();
664              buffer_t      LoadSampleData(unsigned long SampleCount);              buffer_t      LoadSampleData(file_offset_t SampleCount);
665              buffer_t      LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);              buffer_t      LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);
666              buffer_t      LoadSampleDataWithNullSamplesExtension(unsigned long SampleCount, uint NullSamplesCount);              buffer_t      LoadSampleDataWithNullSamplesExtension(file_offset_t SampleCount, uint NullSamplesCount);
667              buffer_t      GetCache();              buffer_t      GetCache();
668              // own static methods              // own static methods
669              static buffer_t CreateDecompressionBuffer(unsigned long MaxReadSize);              static buffer_t CreateDecompressionBuffer(file_offset_t MaxReadSize);
670              static void     DestroyDecompressionBuffer(buffer_t& DecompressionBuffer);              static void     DestroyDecompressionBuffer(buffer_t& DecompressionBuffer);
671              // overridden methods              // overridden methods
672              void          ReleaseSampleData();              void          ReleaseSampleData();
673              void          Resize(int iNewSize);              void          Resize(file_offset_t NewSize);
674              unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start);              file_offset_t SetPos(file_offset_t SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start);
675              unsigned long GetPos() const;              file_offset_t GetPos() const;
676              unsigned long Read(void* pBuffer, unsigned long SampleCount, buffer_t* pExternalDecompressionBuffer = NULL);              file_offset_t Read(void* pBuffer, file_offset_t SampleCount, buffer_t* pExternalDecompressionBuffer = NULL);
677              unsigned long ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer = NULL);              file_offset_t ReadAndLoop(void* pBuffer, file_offset_t SampleCount, playback_state_t* pPlaybackState, DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer = NULL);
678              unsigned long Write(void* pBuffer, unsigned long SampleCount);              file_offset_t Write(void* pBuffer, file_offset_t SampleCount);
679              Group*        GetGroup() const;              Group*        GetGroup() const;
680              virtual void  UpdateChunks(progress_t* pProgress);              virtual void  UpdateChunks(progress_t* pProgress);
681              void CopyAssignMeta(const Sample* orig);              void CopyAssignMeta(const Sample* orig);
682              void CopyAssignWave(const Sample* orig);              void CopyAssignWave(const Sample* orig);
683                uint32_t GetWaveDataCRC32Checksum();
684                bool VerifyWaveData(uint32_t* pActually = NULL);
685          protected:          protected:
686              static unsigned int  Instances;               ///< Number of instances of class Sample.              static size_t        Instances;               ///< Number of instances of class Sample.
687              static buffer_t      InternalDecompressionBuffer; ///< Buffer used for decompression as well as for truncation of 24 Bit -> 16 Bit samples.              static buffer_t      InternalDecompressionBuffer; ///< Buffer used for decompression as well as for truncation of 24 Bit -> 16 Bit samples.
688              Group*               pGroup;                  ///< pointer to the Group this sample belongs to (always not-NULL)              Group*               pGroup;                  ///< pointer to the Group this sample belongs to (always not-NULL)
689              unsigned long        FrameOffset;             ///< Current offset (sample points) in current sample frame (for decompression only).              file_offset_t        FrameOffset;             ///< Current offset (sample points) in current sample frame (for decompression only).
690              unsigned long*       FrameTable;              ///< For positioning within compressed samples only: stores the offset values for each frame.              file_offset_t*       FrameTable;              ///< For positioning within compressed samples only: stores the offset values for each frame.
691              unsigned long        SamplePos;               ///< For compressed samples only: stores the current position (in sample points).              file_offset_t        SamplePos;               ///< For compressed samples only: stores the current position (in sample points).
692              unsigned long        SamplesInLastFrame;      ///< For compressed samples only: length of the last sample frame.              file_offset_t        SamplesInLastFrame;      ///< For compressed samples only: length of the last sample frame.
693              unsigned long        WorstCaseFrameSize;      ///< For compressed samples only: size (in bytes) of the largest possible sample frame.              file_offset_t        WorstCaseFrameSize;      ///< For compressed samples only: size (in bytes) of the largest possible sample frame.
694              unsigned long        SamplesPerFrame;         ///< For compressed samples only: number of samples in a full sample frame.              file_offset_t        SamplesPerFrame;         ///< For compressed samples only: number of samples in a full sample frame.
695              buffer_t             RAMCache;                ///< Buffers samples (already uncompressed) in RAM.              buffer_t             RAMCache;                ///< Buffers samples (already uncompressed) in RAM.
696              unsigned long        FileNo;                  ///< File number (> 0 when sample is stored in an extension file, 0 when it's in the gig)              unsigned long        FileNo;                  ///< File number (> 0 when sample is stored in an extension file, 0 when it's in the gig)
697              RIFF::Chunk*         pCk3gix;              RIFF::Chunk*         pCk3gix;
698              RIFF::Chunk*         pCkSmpl;              RIFF::Chunk*         pCkSmpl;
699              uint32_t             crc;                     ///< CRC-32 checksum of the raw sample data              uint32_t             crc;                     ///< Reflects CRC-32 checksum of the raw sample data at the last time when the sample's raw wave form data has been modified consciously by the user by calling Write().
700    
701              Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo = 0);              Sample(File* pFile, RIFF::List* waveList, file_offset_t WavePoolOffset, unsigned long fileNo = 0, int index = -1);
702             ~Sample();             ~Sample();
703                uint32_t CalculateWaveDataChecksum();
704    
705              // Guess size (in bytes) of a compressed sample              // Guess size (in bytes) of a compressed sample
706              inline unsigned long GuessSize(unsigned long samples) {              inline file_offset_t GuessSize(file_offset_t samples) {
707                  // 16 bit: assume all frames are compressed - 1 byte                  // 16 bit: assume all frames are compressed - 1 byte
708                  // per sample and 5 bytes header per 2048 samples                  // per sample and 5 bytes header per 2048 samples
709    
710                  // 24 bit: assume next best compression rate - 1.5                  // 24 bit: assume next best compression rate - 1.5
711                  // bytes per sample and 13 bytes header per 256                  // bytes per sample and 13 bytes header per 256
712                  // samples                  // samples
713                  const unsigned long size =                  const file_offset_t size =
714                      BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13                      BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13
715                                     : samples + (samples >> 10) * 5;                                     : samples + (samples >> 10) * 5;
716                  // Double for stereo and add one worst case sample                  // Double for stereo and add one worst case sample
# Line 707  namespace gig { Line 720  namespace gig {
720    
721              // Worst case amount of sample points that can be read with the              // Worst case amount of sample points that can be read with the
722              // given decompression buffer.              // given decompression buffer.
723              inline unsigned long WorstCaseMaxSamples(buffer_t* pDecompressionBuffer) {              inline file_offset_t WorstCaseMaxSamples(buffer_t* pDecompressionBuffer) {
724                  return (unsigned long) ((float)pDecompressionBuffer->Size / (float)WorstCaseFrameSize * (float)SamplesPerFrame);                  return (file_offset_t) ((float)pDecompressionBuffer->Size / (float)WorstCaseFrameSize * (float)SamplesPerFrame);
725              }              }
726          private:          private:
727              void ScanCompressedSample();              void ScanCompressedSample();
# Line 1010  namespace gig { Line 1023  namespace gig {
1023              void   SetScriptAsText(const String& text);              void   SetScriptAsText(const String& text);
1024              void   SetGroup(ScriptGroup* pGroup);              void   SetGroup(ScriptGroup* pGroup);
1025              ScriptGroup* GetGroup() const;              ScriptGroup* GetGroup() const;
1026                void   CopyAssign(const Script* orig);
1027          protected:          protected:
1028              Script(ScriptGroup* group, RIFF::Chunk* ckScri);              Script(ScriptGroup* group, RIFF::Chunk* ckScri);
1029              virtual ~Script();              virtual ~Script();
# Line 1266  namespace gig { Line 1280  namespace gig {
1280              virtual void LoadInstruments(progress_t* pProgress);              virtual void LoadInstruments(progress_t* pProgress);
1281              virtual void LoadScriptGroups();              virtual void LoadScriptGroups();
1282              void SetSampleChecksum(Sample* pSample, uint32_t crc);              void SetSampleChecksum(Sample* pSample, uint32_t crc);
1283                uint32_t GetSampleChecksum(Sample* pSample);
1284                uint32_t GetSampleChecksumByIndex(int index);
1285                bool VerifySampleChecksumTable();
1286                bool RebuildSampleChecksumTable();
1287                int  GetWaveTableIndexOf(gig::Sample* pSample);
1288              friend class Region;              friend class Region;
1289              friend class Sample;              friend class Sample;
1290              friend class Instrument;              friend class Instrument;

Legend:
Removed from v.2762  
changed lines
  Added in v.3140

  ViewVC Help
Powered by ViewVC