/[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 2761 by schoenebeck, Sat May 2 11:25:44 2015 UTC revision 2989 by schoenebeck, Sat Sep 24 14:00:46 2016 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-2016 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 70  namespace gig { Line 70  namespace gig {
70    
71      typedef std::string String;      typedef std::string String;
72      typedef RIFF::progress_t progress_t;      typedef RIFF::progress_t progress_t;
73        typedef RIFF::file_offset_t file_offset_t;
74    
75      /** Lower and upper limit of a range. */      /** Lower and upper limit of a range. */
76      struct range_t {      struct range_t {
# Line 80  namespace gig { Line 81  namespace gig {
81      /** Pointer address and size of a buffer. */      /** Pointer address and size of a buffer. */
82      struct buffer_t {      struct buffer_t {
83          void*         pStart;            ///< Points to the beginning of the buffer.          void*         pStart;            ///< Points to the beginning of the buffer.
84          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.
85          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. :)
86          buffer_t() {          buffer_t() {
87              pStart            = NULL;              pStart            = NULL;
88              Size              = 0;              Size              = 0;
# Line 307  namespace gig { Line 308  namespace gig {
308    
309      /** Reflects the current playback state for a sample. */      /** Reflects the current playback state for a sample. */
310      struct playback_state_t {      struct playback_state_t {
311          unsigned long position;          ///< Current position within the sample.          file_offset_t position;          ///< Current position within the sample.
312          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).
313          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.
314      };      };
315    
316      // just symbol prototyping      // just symbol prototyping
# Line 588  namespace gig { Line 589  namespace gig {
589              } _lev_ctrl_t;              } _lev_ctrl_t;
590              typedef std::map<uint32_t, double*> VelocityTableMap;              typedef std::map<uint32_t, double*> VelocityTableMap;
591    
592              static uint              Instances;                  ///< Number of DimensionRegion instances.              static size_t            Instances;                  ///< Number of DimensionRegion instances.
593              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).
594              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.
595              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 652  namespace gig {
652    
653              // own methods              // own methods
654              buffer_t      LoadSampleData();              buffer_t      LoadSampleData();
655              buffer_t      LoadSampleData(unsigned long SampleCount);              buffer_t      LoadSampleData(file_offset_t SampleCount);
656              buffer_t      LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);              buffer_t      LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount);
657              buffer_t      LoadSampleDataWithNullSamplesExtension(unsigned long SampleCount, uint NullSamplesCount);              buffer_t      LoadSampleDataWithNullSamplesExtension(file_offset_t SampleCount, uint NullSamplesCount);
658              buffer_t      GetCache();              buffer_t      GetCache();
659              // own static methods              // own static methods
660              static buffer_t CreateDecompressionBuffer(unsigned long MaxReadSize);              static buffer_t CreateDecompressionBuffer(file_offset_t MaxReadSize);
661              static void     DestroyDecompressionBuffer(buffer_t& DecompressionBuffer);              static void     DestroyDecompressionBuffer(buffer_t& DecompressionBuffer);
662              // overridden methods              // overridden methods
663              void          ReleaseSampleData();              void          ReleaseSampleData();
664              void          Resize(int iNewSize);              void          Resize(file_offset_t NewSize);
665              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);
666              unsigned long GetPos() const;              file_offset_t GetPos() const;
667              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);
668              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);
669              unsigned long Write(void* pBuffer, unsigned long SampleCount);              file_offset_t Write(void* pBuffer, file_offset_t SampleCount);
670              Group*        GetGroup() const;              Group*        GetGroup() const;
671              virtual void  UpdateChunks(progress_t* pProgress);              virtual void  UpdateChunks(progress_t* pProgress);
672              void CopyAssignMeta(const Sample* orig);              void CopyAssignMeta(const Sample* orig);
673              void CopyAssignWave(const Sample* orig);              void CopyAssignWave(const Sample* orig);
674                uint32_t GetWaveDataCRC32Checksum();
675                bool VerifyWaveData(uint32_t* pActually = NULL);
676          protected:          protected:
677              static unsigned int  Instances;               ///< Number of instances of class Sample.              static size_t        Instances;               ///< Number of instances of class Sample.
678              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.
679              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)
680              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).
681              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.
682              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).
683              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.
684              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.
685              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.
686              buffer_t             RAMCache;                ///< Buffers samples (already uncompressed) in RAM.              buffer_t             RAMCache;                ///< Buffers samples (already uncompressed) in RAM.
687              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)
688              RIFF::Chunk*         pCk3gix;              RIFF::Chunk*         pCk3gix;
689              RIFF::Chunk*         pCkSmpl;              RIFF::Chunk*         pCkSmpl;
690              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().
691    
692              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);
693             ~Sample();             ~Sample();
694                uint32_t CalculateWaveDataChecksum();
695    
696              // Guess size (in bytes) of a compressed sample              // Guess size (in bytes) of a compressed sample
697              inline unsigned long GuessSize(unsigned long samples) {              inline file_offset_t GuessSize(file_offset_t samples) {
698                  // 16 bit: assume all frames are compressed - 1 byte                  // 16 bit: assume all frames are compressed - 1 byte
699                  // per sample and 5 bytes header per 2048 samples                  // per sample and 5 bytes header per 2048 samples
700    
701                  // 24 bit: assume next best compression rate - 1.5                  // 24 bit: assume next best compression rate - 1.5
702                  // bytes per sample and 13 bytes header per 256                  // bytes per sample and 13 bytes header per 256
703                  // samples                  // samples
704                  const unsigned long size =                  const file_offset_t size =
705                      BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13                      BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13
706                                     : samples + (samples >> 10) * 5;                                     : samples + (samples >> 10) * 5;
707                  // Double for stereo and add one worst case sample                  // Double for stereo and add one worst case sample
# Line 707  namespace gig { Line 711  namespace gig {
711    
712              // Worst case amount of sample points that can be read with the              // Worst case amount of sample points that can be read with the
713              // given decompression buffer.              // given decompression buffer.
714              inline unsigned long WorstCaseMaxSamples(buffer_t* pDecompressionBuffer) {              inline file_offset_t WorstCaseMaxSamples(buffer_t* pDecompressionBuffer) {
715                  return (unsigned long) ((float)pDecompressionBuffer->Size / (float)WorstCaseFrameSize * (float)SamplesPerFrame);                  return (file_offset_t) ((float)pDecompressionBuffer->Size / (float)WorstCaseFrameSize * (float)SamplesPerFrame);
716              }              }
717          private:          private:
718              void ScanCompressedSample();              void ScanCompressedSample();
# Line 997  namespace gig { Line 1001  namespace gig {
1001                  COMPRESSION_NONE = 0 ///< Is not compressed at all (default).                  COMPRESSION_NONE = 0 ///< Is not compressed at all (default).
1002              };              };
1003              enum Language_t {              enum Language_t {
1004                  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.
1005              };              };
1006    
1007              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 1266  namespace gig { Line 1270  namespace gig {
1270              virtual void LoadInstruments(progress_t* pProgress);              virtual void LoadInstruments(progress_t* pProgress);
1271              virtual void LoadScriptGroups();              virtual void LoadScriptGroups();
1272              void SetSampleChecksum(Sample* pSample, uint32_t crc);              void SetSampleChecksum(Sample* pSample, uint32_t crc);
1273                uint32_t GetSampleChecksum(Sample* pSample);
1274                uint32_t GetSampleChecksumByIndex(int index);
1275                bool VerifySampleChecksumTable();
1276                bool RebuildSampleChecksumTable();
1277                int  GetWaveTableIndexOf(gig::Sample* pSample);
1278              friend class Region;              friend class Region;
1279              friend class Sample;              friend class Sample;
1280              friend class Instrument;              friend class Instrument;

Legend:
Removed from v.2761  
changed lines
  Added in v.2989

  ViewVC Help
Powered by ViewVC