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

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

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

revision 372 by persson, Fri Feb 11 18:58:07 2005 UTC revision 437 by persson, Wed Mar 9 22:02:40 2005 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file loader library    *   *   libgig - C++ cross-platform Gigasampler format file loader library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Christian Schoenebeck                     *   *   Copyright (C) 2003-2005 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  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 23  Line 23 
23    
24  #include "gig.h"  #include "gig.h"
25    
26    #include <iostream>
27    
28  namespace gig { namespace {  namespace gig { namespace {
29    
30  // *************** Internal functions for sample decopmression ***************  // *************** Internal functions for sample decopmression ***************
# Line 92  namespace gig { namespace { Line 94  namespace gig { namespace {
94      void Decompress24(int compressionmode, const unsigned char* params,      void Decompress24(int compressionmode, const unsigned char* params,
95                        int dstStep, const unsigned char* pSrc, int16_t* pDst,                        int dstStep, const unsigned char* pSrc, int16_t* pDst,
96                        unsigned long currentframeoffset,                        unsigned long currentframeoffset,
97                        unsigned long copysamples)                        unsigned long copysamples, int truncatedBits)
98      {      {
99          // Note: The 24 bits are truncated to 16 bits for now.          // Note: The 24 bits are truncated to 16 bits for now.
100    
# Line 104  namespace gig { namespace { Line 106  namespace gig { namespace {
106          //          //
107          // Strange thing #2: The formula in SKIP_ONE gives values for          // Strange thing #2: The formula in SKIP_ONE gives values for
108          // y that are twice as high as they should be. That's why          // y that are twice as high as they should be. That's why
109          // COPY_ONE shifts 9 steps instead of 8, and also why y is          // COPY_ONE shifts an extra step, and also why y is
110          // initialized with a sum instead of a mean value.          // initialized with a sum instead of a mean value.
111    
112          int y, dy, ddy;          int y, dy, ddy;
113    
114            const int shift = 8 - truncatedBits;
115            const int shift1 = shift + 1;
116    
117  #define GET_PARAMS(params)                              \  #define GET_PARAMS(params)                              \
118          y = (get24(params) + get24((params) + 3));      \          y = (get24(params) + get24((params) + 3));      \
119          dy  = get24((params) + 6);                      \          dy  = get24((params) + 6);                      \
# Line 121  namespace gig { namespace { Line 126  namespace gig { namespace {
126    
127  #define COPY_ONE(x)                             \  #define COPY_ONE(x)                             \
128          SKIP_ONE(x);                            \          SKIP_ONE(x);                            \
129          *pDst = y >> 9;                         \          *pDst = y >> shift1;                    \
130          pDst += dstStep          pDst += dstStep
131    
132          switch (compressionmode) {          switch (compressionmode) {
133              case 2: // 24 bit uncompressed              case 2: // 24 bit uncompressed
134                  pSrc += currentframeoffset * 3;                  pSrc += currentframeoffset * 3;
135                  while (copysamples) {                  while (copysamples) {
136                      *pDst = get24(pSrc) >> 8;                      *pDst = get24(pSrc) >> shift;
137                      pDst += dstStep;                      pDst += dstStep;
138                      pSrc += 3;                      pSrc += 3;
139                      copysamples--;                      copysamples--;
# Line 201  namespace gig { namespace { Line 206  namespace gig { namespace {
206  // *************** Sample ***************  // *************** Sample ***************
207  // *  // *
208    
209      unsigned int  Sample::Instances               = 0;      unsigned int Sample::Instances = 0;
210      unsigned char* Sample::pDecompressionBuffer    = NULL;      buffer_t     Sample::InternalDecompressionBuffer;
     unsigned long Sample::DecompressionBufferSize = 0;  
211    
212      Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) {      Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) {
213          Instances++;          Instances++;
# Line 238  namespace gig { namespace { Line 242  namespace gig { namespace {
242    
243          if (BitDepth > 24) throw gig::Exception("Only samples up to 24 bit supported");          if (BitDepth > 24) throw gig::Exception("Only samples up to 24 bit supported");
244    
245          Compressed = (waveList->GetSubChunk(CHUNK_ID_EWAV));          RIFF::Chunk* ewav = waveList->GetSubChunk(CHUNK_ID_EWAV);
246            Compressed        = ewav;
247            Dithered          = false;
248            TruncatedBits     = 0;
249          if (Compressed) {          if (Compressed) {
250                uint32_t version = ewav->ReadInt32();
251                if (version == 3 && BitDepth == 24) {
252                    Dithered = ewav->ReadInt32();
253                    ewav->SetPos(Channels == 2 ? 84 : 64);
254                    TruncatedBits = ewav->ReadInt32();
255                }
256              ScanCompressedSample();              ScanCompressedSample();
257          }          }
258    
259          // we use a buffer for decompression and for truncating 24 bit samples to 16 bit          // we use a buffer for decompression and for truncating 24 bit samples to 16 bit
260          if ((Compressed || BitDepth == 24) && !pDecompressionBuffer) {          if ((Compressed || BitDepth == 24) && !InternalDecompressionBuffer.Size) {
261              pDecompressionBuffer    = new unsigned char[INITIAL_SAMPLE_BUFFER_SIZE];              InternalDecompressionBuffer.pStart = new unsigned char[INITIAL_SAMPLE_BUFFER_SIZE];
262              DecompressionBufferSize = INITIAL_SAMPLE_BUFFER_SIZE;              InternalDecompressionBuffer.Size   = INITIAL_SAMPLE_BUFFER_SIZE;
263          }          }
264          FrameOffset = 0; // just for streaming compressed samples          FrameOffset = 0; // just for streaming compressed samples
265    
266          LoopSize = LoopEnd - LoopStart;          LoopSize = LoopEnd - LoopStart;
267      }      }
# Line 260  namespace gig { namespace { Line 273  namespace gig { namespace {
273          std::list<unsigned long> frameOffsets;          std::list<unsigned long> frameOffsets;
274    
275          SamplesPerFrame = BitDepth == 24 ? 256 : 2048;          SamplesPerFrame = BitDepth == 24 ? 256 : 2048;
276          WorstCaseFrameSize = SamplesPerFrame * FrameSize + Channels;          WorstCaseFrameSize = SamplesPerFrame * FrameSize + Channels; // +Channels for compression flag
277    
278          // Scanning          // Scanning
279          pCkData->SetPos(0);          pCkData->SetPos(0);
# Line 341  namespace gig { namespace { Line 354  namespace gig { namespace {
354       * that will be returned to determine the actual cached samples, but note       * that will be returned to determine the actual cached samples, but note
355       * that the size is given in bytes! You get the number of actually cached       * that the size is given in bytes! You get the number of actually cached
356       * samples by dividing it by the frame size of the sample:       * samples by dividing it by the frame size of the sample:
357       *       * @code
358       *  buffer_t buf       = pSample->LoadSampleData(acquired_samples);       *  buffer_t buf       = pSample->LoadSampleData(acquired_samples);
359       *  long cachedsamples = buf.Size / pSample->FrameSize;       *  long cachedsamples = buf.Size / pSample->FrameSize;
360         * @endcode
361       *       *
362       * @param SampleCount - number of sample points to load into RAM       * @param SampleCount - number of sample points to load into RAM
363       * @returns             buffer_t structure with start address and size of       * @returns             buffer_t structure with start address and size of
# Line 389  namespace gig { namespace { Line 403  namespace gig { namespace {
403       * that will be returned to determine the actual cached samples, but note       * that will be returned to determine the actual cached samples, but note
404       * that the size is given in bytes! You get the number of actually cached       * that the size is given in bytes! You get the number of actually cached
405       * samples by dividing it by the frame size of the sample:       * samples by dividing it by the frame size of the sample:
406       *       * @code
407       *  buffer_t buf       = pSample->LoadSampleDataWithNullSamplesExtension(acquired_samples, null_samples);       *  buffer_t buf       = pSample->LoadSampleDataWithNullSamplesExtension(acquired_samples, null_samples);
408       *  long cachedsamples = buf.Size / pSample->FrameSize;       *  long cachedsamples = buf.Size / pSample->FrameSize;
409       *       * @endcode
410       * The method will add \a NullSamplesCount silence samples past the       * The method will add \a NullSamplesCount silence samples past the
411       * official buffer end (this won't affect the 'Size' member of the       * official buffer end (this won't affect the 'Size' member of the
412       * buffer_t structure, that means 'Size' always reflects the size of the       * buffer_t structure, that means 'Size' always reflects the size of the
# Line 523  namespace gig { namespace { Line 537  namespace gig { namespace {
537       * for the next time you call this method is stored in \a pPlaybackState.       * for the next time you call this method is stored in \a pPlaybackState.
538       * You have to allocate and initialize the playback_state_t structure by       * You have to allocate and initialize the playback_state_t structure by
539       * yourself before you use it to stream a sample:       * yourself before you use it to stream a sample:
540       *       * @code
541       * <i>       * gig::playback_state_t playbackstate;
542       * gig::playback_state_t playbackstate;                           <br>       * playbackstate.position         = 0;
543       * playbackstate.position         = 0;                            <br>       * playbackstate.reverse          = false;
544       * playbackstate.reverse          = false;                        <br>       * playbackstate.loop_cycles_left = pSample->LoopPlayCount;
545       * playbackstate.loop_cycles_left = pSample->LoopPlayCount;       <br>       * @endcode
      * </i>  
      *  
546       * You don't have to take care of things like if there is actually a loop       * You don't have to take care of things like if there is actually a loop
547       * defined or if the current read position is located within a loop area.       * defined or if the current read position is located within a loop area.
548       * The method already handles such cases by itself.       * The method already handles such cases by itself.
549       *       *
550         * <b>Caution:</b> If you are using more than one streaming thread, you
551         * have to use an external decompression buffer for <b>EACH</b>
552         * streaming thread to avoid race conditions and crashes!
553         *
554       * @param pBuffer          destination buffer       * @param pBuffer          destination buffer
555       * @param SampleCount      number of sample points to read       * @param SampleCount      number of sample points to read
556       * @param pPlaybackState   will be used to store and reload the playback       * @param pPlaybackState   will be used to store and reload the playback
557       *                         state for the next ReadAndLoop() call       *                         state for the next ReadAndLoop() call
558         * @param pExternalDecompressionBuffer  (optional) external buffer to use for decompression
559       * @returns                number of successfully read sample points       * @returns                number of successfully read sample points
560         * @see                    CreateDecompressionBuffer()
561       */       */
562      unsigned long Sample::ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState) {      unsigned long Sample::ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, buffer_t* pExternalDecompressionBuffer) {
563          unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend;          unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend;
564          uint8_t* pDst = (uint8_t*) pBuffer;          uint8_t* pDst = (uint8_t*) pBuffer;
565    
# Line 559  namespace gig { namespace { Line 577  namespace gig { namespace {
577                          if (!pPlaybackState->reverse) { // forward playback                          if (!pPlaybackState->reverse) { // forward playback
578                              do {                              do {
579                                  samplestoloopend  = this->LoopEnd - GetPos();                                  samplestoloopend  = this->LoopEnd - GetPos();
580                                  readsamples       = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend));                                  readsamples       = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer);
581                                  samplestoread    -= readsamples;                                  samplestoread    -= readsamples;
582                                  totalreadsamples += readsamples;                                  totalreadsamples += readsamples;
583                                  if (readsamples == samplestoloopend) {                                  if (readsamples == samplestoloopend) {
# Line 585  namespace gig { namespace { Line 603  namespace gig { namespace {
603    
604                              // read samples for backward playback                              // read samples for backward playback
605                              do {                              do {
606                                  readsamples          = Read(&pDst[totalreadsamples * this->FrameSize], samplestoreadinloop);                                  readsamples          = Read(&pDst[totalreadsamples * this->FrameSize], samplestoreadinloop, pExternalDecompressionBuffer);
607                                  samplestoreadinloop -= readsamples;                                  samplestoreadinloop -= readsamples;
608                                  samplestoread       -= readsamples;                                  samplestoread       -= readsamples;
609                                  totalreadsamples    += readsamples;                                  totalreadsamples    += readsamples;
# Line 609  namespace gig { namespace { Line 627  namespace gig { namespace {
627                      // forward playback (not entered the loop yet)                      // forward playback (not entered the loop yet)
628                      if (!pPlaybackState->reverse) do {                      if (!pPlaybackState->reverse) do {
629                          samplestoloopend  = this->LoopEnd - GetPos();                          samplestoloopend  = this->LoopEnd - GetPos();
630                          readsamples       = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend));                          readsamples       = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer);
631                          samplestoread    -= readsamples;                          samplestoread    -= readsamples;
632                          totalreadsamples += readsamples;                          totalreadsamples += readsamples;
633                          if (readsamples == samplestoloopend) {                          if (readsamples == samplestoloopend) {
# Line 639  namespace gig { namespace { Line 657  namespace gig { namespace {
657                          // if not endless loop check if max. number of loop cycles have been passed                          // if not endless loop check if max. number of loop cycles have been passed
658                          if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break;                          if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break;
659                          samplestoloopend     = this->LoopEnd - GetPos();                          samplestoloopend     = this->LoopEnd - GetPos();
660                          readsamples          = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoreadinloop, samplestoloopend));                          readsamples          = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoreadinloop, samplestoloopend), pExternalDecompressionBuffer);
661                          samplestoreadinloop -= readsamples;                          samplestoreadinloop -= readsamples;
662                          samplestoread       -= readsamples;                          samplestoread       -= readsamples;
663                          totalreadsamples    += readsamples;                          totalreadsamples    += readsamples;
# Line 661  namespace gig { namespace { Line 679  namespace gig { namespace {
679                          // if not endless loop check if max. number of loop cycles have been passed                          // if not endless loop check if max. number of loop cycles have been passed
680                          if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break;                          if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break;
681                          samplestoloopend  = this->LoopEnd - GetPos();                          samplestoloopend  = this->LoopEnd - GetPos();
682                          readsamples       = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend));                          readsamples       = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer);
683                          samplestoread    -= readsamples;                          samplestoread    -= readsamples;
684                          totalreadsamples += readsamples;                          totalreadsamples += readsamples;
685                          if (readsamples == samplestoloopend) {                          if (readsamples == samplestoloopend) {
# Line 676  namespace gig { namespace { Line 694  namespace gig { namespace {
694    
695          // read on without looping          // read on without looping
696          if (samplestoread) do {          if (samplestoread) do {
697              readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoread);              readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoread, pExternalDecompressionBuffer);
698              samplestoread    -= readsamples;              samplestoread    -= readsamples;
699              totalreadsamples += readsamples;              totalreadsamples += readsamples;
700          } while (readsamples && samplestoread);          } while (readsamples && samplestoread);
# Line 695  namespace gig { namespace { Line 713  namespace gig { namespace {
713       * and <i>SetPos()</i> if you don't want to load the sample into RAM,       * and <i>SetPos()</i> if you don't want to load the sample into RAM,
714       * thus for disk streaming.       * thus for disk streaming.
715       *       *
716         * <b>Caution:</b> If you are using more than one streaming thread, you
717         * have to use an external decompression buffer for <b>EACH</b>
718         * streaming thread to avoid race conditions and crashes!
719         *
720       * @param pBuffer      destination buffer       * @param pBuffer      destination buffer
721       * @param SampleCount  number of sample points to read       * @param SampleCount  number of sample points to read
722         * @param pExternalDecompressionBuffer  (optional) external buffer to use for decompression
723       * @returns            number of successfully read sample points       * @returns            number of successfully read sample points
724       * @see                SetPos()       * @see                SetPos(), CreateDecompressionBuffer()
725       */       */
726      unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) {      unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount, buffer_t* pExternalDecompressionBuffer) {
727          if (SampleCount == 0) return 0;          if (SampleCount == 0) return 0;
728          if (!Compressed) {          if (!Compressed) {
729              if (BitDepth == 24) {              if (BitDepth == 24) {
730                  // 24 bit sample. For now just truncate to 16 bit.                  // 24 bit sample. For now just truncate to 16 bit.
731                  unsigned char* pSrc = this->pDecompressionBuffer;                  unsigned char* pSrc = (unsigned char*) ((pExternalDecompressionBuffer) ? pExternalDecompressionBuffer->pStart : this->InternalDecompressionBuffer.pStart);
732                  int16_t* pDst = static_cast<int16_t*>(pBuffer);                  int16_t* pDst = static_cast<int16_t*>(pBuffer);
733                  if (Channels == 2) { // Stereo                  if (Channels == 2) { // Stereo
734                      unsigned long readBytes = pCkData->Read(pSrc, SampleCount * 6, 1);                      unsigned long readBytes = pCkData->Read(pSrc, SampleCount * 6, 1);
# Line 742  namespace gig { namespace { Line 765  namespace gig { namespace {
765                            currentframeoffset = this->FrameOffset;  // offset in current sample frame since last Read()                            currentframeoffset = this->FrameOffset;  // offset in current sample frame since last Read()
766              this->FrameOffset = 0;              this->FrameOffset = 0;
767    
768              if (assumedsize > this->DecompressionBufferSize) {              buffer_t* pDecompressionBuffer = (pExternalDecompressionBuffer) ? pExternalDecompressionBuffer : &InternalDecompressionBuffer;
769                  // local buffer reallocation - hope this won't happen  
770                  if (this->pDecompressionBuffer) delete[] this->pDecompressionBuffer;              // if decompression buffer too small, then reduce amount of samples to read
771                  this->pDecompressionBuffer    = new unsigned char[assumedsize << 1]; // double of current needed size              if (pDecompressionBuffer->Size < assumedsize) {
772                  this->DecompressionBufferSize = assumedsize << 1;                  std::cerr << "gig::Read(): WARNING - decompression buffer size too small!" << std::endl;
773                    SampleCount      = WorstCaseMaxSamples(pDecompressionBuffer);
774                    remainingsamples = SampleCount;
775                    assumedsize      = GuessSize(SampleCount);
776              }              }
777    
778              unsigned char* pSrc = this->pDecompressionBuffer;              unsigned char* pSrc = (unsigned char*) pDecompressionBuffer->pStart;
779              int16_t* pDst = static_cast<int16_t*>(pBuffer);              int16_t* pDst = static_cast<int16_t*>(pBuffer);
780              remainingbytes = pCkData->Read(pSrc, assumedsize, 1);              remainingbytes = pCkData->Read(pSrc, assumedsize, 1);
781    
# Line 832  namespace gig { namespace { Line 858  namespace gig { namespace {
858                              const unsigned char* const param_r = pSrc;                              const unsigned char* const param_r = pSrc;
859                              if (mode_r != 2) pSrc += 12;                              if (mode_r != 2) pSrc += 12;
860    
861                              Decompress24(mode_l, param_l, 2, pSrc, pDst, skipsamples, copysamples);                              Decompress24(mode_l, param_l, 2, pSrc, pDst,
862                                             skipsamples, copysamples, TruncatedBits);
863                              Decompress24(mode_r, param_r, 2, pSrc + rightChannelOffset, pDst + 1,                              Decompress24(mode_r, param_r, 2, pSrc + rightChannelOffset, pDst + 1,
864                                           skipsamples, copysamples);                                           skipsamples, copysamples, TruncatedBits);
865                              pDst += copysamples << 1;                              pDst += copysamples << 1;
866                          }                          }
867                          else { // Mono                          else { // Mono
868                              Decompress24(mode_l, param_l, 1, pSrc, pDst, skipsamples, copysamples);                              Decompress24(mode_l, param_l, 1, pSrc, pDst,
869                                             skipsamples, copysamples, TruncatedBits);
870                              pDst += copysamples;                              pDst += copysamples;
871                          }                          }
872                      }                      }
# Line 870  namespace gig { namespace { Line 898  namespace gig { namespace {
898                      assumedsize    = GuessSize(remainingsamples);                      assumedsize    = GuessSize(remainingsamples);
899                      pCkData->SetPos(remainingbytes, RIFF::stream_backward);                      pCkData->SetPos(remainingbytes, RIFF::stream_backward);
900                      if (pCkData->RemainingBytes() < assumedsize) assumedsize = pCkData->RemainingBytes();                      if (pCkData->RemainingBytes() < assumedsize) assumedsize = pCkData->RemainingBytes();
901                      remainingbytes = pCkData->Read(this->pDecompressionBuffer, assumedsize, 1);                      remainingbytes = pCkData->Read(pDecompressionBuffer->pStart, assumedsize, 1);
902                      pSrc = this->pDecompressionBuffer;                      pSrc = (unsigned char*) pDecompressionBuffer->pStart;
903                  }                  }
904              } // while              } // while
905    
# Line 881  namespace gig { namespace { Line 909  namespace gig { namespace {
909          }          }
910      }      }
911    
912        /**
913         * Allocates a decompression buffer for streaming (compressed) samples
914         * with Sample::Read(). If you are using more than one streaming thread
915         * in your application you <b>HAVE</b> to create a decompression buffer
916         * for <b>EACH</b> of your streaming threads and provide it with the
917         * Sample::Read() call in order to avoid race conditions and crashes.
918         *
919         * You should free the memory occupied by the allocated buffer(s) once
920         * you don't need one of your streaming threads anymore by calling
921         * DestroyDecompressionBuffer().
922         *
923         * @param MaxReadSize - the maximum size (in sample points) you ever
924         *                      expect to read with one Read() call
925         * @returns allocated decompression buffer
926         * @see DestroyDecompressionBuffer()
927         */
928        buffer_t Sample::CreateDecompressionBuffer(unsigned long MaxReadSize) {
929            buffer_t result;
930            const double worstCaseHeaderOverhead =
931                    (256.0 /*frame size*/ + 12.0 /*header*/ + 2.0 /*compression type flag (stereo)*/) / 256.0;
932            result.Size              = (unsigned long) (double(MaxReadSize) * 3.0 /*(24 Bit)*/ * 2.0 /*stereo*/ * worstCaseHeaderOverhead);
933            result.pStart            = new int8_t[result.Size];
934            result.NullExtensionSize = 0;
935            return result;
936        }
937    
938        /**
939         * Free decompression buffer, previously created with
940         * CreateDecompressionBuffer().
941         *
942         * @param DecompressionBuffer - previously allocated decompression
943         *                              buffer to free
944         */
945        void Sample::DestroyDecompressionBuffer(buffer_t& DecompressionBuffer) {
946            if (DecompressionBuffer.Size && DecompressionBuffer.pStart) {
947                delete[] (int8_t*) DecompressionBuffer.pStart;
948                DecompressionBuffer.pStart = NULL;
949                DecompressionBuffer.Size   = 0;
950                DecompressionBuffer.NullExtensionSize = 0;
951            }
952        }
953    
954      Sample::~Sample() {      Sample::~Sample() {
955          Instances--;          Instances--;
956          if (!Instances && pDecompressionBuffer) {          if (!Instances && InternalDecompressionBuffer.Size) {
957              delete[] pDecompressionBuffer;              delete[] (unsigned char*) InternalDecompressionBuffer.pStart;
958              pDecompressionBuffer = NULL;              InternalDecompressionBuffer.pStart = NULL;
959                InternalDecompressionBuffer.Size   = 0;
960          }          }
961          if (FrameTable) delete[] FrameTable;          if (FrameTable) delete[] FrameTable;
962          if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart;          if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart;
# Line 1068  namespace gig { namespace { Line 1139  namespace gig { namespace {
1139                                      VelocityResponseCurveScaling);                                      VelocityResponseCurveScaling);
1140              (*pVelocityTables)[tableKey] = pVelocityAttenuationTable; // put the new table into the tables map              (*pVelocityTables)[tableKey] = pVelocityAttenuationTable; // put the new table into the tables map
1141          }          }
1142    
1143            SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360));
1144      }      }
1145    
1146      leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) {      leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) {
# Line 1319  namespace gig { namespace { Line 1392  namespace gig { namespace {
1392                      pDimensionDefinitions[i].zones     = 0x01 << bits; // = pow(2,bits)                      pDimensionDefinitions[i].zones     = 0x01 << bits; // = pow(2,bits)
1393                      pDimensionDefinitions[i].split_type = (dimension == dimension_layer ||                      pDimensionDefinitions[i].split_type = (dimension == dimension_layer ||
1394                                                             dimension == dimension_samplechannel ||                                                             dimension == dimension_samplechannel ||
1395                                                             dimension == dimension_releasetrigger) ? split_type_bit                                                             dimension == dimension_releasetrigger ||
1396                                                                                                    : split_type_normal;                                                             dimension == dimension_roundrobin ||
1397                                                               dimension == dimension_random) ? split_type_bit
1398                                                                                              : split_type_normal;
1399                      pDimensionDefinitions[i].ranges = NULL; // it's not possible to check velocity dimensions for custom defined ranges at this point                      pDimensionDefinitions[i].ranges = NULL; // it's not possible to check velocity dimensions for custom defined ranges at this point
1400                      pDimensionDefinitions[i].zone_size  =                      pDimensionDefinitions[i].zone_size  =
1401                          (pDimensionDefinitions[i].split_type == split_type_normal) ? 128 / pDimensionDefinitions[i].zones                          (pDimensionDefinitions[i].split_type == split_type_normal) ? 128 / pDimensionDefinitions[i].zones

Legend:
Removed from v.372  
changed lines
  Added in v.437

  ViewVC Help
Powered by ViewVC