/[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 518 by schoenebeck, Sun May 8 16:19:34 2005 UTC revision 666 by persson, Sun Jun 19 15:18:59 2005 UTC
# Line 243  namespace { Line 243  namespace {
243      unsigned int Sample::Instances = 0;      unsigned int Sample::Instances = 0;
244      buffer_t     Sample::InternalDecompressionBuffer;      buffer_t     Sample::InternalDecompressionBuffer;
245    
246      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) {
247          Instances++;          Instances++;
248            FileNo = fileNo;
249    
250          RIFF::Chunk* _3gix = waveList->GetSubChunk(CHUNK_ID_3GIX);          RIFF::Chunk* _3gix = waveList->GetSubChunk(CHUNK_ID_3GIX);
251          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 1162  namespace {
1162                  VCFType = vcf_type_lowpassturbo;                  VCFType = vcf_type_lowpassturbo;
1163          }          }
1164    
1165          // get the corresponding velocity->volume table from the table map or create & calculate that table if it doesn't exist yet          pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve,
1166          uint32_t tableKey = (VelocityResponseCurve<<16) | (VelocityResponseDepth<<8) | VelocityResponseCurveScaling;                                                       VelocityResponseDepth,
1167                                                         VelocityResponseCurveScaling);
1168    
1169            curve_type_t curveType = ReleaseVelocityResponseCurve;
1170            uint8_t depth = ReleaseVelocityResponseDepth;
1171    
1172            // this models a strange behaviour or bug in GSt: two of the
1173            // velocity response curves for release time are not used even
1174            // if specified, instead another curve is chosen.
1175    
1176            if ((curveType == curve_type_nonlinear && depth == 0) ||
1177                (curveType == curve_type_special   && depth == 4)) {
1178                curveType = curve_type_nonlinear;
1179                depth = 3;
1180            }
1181            pVelocityReleaseTable = GetVelocityTable(curveType, depth, 0);
1182    
1183            SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360));
1184        }
1185    
1186        // get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet
1187        double* DimensionRegion::GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling)
1188        {
1189            double* table;
1190            uint32_t tableKey = (curveType<<16) | (depth<<8) | scaling;
1191          if (pVelocityTables->count(tableKey)) { // if key exists          if (pVelocityTables->count(tableKey)) { // if key exists
1192              pVelocityAttenuationTable = (*pVelocityTables)[tableKey];              table = (*pVelocityTables)[tableKey];
1193          }          }
1194          else {          else {
1195              pVelocityAttenuationTable =              table = CreateVelocityTable(curveType, depth, scaling);
1196                  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  
1197          }          }
1198            return table;
         SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360));  
1199      }      }
1200    
1201      leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) {      leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) {
# Line 1325  namespace { Line 1346  namespace {
1346          return pVelocityAttenuationTable[MIDIKeyVelocity];          return pVelocityAttenuationTable[MIDIKeyVelocity];
1347      }      }
1348    
1349        double DimensionRegion::GetVelocityRelease(uint8_t MIDIKeyVelocity) {
1350            return pVelocityReleaseTable[MIDIKeyVelocity];
1351        }
1352    
1353      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) {
1354    
1355          // line-segment approximations of the 15 velocity curves          // line-segment approximations of the 15 velocity curves
# Line 1589  namespace { Line 1614  namespace {
1614          if ((int32_t)WavePoolTableIndex == -1) return NULL;          if ((int32_t)WavePoolTableIndex == -1) return NULL;
1615          File* file = (File*) GetParent()->GetParent();          File* file = (File*) GetParent()->GetParent();
1616          unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex];          unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex];
1617            unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex];
1618          Sample* sample = file->GetFirstSample(pProgress);          Sample* sample = file->GetFirstSample(pProgress);
1619          while (sample) {          while (sample) {
1620              if (sample->ulWavePoolOffset == soughtoffset) return static_cast<gig::Sample*>(pSample = sample);              if (sample->ulWavePoolOffset == soughtoffset &&
1621                    sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(pSample = sample);
1622              sample = file->GetNextSample();              sample = file->GetNextSample();
1623          }          }
1624          return NULL;          return NULL;
# Line 1734  namespace { Line 1761  namespace {
1761              pInstruments->clear();              pInstruments->clear();
1762              delete pInstruments;              delete pInstruments;
1763          }          }
1764            // free extension files
1765            for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)
1766                delete *i;
1767      }      }
1768    
1769      Sample* File::GetFirstSample(progress_t* pProgress) {      Sample* File::GetFirstSample(progress_t* pProgress) {
# Line 1750  namespace { Line 1780  namespace {
1780      }      }
1781    
1782      void File::LoadSamples(progress_t* pProgress) {      void File::LoadSamples(progress_t* pProgress) {
1783          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);  
   
                     if (!pSamples) pSamples = new SampleList;  
                     unsigned long waveFileOffset = wave->GetFilePos();  
                     pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));  
1784    
1785                      iSampleIndex++;          // just for progress calculation
1786            int iSampleIndex  = 0;
1787            int iTotalSamples = WavePoolCount;
1788    
1789            // check if samples should be loaded from extension files
1790            int lastFileNo = 0;
1791            for (int i = 0 ; i < WavePoolCount ; i++) {
1792                if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i];
1793            }
1794            String name(pRIFF->Filename);
1795            int nameLen = pRIFF->Filename.length();
1796            char suffix[6];
1797            if (nameLen > 4 && pRIFF->Filename.substr(nameLen - 4) == ".gig") nameLen -= 4;
1798    
1799            for (int fileNo = 0 ; ; ) {
1800                RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL);
1801                if (wvpl) {
1802                    unsigned long wvplFileOffset = wvpl->GetFilePos();
1803                    RIFF::List* wave = wvpl->GetFirstSubList();
1804                    while (wave) {
1805                        if (wave->GetListType() == LIST_TYPE_WAVE) {
1806                            // notify current progress
1807                            const float subprogress = (float) iSampleIndex / (float) iTotalSamples;
1808                            __notify_progress(pProgress, subprogress);
1809    
1810                            if (!pSamples) pSamples = new SampleList;
1811                            unsigned long waveFileOffset = wave->GetFilePos();
1812                            pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo));
1813    
1814                            iSampleIndex++;
1815                        }
1816                        wave = wvpl->GetNextSubList();
1817                  }                  }
1818                  wave = wvpl->GetNextSubList();  
1819                    if (fileNo == lastFileNo) break;
1820    
1821                    // open extension file (*.gx01, *.gx02, ...)
1822                    fileNo++;
1823                    sprintf(suffix, ".gx%02d", fileNo);
1824                    name.replace(nameLen, 5, suffix);
1825                    file = new RIFF::File(name);
1826                    ExtensionFiles.push_back(file);
1827              }              }
1828              __notify_progress(pProgress, 1.0); // notify done              else throw gig::Exception("Mandatory <wvpl> chunk not found.");
1829          }          }
1830          else throw gig::Exception("Mandatory <wvpl> chunk not found.");  
1831            __notify_progress(pProgress, 1.0); // notify done
1832      }      }
1833    
1834      Instrument* File::GetFirstInstrument() {      Instrument* File::GetFirstInstrument() {

Legend:
Removed from v.518  
changed lines
  Added in v.666

  ViewVC Help
Powered by ViewVC