/[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 436 by persson, Wed Feb 23 19:11:07 2005 UTC revision 437 by persson, Wed Mar 9 22:02:40 2005 UTC
# Line 94  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 106  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 123  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 239  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    
# Line 249  namespace gig { namespace { Line 261  namespace gig { namespace {
261              InternalDecompressionBuffer.pStart = new unsigned char[INITIAL_SAMPLE_BUFFER_SIZE];              InternalDecompressionBuffer.pStart = new unsigned char[INITIAL_SAMPLE_BUFFER_SIZE];
262              InternalDecompressionBuffer.Size   = 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 846  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 1378  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.436  
changed lines
  Added in v.437

  ViewVC Help
Powered by ViewVC