/[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 316 by schoenebeck, Sun Nov 21 18:02:21 2004 UTC revision 317 by schoenebeck, Sat Dec 4 14:13:49 2004 UTC
# Line 66  namespace gig { Line 66  namespace gig {
66          Compressed = (waveList->GetSubChunk(CHUNK_ID_EWAV));          Compressed = (waveList->GetSubChunk(CHUNK_ID_EWAV));
67          if (Compressed) {          if (Compressed) {
68              ScanCompressedSample();              ScanCompressedSample();
69              if (!pDecompressionBuffer) {          }
70                  pDecompressionBuffer    = new int8_t[INITIAL_SAMPLE_BUFFER_SIZE];  
71                  DecompressionBufferSize = INITIAL_SAMPLE_BUFFER_SIZE;          if (BitDepth > 24)                throw gig::Exception("Only samples up to 24 bit supported");
72              }          if (Compressed && Channels == 1)  throw gig::Exception("Mono compressed samples not yet supported");
73            if (Compressed && BitDepth == 24) throw gig::Exception("24 bit compressed samples not yet supported");
74    
75            // we use a buffer for decompression and for truncating 24 bit samples to 16 bit
76            if ((Compressed || BitDepth == 24) && !pDecompressionBuffer) {
77                pDecompressionBuffer    = new int8_t[INITIAL_SAMPLE_BUFFER_SIZE];
78                DecompressionBufferSize = INITIAL_SAMPLE_BUFFER_SIZE;
79          }          }
80          FrameOffset = 0; // just for streaming compressed samples          FrameOffset = 0; // just for streaming compressed samples
81    
# Line 502  namespace gig { Line 508  namespace gig {
508       */       */
509      unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) {      unsigned long Sample::Read(void* pBuffer, unsigned long SampleCount) {
510          if (SampleCount == 0) return 0;          if (SampleCount == 0) return 0;
511          if (!Compressed) return pCkData->Read(pBuffer, SampleCount, FrameSize); //FIXME: channel inversion due to endian correction?          if (!Compressed) {
512                if (BitDepth == 24) {
513                    // 24 bit sample. For now just truncate to 16 bit.
514                    int8_t* pSrc = (int8_t*)this->pDecompressionBuffer;
515                    int8_t* pDst = (int8_t*)pBuffer;
516                    unsigned long n = pCkData->Read(pSrc, SampleCount, FrameSize);
517                    for (int i = SampleCount * (FrameSize / 3) ; i > 0 ; i--) {
518                        pSrc++;
519                        *pDst++ = *pSrc++;
520                        *pDst++ = *pSrc++;
521                    }
522                    return SampleCount;
523                } else {
524                    return pCkData->Read(pBuffer, SampleCount, FrameSize); //FIXME: channel inversion due to endian correction?
525                }
526            }
527          else { //FIXME: no support for mono compressed samples yet, are there any?          else { //FIXME: no support for mono compressed samples yet, are there any?
528              if (this->SamplePos >= this->SamplesTotal) return 0;              if (this->SamplePos >= this->SamplesTotal) return 0;
529              //TODO: efficiency: we simply assume here that all frames are compressed, maybe we should test for an average compression rate              //TODO: efficiency: we simply assume here that all frames are compressed, maybe we should test for an average compression rate
# Line 836  namespace gig { Line 857  namespace gig {
857              pVelocityAttenuationTable = (*pVelocityTables)[tableKey];              pVelocityAttenuationTable = (*pVelocityTables)[tableKey];
858          }          }
859          else {          else {
860              pVelocityAttenuationTable =              pVelocityAttenuationTable =
861                  CreateVelocityTable(VelocityResponseCurve,                  CreateVelocityTable(VelocityResponseCurve,
862                                      VelocityResponseDepth,                                      VelocityResponseDepth,
863                                      VelocityResponseCurveScaling);                                      VelocityResponseCurveScaling);
# Line 993  namespace gig { Line 1014  namespace gig {
1014      }      }
1015    
1016      double* DimensionRegion::CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) {      double* DimensionRegion::CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) {
1017            
1018          // line-segment approximations of the 15 velocity curves          // line-segment approximations of the 15 velocity curves
1019    
1020          // linear          // linear
# Line 1005  namespace gig { Line 1026  namespace gig {
1026    
1027          // non-linear          // non-linear
1028          const int non0[] = { 1, 4, 24, 5, 57, 17, 92, 57, 122, 127, 127, 127 };          const int non0[] = { 1, 4, 24, 5, 57, 17, 92, 57, 122, 127, 127, 127 };
1029          const int non1[] = { 1, 4, 46, 9, 93, 56, 118, 106, 123, 127,          const int non1[] = { 1, 4, 46, 9, 93, 56, 118, 106, 123, 127,
1030                               127, 127 };                               127, 127 };
1031          const int non2[] = { 1, 4, 46, 9, 57, 20, 102, 107, 107, 127,          const int non2[] = { 1, 4, 46, 9, 57, 20, 102, 107, 107, 127,
1032                               127, 127 };                               127, 127 };
1033          const int non3[] = { 1, 15, 10, 19, 67, 73, 80, 80, 90, 98, 98, 127,          const int non3[] = { 1, 15, 10, 19, 67, 73, 80, 80, 90, 98, 98, 127,
1034                               127, 127 };                               127, 127 };
1035          const int non4[] = { 1, 25, 33, 57, 82, 81, 92, 127, 127, 127 };          const int non4[] = { 1, 25, 33, 57, 82, 81, 92, 127, 127, 127 };
1036            
1037          // special          // special
1038          const int spe0[] = { 1, 2, 76, 10, 90, 15, 95, 20, 99, 28, 103, 44,          const int spe0[] = { 1, 2, 76, 10, 90, 15, 95, 20, 99, 28, 103, 44,
1039                               113, 127, 127, 127 };                               113, 127, 127, 127 };
1040          const int spe1[] = { 1, 2, 27, 5, 67, 18, 89, 29, 95, 35, 107, 67,          const int spe1[] = { 1, 2, 27, 5, 67, 18, 89, 29, 95, 35, 107, 67,
1041                               118, 127, 127, 127 };                               118, 127, 127, 127 };
1042          const int spe2[] = { 1, 1, 33, 1, 53, 5, 61, 13, 69, 32, 79, 74,          const int spe2[] = { 1, 1, 33, 1, 53, 5, 61, 13, 69, 32, 79, 74,
1043                               85, 90, 91, 127, 127, 127 };                               85, 90, 91, 127, 127, 127 };
1044          const int spe3[] = { 1, 32, 28, 35, 66, 48, 89, 59, 95, 65, 99, 73,          const int spe3[] = { 1, 32, 28, 35, 66, 48, 89, 59, 95, 65, 99, 73,
1045                               117, 127, 127, 127 };                               117, 127, 127, 127 };
1046          const int spe4[] = { 1, 4, 23, 5, 49, 13, 57, 17, 92, 57, 122, 127,          const int spe4[] = { 1, 4, 23, 5, 49, 13, 57, 17, 92, 57, 122, 127,
1047                               127, 127 };                               127, 127 };
1048            
1049          const int* const curves[] = { non0, non1, non2, non3, non4,          const int* const curves[] = { non0, non1, non2, non3, non4,
1050                                        lin0, lin1, lin2, lin3, lin4,                                        lin0, lin1, lin2, lin3, lin4,
1051                                        spe0, spe1, spe2, spe3, spe4 };                                        spe0, spe1, spe2, spe3, spe4 };
1052            
1053          double* const table = new double[128];          double* const table = new double[128];
1054    
1055          const int* curve = curves[curveType * 5 + depth];          const int* curve = curves[curveType * 5 + depth];
1056          const int s = scaling == 0 ? 20 : scaling; // 0 or 20 means no scaling          const int s = scaling == 0 ? 20 : scaling; // 0 or 20 means no scaling
1057            
1058          table[0] = 0;          table[0] = 0;
1059          for (int x = 1 ; x < 128 ; x++) {          for (int x = 1 ; x < 128 ; x++) {
1060    
1061              if (x > curve[2]) curve += 2;              if (x > curve[2]) curve += 2;
1062              double y = curve[1] + (x - curve[0]) *              double y = curve[1] + (x - curve[0]) *
1063                  (double(curve[3] - curve[1]) / (curve[2] - curve[0]));                  (double(curve[3] - curve[1]) / (curve[2] - curve[0]));
1064              y = y / 127;              y = y / 127;
1065    
# Line 1135  namespace gig { Line 1156  namespace gig {
1156                  }                  }
1157              }              }
1158    
1159                // jump to start of the wave pool indices (if not already there)
1160                File* file = (File*) GetParent()->GetParent();
1161                if (file->pVersion && file->pVersion->major == 3)
1162                    _3lnk->SetPos(68); // version 3 has a different 3lnk structure
1163                else
1164                    _3lnk->SetPos(44);
1165    
1166              // load sample references              // load sample references
             _3lnk->SetPos(44); // jump to start of the wave pool indices (if not already there)  
1167              for (uint i = 0; i < DimensionRegions; i++) {              for (uint i = 0; i < DimensionRegions; i++) {
1168                  uint32_t wavepoolindex = _3lnk->ReadUint32();                  uint32_t wavepoolindex = _3lnk->ReadUint32();
1169                  pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex);                  pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex);

Legend:
Removed from v.316  
changed lines
  Added in v.317

  ViewVC Help
Powered by ViewVC