/[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 2700 by schoenebeck, Mon Jan 12 23:22:29 2015 UTC revision 3138 by schoenebeck, Wed May 3 14:41:58 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 25  Line 25 
25  #define __GIG_H__  #define __GIG_H__
26    
27  #include "DLS.h"  #include "DLS.h"
28    #include "Serialization.h"
29  #include <vector>  #include <vector>
30    
31  #if WORDS_BIGENDIAN  #if WORDS_BIGENDIAN
# Line 70  namespace gig { Line 71  namespace gig {
71    
72      typedef std::string String;      typedef std::string String;
73      typedef RIFF::progress_t progress_t;      typedef RIFF::progress_t progress_t;
74        typedef RIFF::file_offset_t file_offset_t;
75    
76      /** Lower and upper limit of a range. */      /** Lower and upper limit of a range. */
77      struct range_t {      struct range_t {
# Line 80  namespace gig { Line 82  namespace gig {
82      /** Pointer address and size of a buffer. */      /** Pointer address and size of a buffer. */
83      struct buffer_t {      struct buffer_t {
84          void*         pStart;            ///< Points to the beginning of the buffer.          void*         pStart;            ///< Points to the beginning of the buffer.
85          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.
86          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. :)
87          buffer_t() {          buffer_t() {
88              pStart            = NULL;              pStart            = NULL;
89              Size              = 0;              Size              = 0;
# Line 190  namespace gig { Line 192  namespace gig {
192    
193          type_t type;              ///< Controller type          type_t type;              ///< Controller type
194          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
195    
196            void serialize(Serialization::Archive* archive);
197      };      };
198    
199      /**      /**
# Line 303  namespace gig { Line 307  namespace gig {
307          uint8_t out_start;  ///< Start position of fade out.          uint8_t out_start;  ///< Start position of fade out.
308          uint8_t out_end;    ///< End postition of fade out.          uint8_t out_end;    ///< End postition of fade out.
309          #endif // WORDS_BIGENDIAN          #endif // WORDS_BIGENDIAN
310    
311            void serialize(Serialization::Archive* archive);
312      };      };
313    
314      /** Reflects the current playback state for a sample. */      /** Reflects the current playback state for a sample. */
315      struct playback_state_t {      struct playback_state_t {
316          unsigned long position;          ///< Current position within the sample.          file_offset_t position;          ///< Current position within the sample.
317          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).
318          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.
319      };      };
320    
321      // just symbol prototyping      // just symbol prototyping
# Line 485  namespace gig { Line 491  namespace gig {
491              DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src);              DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src);
492             ~DimensionRegion();             ~DimensionRegion();
493              void CopyAssign(const DimensionRegion* orig, const std::map<Sample*,Sample*>* mSamples);              void CopyAssign(const DimensionRegion* orig, const std::map<Sample*,Sample*>* mSamples);
494                void serialize(Serialization::Archive* archive);
495              friend class Region;              friend class Region;
496                friend class Serialization::Archive;
497          private:          private:
498              typedef enum { ///< Used to decode attenuation, EG1 and EG2 controller              typedef enum { ///< Used to decode attenuation, EG1 and EG2 controller
499                  // 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 596  namespace gig {
596              } _lev_ctrl_t;              } _lev_ctrl_t;
597              typedef std::map<uint32_t, double*> VelocityTableMap;              typedef std::map<uint32_t, double*> VelocityTableMap;
598    
599              static uint              Instances;                  ///< Number of DimensionRegion instances.              static size_t            Instances;                  ///< Number of DimensionRegion instances.
600              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).
601              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.
602              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 659  namespace gig {
659    
660              // own methods              // own methods
661              buffer_t      LoadSampleData();              buffer_t      LoadSampleData();
662              buffer_t      LoadSampleData(unsigned long SampleCount);              buffer_t      LoadSampleData(file_offset_t SampleCount);
663              buffer_t      LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);              buffer_t      LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);
664              buffer_t      LoadSampleDataWithNullSamplesExtension(unsigned long SampleCount, uint NullSamplesCount);              buffer_t      LoadSampleDataWithNullSamplesExtension(file_offset_t SampleCount, uint NullSamplesCount);
665              buffer_t      GetCache();              buffer_t      GetCache();
666              // own static methods              // own static methods
667              static buffer_t CreateDecompressionBuffer(unsigned long MaxReadSize);              static buffer_t CreateDecompressionBuffer(file_offset_t MaxReadSize);
668              static void     DestroyDecompressionBuffer(buffer_t& DecompressionBuffer);              static void     DestroyDecompressionBuffer(buffer_t& DecompressionBuffer);
669              // overridden methods              // overridden methods
670              void          ReleaseSampleData();              void          ReleaseSampleData();
671              void          Resize(int iNewSize);              void          Resize(file_offset_t NewSize);
672              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);
673              unsigned long GetPos() const;              file_offset_t GetPos() const;
674              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);
675              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);
676              unsigned long Write(void* pBuffer, unsigned long SampleCount);              file_offset_t Write(void* pBuffer, file_offset_t SampleCount);
677              Group*        GetGroup() const;              Group*        GetGroup() const;
678              virtual void  UpdateChunks(progress_t* pProgress);              virtual void  UpdateChunks(progress_t* pProgress);
679              void CopyAssignMeta(const Sample* orig);              void CopyAssignMeta(const Sample* orig);
680              void CopyAssignWave(const Sample* orig);              void CopyAssignWave(const Sample* orig);
681                uint32_t GetWaveDataCRC32Checksum();
682                bool VerifyWaveData(uint32_t* pActually = NULL);
683          protected:          protected:
684              static unsigned int  Instances;               ///< Number of instances of class Sample.              static size_t        Instances;               ///< Number of instances of class Sample.
685              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.
686              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)
687              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).
688              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.
689              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).
690              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.
691              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.
692              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.
693              buffer_t             RAMCache;                ///< Buffers samples (already uncompressed) in RAM.              buffer_t             RAMCache;                ///< Buffers samples (already uncompressed) in RAM.
694              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)
695              RIFF::Chunk*         pCk3gix;              RIFF::Chunk*         pCk3gix;
696              RIFF::Chunk*         pCkSmpl;              RIFF::Chunk*         pCkSmpl;
697              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().
698    
699              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);
700             ~Sample();             ~Sample();
701                uint32_t CalculateWaveDataChecksum();
702    
703              // Guess size (in bytes) of a compressed sample              // Guess size (in bytes) of a compressed sample
704              inline unsigned long GuessSize(unsigned long samples) {              inline file_offset_t GuessSize(file_offset_t samples) {
705                  // 16 bit: assume all frames are compressed - 1 byte                  // 16 bit: assume all frames are compressed - 1 byte
706                  // per sample and 5 bytes header per 2048 samples                  // per sample and 5 bytes header per 2048 samples
707    
708                  // 24 bit: assume next best compression rate - 1.5                  // 24 bit: assume next best compression rate - 1.5
709                  // bytes per sample and 13 bytes header per 256                  // bytes per sample and 13 bytes header per 256
710                  // samples                  // samples
711                  const unsigned long size =                  const file_offset_t size =
712                      BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13                      BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13
713                                     : samples + (samples >> 10) * 5;                                     : samples + (samples >> 10) * 5;
714                  // Double for stereo and add one worst case sample                  // Double for stereo and add one worst case sample
# Line 707  namespace gig { Line 718  namespace gig {
718    
719              // Worst case amount of sample points that can be read with the              // Worst case amount of sample points that can be read with the
720              // given decompression buffer.              // given decompression buffer.
721              inline unsigned long WorstCaseMaxSamples(buffer_t* pDecompressionBuffer) {              inline file_offset_t WorstCaseMaxSamples(buffer_t* pDecompressionBuffer) {
722                  return (unsigned long) ((float)pDecompressionBuffer->Size / (float)WorstCaseFrameSize * (float)SamplesPerFrame);                  return (file_offset_t) ((float)pDecompressionBuffer->Size / (float)WorstCaseFrameSize * (float)SamplesPerFrame);
723              }              }
724          private:          private:
725              void ScanCompressedSample();              void ScanCompressedSample();
# Line 979  namespace gig { Line 990  namespace gig {
990       * not available in the GigaStudio 4 software. It is currently only       * not available in the GigaStudio 4 software. It is currently only
991       * supported by LinuxSampler and gigedit. Scripts will not load with the       * supported by LinuxSampler and gigedit. Scripts will not load with the
992       * original GigaStudio software.       * original GigaStudio software.
993         *
994         * You find more informations about Instrument Scripts on the LinuxSampler
995         * documentation site:
996         *
997         * - <a href="http://doc.linuxsampler.org/Instrument_Scripts/">About Instrument Scripts in General</a>
998         * - <a href="http://doc.linuxsampler.org/Instrument_Scripts/NKSP_Language">Introduction to the NKSP Script Language</a>
999         * - <a href="http://doc.linuxsampler.org/Instrument_Scripts/NKSP_Language/Reference/">NKSP Reference Manual</a>
1000         * - <a href="http://doc.linuxsampler.org/Gigedit/Managing_Scripts">Using Instrument Scripts with Gigedit</a>
1001       */       */
1002      class Script {      class Script {
1003          public:          public:
# Line 989  namespace gig { Line 1008  namespace gig {
1008                  COMPRESSION_NONE = 0 ///< Is not compressed at all (default).                  COMPRESSION_NONE = 0 ///< Is not compressed at all (default).
1009              };              };
1010              enum Language_t {              enum Language_t {
1011                  LANGUAGE_NKSP = 0 ///< NKSP stands for "Is Not KSP" (default).                  LANGUAGE_NKSP = 0 ///< NKSP stands for "Is Not KSP" (default). Refer to the <a href="http://doc.linuxsampler.org/Instrument_Scripts/NKSP_Language/Reference/">NKSP Reference Manual</a> for details about this script language.
1012              };              };
1013    
1014              String         Name;        ///< Arbitrary name of the script, which may be displayed i.e. in an instrument editor.              String         Name;        ///< Arbitrary name of the script, which may be displayed i.e. in an instrument editor.
# Line 1002  namespace gig { Line 1021  namespace gig {
1021              void   SetScriptAsText(const String& text);              void   SetScriptAsText(const String& text);
1022              void   SetGroup(ScriptGroup* pGroup);              void   SetGroup(ScriptGroup* pGroup);
1023              ScriptGroup* GetGroup() const;              ScriptGroup* GetGroup() const;
1024                void   CopyAssign(const Script* orig);
1025          protected:          protected:
1026              Script(ScriptGroup* group, RIFF::Chunk* ckScri);              Script(ScriptGroup* group, RIFF::Chunk* ckScri);
1027              virtual ~Script();              virtual ~Script();
# Line 1258  namespace gig { Line 1278  namespace gig {
1278              virtual void LoadInstruments(progress_t* pProgress);              virtual void LoadInstruments(progress_t* pProgress);
1279              virtual void LoadScriptGroups();              virtual void LoadScriptGroups();
1280              void SetSampleChecksum(Sample* pSample, uint32_t crc);              void SetSampleChecksum(Sample* pSample, uint32_t crc);
1281                uint32_t GetSampleChecksum(Sample* pSample);
1282                uint32_t GetSampleChecksumByIndex(int index);
1283                bool VerifySampleChecksumTable();
1284                bool RebuildSampleChecksumTable();
1285                int  GetWaveTableIndexOf(gig::Sample* pSample);
1286              friend class Region;              friend class Region;
1287              friend class Sample;              friend class Sample;
1288              friend class Instrument;              friend class Instrument;

Legend:
Removed from v.2700  
changed lines
  Added in v.3138

  ViewVC Help
Powered by ViewVC