/[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 516 by schoenebeck, Sat May 7 21:24:04 2005 UTC revision 695 by persson, Sat Jul 16 19:36:23 2005 UTC
# Line 132  namespace { Line 132  namespace {
132      {      {
133          // Note: The 24 bits are truncated to 16 bits for now.          // Note: The 24 bits are truncated to 16 bits for now.
134    
135          // Note: The calculation of the initial value of y is strange          int y, dy, ddy, dddy;
         // and not 100% correct. What should the first two parameters  
         // really be used for? Why are they two? The correct value for  
         // y seems to lie somewhere between the values of the first  
         // two parameters.  
         //  
         // Strange thing #2: The formula in SKIP_ONE gives values for  
         // y that are twice as high as they should be. That's why  
         // COPY_ONE shifts an extra step, and also why y is  
         // initialized with a sum instead of a mean value.  
   
         int y, dy, ddy;  
   
136          const int shift = 8 - truncatedBits;          const int shift = 8 - truncatedBits;
         const int shift1 = shift + 1;  
137    
138  #define GET_PARAMS(params)                              \  #define GET_PARAMS(params)                      \
139          y = (get24(params) + get24((params) + 3));      \          y    = get24(params);                   \
140          dy  = get24((params) + 6);                      \          dy   = y - get24((params) + 3);         \
141          ddy = get24((params) + 9)          ddy  = get24((params) + 6);             \
142            dddy = get24((params) + 9)
143    
144  #define SKIP_ONE(x)                             \  #define SKIP_ONE(x)                             \
145          ddy -= (x);                             \          dddy -= (x);                            \
146          dy -= ddy;                              \          ddy  -= dddy;                           \
147          y -= dy          dy   =  -dy - ddy;                      \
148            y    += dy
149    
150  #define COPY_ONE(x)                             \  #define COPY_ONE(x)                             \
151          SKIP_ONE(x);                            \          SKIP_ONE(x);                            \
152          *pDst = y >> shift1;                    \          *pDst = y >> shift;                     \
153          pDst += dstStep          pDst += dstStep
154    
155          switch (compressionmode) {          switch (compressionmode) {
# Line 243  namespace { Line 232  namespace {
232      unsigned int Sample::Instances = 0;      unsigned int Sample::Instances = 0;
233      buffer_t     Sample::InternalDecompressionBuffer;      buffer_t     Sample::InternalDecompressionBuffer;
234    
235      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, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) {
236          Instances++;          Instances++;
237            FileNo = fileNo;
238    
239          RIFF::Chunk* _3gix = waveList->GetSubChunk(CHUNK_ID_3GIX);          RIFF::Chunk* _3gix = waveList->GetSubChunk(CHUNK_ID_3GIX);
240          if (!_3gix) throw gig::Exception("Mandatory chunks in <wave> list chunk not found.");          if (!_3gix) throw gig::Exception("Mandatory chunks in <wave> list chunk not found.");
# Line 1161  namespace { Line 1151  namespace {
1151                  VCFType = vcf_type_lowpassturbo;                  VCFType = vcf_type_lowpassturbo;
1152          }          }
1153    
1154          // get the corresponding velocity->volume table from the table map or create & calculate that table if it doesn't exist yet          pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve,
1155          uint32_t tableKey = (VelocityResponseCurve<<16) | (VelocityResponseDepth<<8) | VelocityResponseCurveScaling;                                                       VelocityResponseDepth,
1156                                                         VelocityResponseCurveScaling);
1157    
1158            curve_type_t curveType = ReleaseVelocityResponseCurve;
1159            uint8_t depth = ReleaseVelocityResponseDepth;
1160    
1161            // this models a strange behaviour or bug in GSt: two of the
1162            // velocity response curves for release time are not used even
1163            // if specified, instead another curve is chosen.
1164    
1165            if ((curveType == curve_type_nonlinear && depth == 0) ||
1166                (curveType == curve_type_special   && depth == 4)) {
1167                curveType = curve_type_nonlinear;
1168                depth = 3;
1169            }
1170            pVelocityReleaseTable = GetVelocityTable(curveType, depth, 0);
1171    
1172            SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360));
1173        }
1174    
1175        // get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet
1176        double* DimensionRegion::GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling)
1177        {
1178            double* table;
1179            uint32_t tableKey = (curveType<<16) | (depth<<8) | scaling;
1180          if (pVelocityTables->count(tableKey)) { // if key exists          if (pVelocityTables->count(tableKey)) { // if key exists
1181              pVelocityAttenuationTable = (*pVelocityTables)[tableKey];              table = (*pVelocityTables)[tableKey];
1182          }          }
1183          else {          else {
1184              pVelocityAttenuationTable =              table = CreateVelocityTable(curveType, depth, scaling);
1185                  CreateVelocityTable(VelocityResponseCurve,              (*pVelocityTables)[tableKey] = table; // put the new table into the tables map
                                     VelocityResponseDepth,  
                                     VelocityResponseCurveScaling);  
             (*pVelocityTables)[tableKey] = pVelocityAttenuationTable; // put the new table into the tables map  
1186          }          }
1187            return table;
         SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360));  
