/[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 2922 by schoenebeck, Wed May 18 18:04:49 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          protected:          protected:
675              static unsigned int  Instances;               ///< Number of instances of class Sample.              static size_t        Instances;               ///< Number of instances of class Sample.
676              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.
677              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)
678              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).
679              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.
680              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).
681              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.
682              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.
683              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.
684              buffer_t             RAMCache;                ///< Buffers samples (already uncompressed) in RAM.              buffer_t             RAMCache;                ///< Buffers samples (already uncompressed) in RAM.
685              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)
686              RIFF::Chunk*         pCk3gix;              RIFF::Chunk*         pCk3gix;
687              RIFF::Chunk*         pCkSmpl;              RIFF::Chunk*         pCkSmpl;
688              uint32_t             crc;                     ///< CRC-32 checksum of the raw sample data              uint32_t             crc;                     ///< CRC-32 checksum of the raw sample data
689    
690              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);
691             ~Sample();             ~Sample();
692    
693              // Guess size (in bytes) of a compressed sample              // Guess size (in bytes) of a compressed sample
694              inline unsigned long GuessSize(unsigned long samples) {              inline file_offset_t GuessSize(file_offset_t samples) {
695                  // 16 bit: assume all frames are compressed - 1 byte                  // 16 bit: assume all frames are compressed - 1 byte
696                  // per sample and 5 bytes header per 2048 samples                  // per sample and 5 bytes header per 2048 samples
697    
698                  // 24 bit: assume next best compression rate - 1.5                  // 24 bit: assume next best compression rate - 1.5
699                  // bytes per sample and 13 bytes header per 256                  // bytes per sample and 13 bytes header per 256
700                  // samples                  // samples
701                  const unsigned long size =                  const file_offset_t size =
702                      BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13                      BitDepth == 24 ? samples + (samples >> 1) + (samples >> 8) * 13
703                                     : samples + (samples >> 10) * 5;                                     : samples + (samples >> 10) * 5;
704                  // Double for stereo and add one worst case sample                  // Double for stereo and add one worst case sample
# Line 707  namespace gig { Line 708  namespace gig {
708    
709              // Worst case amount of sample points that can be read with the              // Worst case amount of sample points that can be read with the
710              // given decompression buffer.              // given decompression buffer.
711              inline unsigned long WorstCaseMaxSamples(buffer_t* pDecompressionBuffer) {              inline file_offset_t WorstCaseMaxSamples(buffer_t* pDecompressionBuffer) {
712                  return (unsigned long) ((float)pDecompressionBuffer->Size / (float)WorstCaseFrameSize * (float)SamplesPerFrame);                  return (file_offset_t) ((float)pDecompressionBuffer->Size / (float)WorstCaseFrameSize * (float)SamplesPerFrame);
713              }              }
714          private:          private:
715              void ScanCompressedSample();              void ScanCompressedSample();

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

  ViewVC Help
Powered by ViewVC