1188      }      }
1189    
1190      leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) {      leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) {
# Line 1325  namespace { Line 1335  namespace {
1335          return pVelocityAttenuationTable[MIDIKeyVelocity];          return pVelocityAttenuationTable[MIDIKeyVelocity];
1336      }      }
1337    
1338        double DimensionRegion::GetVelocityRelease(uint8_t MIDIKeyVelocity) {
1339            return pVelocityReleaseTable[MIDIKeyVelocity];
1340        }
1341    
1342      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) {
1343    
1344          // line-segment approximations of the 15 velocity curves          // line-segment approximations of the 15 velocity curves
# Line 1589  namespace { Line 1603  namespace {
1603          if ((int32_t)WavePoolTableIndex == -1) return NULL;          if ((int32_t)WavePoolTableIndex == -1) return NULL;
1604          File* file = (File*) GetParent()->GetParent();          File* file = (File*) GetParent()->GetParent();
1605          unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex];          unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex];
1606            unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex];
1607          Sample* sample = file->GetFirstSample(pProgress);          Sample* sample = file->GetFirstSample(pProgress);
1608          while (sample) {          while (sample) {
1609              if (sample->ulWavePoolOffset == soughtoffset) return static_cast<gig::Sample*>(pSample = sample);              if (sample->ulWavePoolOffset == soughtoffset &&
1610                    sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(pSample = sample);
1611              sample = file->GetNextSample();              sample = file->GetNextSample();
1612          }          }
1613          return NULL;          return NULL;
# Line 1734  namespace { Line 1750  namespace {
1750              pInstruments->clear();              pInstruments->clear();
1751              delete pInstruments;              delete pInstruments;
1752          }          }
1753            // free extension files
1754            for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)
1755                delete *i;
1756      }      }
1757    
1758      Sample* File::GetFirstSample(progress_t* pProgress) {      Sample* File::GetFirstSample(progress_t* pProgress) {
# Line 1750  namespace { Line 1769  namespace {
1769      }      }
1770    
1771      void File::LoadSamples(progress_t* pProgress) {      void File::LoadSamples(progress_t* pProgress) {
1772          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);          RIFF::File* file = pRIFF;
         if (wvpl) {  
             // just for progress calculation  
             int iSampleIndex  = 0;  
             int iTotalSamples = wvpl->CountSubLists(LIST_TYPE_WAVE);  
   
             unsigned long wvplFileOffset = wvpl->GetFilePos();  
             RIFF::List* wave = wvpl->GetFirstSubList();  
             while (wave) {  
                 if (wave->GetListType() == LIST_TYPE_WAVE) {  
                     // notify current progress  
                     const float subprogress = (float) iSampleIndex / (float) iTotalSamples;  
                     __notify_progress(pProgress, subprogress);  
1773    
1774                      if (!pSamples) pSamples = new SampleList;          // just for progress calculation
1775                      unsigned long waveFileOffset = wave->GetFilePos();          int iSampleIndex  = 0;
1776                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));          int iTotalSamples = WavePoolCount;
1777    
1778            // check if samples should be loaded from extension files
1779            int lastFileNo = 0;
1780            for (int i = 0 ; i < WavePoolCount ; i++) {
1781                if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i];
1782            }
1783            String name(pRIFF->Filename);
1784            int nameLen = pRIFF->Filename.length();
1785            char suffix[6];
1786            if (nameLen > 4 && pRIFF->Filename.substr(nameLen - 4) == ".gig") nameLen -= 4;
1787    
1788            for (int fileNo = 0 ; ; ) {
1789                RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL);
1790                if (wvpl) {
1791                    unsigned long wvplFileOffset = wvpl->GetFilePos();
1792                    RIFF::List* wave = wvpl->GetFirstSubList();
1793                    while (wave) {
1794                        if (wave->GetListType() == LIST_TYPE_WAVE) {
1795                            // notify current progress
1796                            const float subprogress = (float) iSampleIndex / (float) iTotalSamples;
1797                            __notify_progress(pProgress, subprogress);
1798    
1799                            if (!pSamples) pSamples = new SampleList;
1800                            unsigned long waveFileOffset = wave->GetFilePos();
1801                            pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo));
1802    
1803                      iSampleIndex++;                          iSampleIndex++;
1804                        }
1805                        wave = wvpl->GetNextSubList();
1806                  }                  }
1807                  wave = wvpl->GetNextSubList();  
1808                    if (fileNo == lastFileNo) break;
1809    
1810                    // open extension file (*.gx01, *.gx02, ...)
1811                    fileNo++;
1812                    sprintf(suffix, ".gx%02d", fileNo);
1813                    name.replace(nameLen, 5, suffix);
1814                    file = new RIFF::File(name);
1815                    ExtensionFiles.push_back(file);
1816              }              }
1817              __notify_progress(pProgress, 1.0); // notify done              else throw gig::Exception("Mandatory <wvpl> chunk not found.");
1818          }          }
1819          else throw gig::Exception("Mandatory <wvpl> chunk not found.");  
1820            __notify_progress(pProgress, 1.0); // notify done
1821      }      }
1822    
1823      Instrument* File::GetFirstInstrument() {      Instrument* File::GetFirstInstrument() {
# Line 1865  namespace { Line 1908  namespace {
1908          std::cout << "gig::Exception: " << Message << std::endl;          std::cout << "gig::Exception: " << Message << std::endl;
1909      }      }
1910    
1911    
1912    // *************** functions ***************
1913    // *
1914    
1915        /**
1916         * Returns the name of this C++ library. This is usually "libgig" of
1917         * course. This call is equivalent to RIFF::libraryName() and
1918         * DLS::libraryName().
1919         */
1920        String libraryName() {
1921            return PACKAGE;
1922        }
1923    
1924        /**
1925         * Returns version of this C++ library. This call is equivalent to
1926         * RIFF::libraryVersion() and DLS::libraryVersion().
1927         */
1928        String libraryVersion() {
1929            return VERSION;
1930        }
1931    
1932  } // namespace gig  } // namespace gig

Legend:
Removed from v.516  
changed lines
  Added in v.695

  ViewVC Help
Powered by ViewVC