/[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 2912 by schoenebeck, Tue May 17 14:30:10 2016 UTC revision 3117 by schoenebeck, Sun Apr 16 23:20:30 2017 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file access library    *   *   libgig - C++ cross-platform Gigasampler format file access library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2016 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2017 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  *
# Line 269  namespace { Line 269  namespace {
269       * steps.       * steps.
270       *       *
271       * Once the whole data was processed by __calculateCRC(), one should       * Once the whole data was processed by __calculateCRC(), one should
272       * call __encodeCRC() to get the final CRC result.       * call __finalizeCRC() to get the final CRC result.
273       *       *
274       * @param buf     - pointer to data the CRC shall be calculated of       * @param buf     - pointer to data the CRC shall be calculated of
275       * @param bufSize - size of the data to be processed       * @param bufSize - size of the data to be processed
276       * @param crc     - variable the CRC sum shall be stored to       * @param crc     - variable the CRC sum shall be stored to
277       */       */
278      static void __calculateCRC(unsigned char* buf, int bufSize, uint32_t& crc) {      static void __calculateCRC(unsigned char* buf, size_t bufSize, uint32_t& crc) {
279          for (int i = 0 ; i < bufSize ; i++) {          for (size_t i = 0 ; i < bufSize ; i++) {
280              crc = __CRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >> 8);              crc = __CRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >> 8);
281          }          }
282      }      }
# Line 286  namespace { Line 286  namespace {
286       *       *
287       * @param crc - variable previously passed to __calculateCRC()       * @param crc - variable previously passed to __calculateCRC()
288       */       */
289      inline static uint32_t __encodeCRC(const uint32_t& crc) {      inline static void __finalizeCRC(uint32_t& crc) {
290          return crc ^ 0xffffffff;          crc ^= 0xffffffff;
291      }      }
292    
293    
# Line 318  namespace { Line 318  namespace {
318  // *************** Sample ***************  // *************** Sample ***************
319  // *  // *
320    
321      unsigned int Sample::Instances = 0;      size_t       Sample::Instances = 0;
322      buffer_t     Sample::InternalDecompressionBuffer;      buffer_t     Sample::InternalDecompressionBuffer;
323    
324      /** @brief Constructor.      /** @brief Constructor.
# Line 338  namespace { Line 338  namespace {
338       *                         ('wvpl') list chunk       *                         ('wvpl') list chunk
339       * @param fileNo         - number of an extension file where this sample       * @param fileNo         - number of an extension file where this sample
340       *                         is located, 0 otherwise       *                         is located, 0 otherwise
341         * @param index          - wave pool index of sample (may be -1 on new sample)
342       */       */
343      Sample::Sample(File* pFile, RIFF::List* waveList, file_offset_t WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) {      Sample::Sample(File* pFile, RIFF::List* waveList, file_offset_t WavePoolOffset, unsigned long fileNo, int index)
344            : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset)
345        {
346          static const DLS::Info::string_length_t fixedStringLengths[] = {          static const DLS::Info::string_length_t fixedStringLengths[] = {
347              { CHUNK_ID_INAM, 64 },              { CHUNK_ID_INAM, 64 },
348              { 0, 0 }              { 0, 0 }
# Line 349  namespace { Line 352  namespace {
352          FileNo = fileNo;          FileNo = fileNo;
353    
354          __resetCRC(crc);          __resetCRC(crc);
355            // if this is not a new sample, try to get the sample's already existing
356            // CRC32 checksum from disk, this checksum will reflect the sample's CRC32
357            // checksum of the time when the sample was consciously modified by the
358            // user for the last time (by calling Sample::Write() that is).
359            if (index >= 0) { // not a new file ...
360                try {
361                    uint32_t crc = pFile->GetSampleChecksumByIndex(index);
362                    this->crc = crc;
363                } catch (...) {}
364            }
365    
366          pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX);          pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX);
367          if (pCk3gix) {          if (pCk3gix) {
# Line 789  namespace { Line 802  namespace {
802       * FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with       * FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with
803       * other formats will fail!       * other formats will fail!
804       *       *
805       * @param iNewSize - new sample wave data size in sample points (must be       * @param NewSize - new sample wave data size in sample points (must be
806       *                   greater than zero)       *                  greater than zero)
807       * @throws DLS::Excecption if FormatTag != DLS_WAVE_FORMAT_PCM       * @throws DLS::Excecption if FormatTag != DLS_WAVE_FORMAT_PCM
808       *                         or if \a iNewSize is less than 1       * @throws DLS::Exception if \a NewSize is less than 1 or unrealistic large
809       * @throws gig::Exception if existing sample is compressed       * @throws gig::Exception if existing sample is compressed
810       * @see DLS::Sample::GetSize(), DLS::Sample::FrameSize,       * @see DLS::Sample::GetSize(), DLS::Sample::FrameSize,
811       *      DLS::Sample::FormatTag, File::Save()       *      DLS::Sample::FormatTag, File::Save()
812       */       */
813      void Sample::Resize(int iNewSize) {      void Sample::Resize(file_offset_t NewSize) {
814          if (Compressed) throw gig::Exception("There is no support for modifying compressed samples (yet)");          if (Compressed) throw gig::Exception("There is no support for modifying compressed samples (yet)");
815          DLS::Sample::Resize(iNewSize);          DLS::Sample::Resize(NewSize);
816      }      }
817    
818      /**      /**
# Line 1281  namespace { Line 1294  namespace {
1294          // if this is the last write, update the checksum chunk in the          // if this is the last write, update the checksum chunk in the
1295          // file          // file
1296          if (pCkData->GetPos() == pCkData->GetSize()) {          if (pCkData->GetPos() == pCkData->GetSize()) {
1297                __finalizeCRC(crc);
1298              File* pFile = static_cast<File*>(GetParent());              File* pFile = static_cast<File*>(GetParent());
1299              pFile->SetSampleChecksum(this, __encodeCRC(crc));              pFile->SetSampleChecksum(this, crc);
1300          }          }
1301          return res;          return res;
1302      }      }
# Line 1341  namespace { Line 1355  namespace {
1355          return pGroup;          return pGroup;
1356      }      }
1357    
1358        /**
1359         * Returns the CRC-32 checksum of the sample's raw wave form data at the
1360         * time when this sample's wave form data was modified for the last time
1361         * by calling Write(). This checksum only covers the raw wave form data,
1362         * not any meta informations like i.e. bit depth or loop points. Since
1363         * this method just returns the checksum stored for this sample i.e. when
1364         * the gig file was loaded, this method returns immediately. So it does no
1365         * recalcuation of the checksum with the currently available sample wave
1366         * form data.
1367         *
1368         * @see VerifyWaveData()
1369         */
1370        uint32_t Sample::GetWaveDataCRC32Checksum() {
1371            return crc;
1372        }
1373    
1374        /**
1375         * Checks the integrity of this sample's raw audio wave data. Whenever a
1376         * Sample's raw wave data is intentionally modified (i.e. by calling
1377         * Write() and supplying the new raw audio wave form data) a CRC32 checksum
1378         * is calculated and stored/updated for this sample, along to the sample's
1379         * meta informations.
1380         *
1381         * Now by calling this method the current raw audio wave data is checked
1382         * against the already stored CRC32 check sum in order to check whether the
1383         * sample data had been damaged unintentionally for some reason. Since by
1384         * calling this method always the entire raw audio wave data has to be
1385         * read, verifying all samples this way may take a long time accordingly.
1386         * And that's also the reason why the sample integrity is not checked by
1387         * default whenever a gig file is loaded. So this method must be called
1388         * explicitly to fulfill this task.
1389         *
1390         * @param pActually - (optional) if provided, will be set to the actually
1391         *                    calculated checksum of the current raw wave form data,
1392         *                    you can get the expected checksum instead by calling
1393         *                    GetWaveDataCRC32Checksum()
1394         * @returns true if sample is OK or false if the sample is damaged
1395         * @throws Exception if no checksum had been stored to disk for this
1396         *         sample yet, or on I/O issues
1397         * @see GetWaveDataCRC32Checksum()
1398         */
1399        bool Sample::VerifyWaveData(uint32_t* pActually) {
1400            //File* pFile = static_cast<File*>(GetParent());
1401            uint32_t crc = CalculateWaveDataChecksum();
1402            if (pActually) *pActually = crc;
1403            return crc == this->crc;
1404        }
1405    
1406        uint32_t Sample::CalculateWaveDataChecksum() {
1407            const size_t sz = 20*1024; // 20kB buffer size
1408            std::vector<uint8_t> buffer(sz);
1409            buffer.resize(sz);
1410    
1411            const size_t n = sz / FrameSize;
1412            SetPos(0);
1413            uint32_t crc = 0;
1414            __resetCRC(crc);
1415            while (true) {
1416                file_offset_t nRead = Read(&buffer[0], n);
1417                if (nRead <= 0) break;
1418                __calculateCRC(&buffer[0], nRead * FrameSize, crc);
1419            }
1420            __finalizeCRC(crc);
1421            return crc;
1422        }
1423    
1424      Sample::~Sample() {      Sample::~Sample() {
1425          Instances--;          Instances--;
1426          if (!Instances && InternalDecompressionBuffer.Size) {          if (!Instances && InternalDecompressionBuffer.Size) {
# Line 1357  namespace { Line 1437  namespace {
1437  // *************** DimensionRegion ***************  // *************** DimensionRegion ***************
1438  // *  // *
1439    
1440      uint                               DimensionRegion::Instances       = 0;      size_t                             DimensionRegion::Instances       = 0;
1441      DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL;      DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL;
1442    
1443      DimensionRegion::DimensionRegion(Region* pParent, RIFF::List* _3ewl) : DLS::Sampler(_3ewl) {      DimensionRegion::DimensionRegion(Region* pParent, RIFF::List* _3ewl) : DLS::Sampler(_3ewl) {
# Line 1551  namespace { Line 1631  namespace {
1631              EG2Attack                       = 0.0;              EG2Attack                       = 0.0;
1632              EG2Decay1                       = 0.005;              EG2Decay1                       = 0.005;
1633              EG2Sustain                      = 1000;              EG2Sustain                      = 1000;
1634              EG2Release                      = 0.3;              EG2Release                      = 60;
1635              LFO2ControlDepth                = 0;              LFO2ControlDepth                = 0;
1636              LFO2Frequency                   = 1.0;              LFO2Frequency                   = 1.0;
1637              LFO2InternalDepth               = 0;              LFO2InternalDepth               = 0;
# Line 1750  namespace { Line 1830  namespace {
1830    
1831          // update '3ewa' chunk with DimensionRegion's current settings          // update '3ewa' chunk with DimensionRegion's current settings
1832    
1833          const uint32_t chunksize = _3ewa->GetNewSize();          const uint32_t chunksize = (uint32_t) _3ewa->GetNewSize();
1834          store32(&pData[0], chunksize); // unknown, always chunk size?          store32(&pData[0], chunksize); // unknown, always chunk size?
1835    
1836          const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency);          const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency);
# Line 3106  namespace { Line 3186  namespace {
3186          int step = 1;          int step = 1;
3187          for (int i = 0 ; i < veldim ; i++) step <<= pDimensionDefinitions[i].bits;          for (int i = 0 ; i < veldim ; i++) step <<= pDimensionDefinitions[i].bits;
3188          int skipveldim = (step << pDimensionDefinitions[veldim].bits) - step;          int skipveldim = (step << pDimensionDefinitions[veldim].bits) - step;
         int end = step * pDimensionDefinitions[veldim].zones;  
3189    
3190          // loop through all dimension regions for all dimensions except the velocity dimension          // loop through all dimension regions for all dimensions except the velocity dimension
3191          int dim[8] = { 0 };          int dim[8] = { 0 };
3192          for (int i = 0 ; i < DimensionRegions ; i++) {          for (int i = 0 ; i < DimensionRegions ; i++) {
3193                const int end = i + step * pDimensionDefinitions[veldim].zones;
3194    
3195                // create a velocity table for all cases where the velocity zone is zero
3196              if (pDimensionRegions[i]->DimensionUpperLimits[veldim] ||              if (pDimensionRegions[i]->DimensionUpperLimits[veldim] ||
3197                  pDimensionRegions[i]->VelocityUpperLimit) {                  pDimensionRegions[i]->VelocityUpperLimit) {
3198                  // create the velocity table                  // create the velocity table
# Line 3142  namespace { Line 3223  namespace {
3223                  }                  }
3224              }              }
3225    
3226                // jump to the next case where the velocity zone is zero
3227              int j;              int j;
3228              int shift = 0;              int shift = 0;
3229              for (j = 0 ; j < Dimensions ; j++) {              for (j = 0 ; j < Dimensions ; j++) {
# Line 3716  namespace { Line 3798  namespace {
3798      DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) {      DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) {
3799          uint8_t bits;          uint8_t bits;
3800          int veldim = -1;          int veldim = -1;
3801          int velbitpos;          int velbitpos = 0;
3802          int bitpos = 0;          int bitpos = 0;
3803          int dimregidx = 0;          int dimregidx = 0;
3804          for (uint i = 0; i < Dimensions; i++) {          for (uint i = 0; i < Dimensions; i++) {
# Line 3765  namespace { Line 3847  namespace {
3847      int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) {      int Region::GetDimensionRegionIndexByValue(const uint DimValues[8]) {
3848          uint8_t bits;          uint8_t bits;
3849          int veldim = -1;          int veldim = -1;
3850          int velbitpos;          int velbitpos = 0;
3851          int bitpos = 0;          int bitpos = 0;
3852          int dimregidx = 0;          int dimregidx = 0;
3853          for (uint i = 0; i < Dimensions; i++) {          for (uint i = 0; i < Dimensions; i++) {
# Line 3850  namespace { Line 3932  namespace {
3932          if ((int32_t)WavePoolTableIndex == -1) return NULL;          if ((int32_t)WavePoolTableIndex == -1) return NULL;
3933          File* file = (File*) GetParent()->GetParent();          File* file = (File*) GetParent()->GetParent();
3934          if (!file->pWavePoolTable) return NULL;          if (!file->pWavePoolTable) return NULL;
3935          if (file->HasMonolithicLargeFilePolicy()) {          // for new files or files >= 2 GB use 64 bit wave pool offsets
3936            if (file->pRIFF->IsNew() || (file->pRIFF->GetCurrentFileSize() >> 31)) {
3937                // use 64 bit wave pool offsets (treating this as large file)
3938              uint64_t soughtoffset =              uint64_t soughtoffset =
3939                  uint64_t(file->pWavePoolTable[WavePoolTableIndex]) |                  uint64_t(file->pWavePoolTable[WavePoolTableIndex]) |
3940                  uint64_t(file->pWavePoolTableHi[WavePoolTableIndex]) << 32;                  uint64_t(file->pWavePoolTableHi[WavePoolTableIndex]) << 32;
# Line 3861  namespace { Line 3945  namespace {
3945                  sample = file->GetNextSample();                  sample = file->GetNextSample();
3946              }              }
3947          } else {          } else {
3948                // use extension files and 32 bit wave pool offsets
3949              file_offset_t soughtoffset = file->pWavePoolTable[WavePoolTableIndex];              file_offset_t soughtoffset = file->pWavePoolTable[WavePoolTableIndex];
3950              file_offset_t soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex];              file_offset_t soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex];
3951              Sample* sample = file->GetFirstSample(pProgress);              Sample* sample = file->GetFirstSample(pProgress);
# Line 4111  namespace { Line 4196  namespace {
4196              // to handle potential future extensions of the header              // to handle potential future extensions of the header
4197              ckScri->SetPos(sizeof(int32_t) + headerSize);              ckScri->SetPos(sizeof(int32_t) + headerSize);
4198              // read actual script data              // read actual script data
4199              uint32_t scriptSize = ckScri->GetSize() - ckScri->GetPos();              uint32_t scriptSize = uint32_t(ckScri->GetSize() - ckScri->GetPos());
4200              data.resize(scriptSize);              data.resize(scriptSize);
4201              for (int i = 0; i < scriptSize; ++i)              for (int i = 0; i < scriptSize; ++i)
4202                  data[i] = ckScri->ReadUint8();                  data[i] = ckScri->ReadUint8();
# Line 4162  namespace { Line 4247  namespace {
4247          // recalculate CRC32 check sum          // recalculate CRC32 check sum
4248          __resetCRC(crc);          __resetCRC(crc);
4249          __calculateCRC(&data[0], data.size(), crc);          __calculateCRC(&data[0], data.size(), crc);
4250          __encodeCRC(crc);          __finalizeCRC(crc);
4251          // make sure chunk exists and has the required size          // make sure chunk exists and has the required size
4252          const int chunkSize = 7*sizeof(int32_t) + Name.size() + data.size();          const file_offset_t chunkSize = (file_offset_t) 7*sizeof(int32_t) + Name.size() + data.size();
4253          if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize);          if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize);
4254          else pChunk->Resize(chunkSize);          else pChunk->Resize(chunkSize);
4255          // fill the chunk data to be written to disk          // fill the chunk data to be written to disk
4256          uint8_t* pData = (uint8_t*) pChunk->LoadChunkData();          uint8_t* pData = (uint8_t*) pChunk->LoadChunkData();
4257          int pos = 0;          int pos = 0;
4258          store32(&pData[pos], 6*sizeof(int32_t) + Name.size()); // total header size          store32(&pData[pos], uint32_t(6*sizeof(int32_t) + Name.size())); // total header size
4259          pos += sizeof(int32_t);          pos += sizeof(int32_t);
4260          store32(&pData[pos], Compression);          store32(&pData[pos], Compression);
4261          pos += sizeof(int32_t);          pos += sizeof(int32_t);
# Line 4182  namespace { Line 4267  namespace {
4267          pos += sizeof(int32_t);          pos += sizeof(int32_t);
4268          store32(&pData[pos], crc);          store32(&pData[pos], crc);
4269          pos += sizeof(int32_t);          pos += sizeof(int32_t);
4270          store32(&pData[pos], Name.size());          store32(&pData[pos], (uint32_t) Name.size());
4271          pos += sizeof(int32_t);          pos += sizeof(int32_t);
4272          for (int i = 0; i < Name.size(); ++i, ++pos)          for (int i = 0; i < Name.size(); ++i, ++pos)
4273              pData[pos] = Name[i];              pData[pos] = Name[i];
# Line 4213  namespace { Line 4298  namespace {
4298          return pGroup;          return pGroup;
4299      }      }
4300    
4301        /**
4302         * Make a (semi) deep copy of the Script object given by @a orig
4303         * and assign it to this object. Note: the ScriptGroup this Script
4304         * object belongs to remains untouched by this call.
4305         *
4306         * @param orig - original Script object to be copied from
4307         */
4308        void Script::CopyAssign(const Script* orig) {
4309            Name        = orig->Name;
4310            Compression = orig->Compression;
4311            Encoding    = orig->Encoding;
4312            Language    = orig->Language;
4313            Bypass      = orig->Bypass;
4314            data        = orig->data;
4315        }
4316    
4317      void Script::RemoveAllScriptReferences() {      void Script::RemoveAllScriptReferences() {
4318          File* pFile = pGroup->pFile;          File* pFile = pGroup->pFile;
4319          for (int i = 0; pFile->GetInstrument(i); ++i) {          for (int i = 0; pFile->GetInstrument(i); ++i) {
# Line 4359  namespace { Line 4460  namespace {
4460          EffectSend = 0;          EffectSend = 0;
4461          Attenuation = 0;          Attenuation = 0;
4462          FineTune = 0;          FineTune = 0;
4463          PitchbendRange = 0;          PitchbendRange = 2;
4464          PianoReleaseMode = false;          PianoReleaseMode = false;
4465          DimensionKeyRange.low = 0;          DimensionKeyRange.low = 0;
4466          DimensionKeyRange.high = 0;          DimensionKeyRange.high = 0;
# Line 4534  namespace { Line 4635  namespace {
4635    
4636             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);
4637             if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS);             if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS);
4638             const int slotCount = pScriptRefs->size();             const int slotCount = (int) pScriptRefs->size();
4639             const int headerSize = 3 * sizeof(uint32_t);             const int headerSize = 3 * sizeof(uint32_t);
4640             const int slotSize  = 2 * sizeof(uint32_t);             const int slotSize  = 2 * sizeof(uint32_t);
4641             const int totalChunkSize = headerSize + slotCount * slotSize;             const int totalChunkSize = headerSize + slotCount * slotSize;
# Line 4570  namespace { Line 4671  namespace {
4671         if (pScriptRefs && pScriptRefs->size() > 0) {         if (pScriptRefs && pScriptRefs->size() > 0) {
4672             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);
4673             RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);             RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);
4674             const int slotCount = pScriptRefs->size();             const int slotCount = (int) pScriptRefs->size();
4675             const int headerSize = 3 * sizeof(uint32_t);             const int headerSize = 3 * sizeof(uint32_t);
4676             ckSCSL->SetPos(headerSize);             ckSCSL->SetPos(headerSize);
4677             for (int i = 0; i < slotCount; ++i) {             for (int i = 0; i < slotCount; ++i) {
4678                 uint32_t fileOffset =                 uint32_t fileOffset = uint32_t(
4679                      (*pScriptRefs)[i].script->pChunk->GetFilePos() -                      (*pScriptRefs)[i].script->pChunk->GetFilePos() -
4680                      (*pScriptRefs)[i].script->pChunk->GetPos() -                      (*pScriptRefs)[i].script->pChunk->GetPos() -
4681                      CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize());                      CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize())
4682                   );
4683                 ckSCSL->WriteUint32(&fileOffset);                 ckSCSL->WriteUint32(&fileOffset);
4684                 // jump over flags entry (containing the bypass flag)                 // jump over flags entry (containing the bypass flag)
4685                 ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos);                 ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos);
# Line 4637  namespace { Line 4739  namespace {
4739          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);
4740          Region* pNewRegion = new Region(this, rgn);          Region* pNewRegion = new Region(this, rgn);
4741          pRegions->push_back(pNewRegion);          pRegions->push_back(pNewRegion);
4742          Regions = pRegions->size();          Regions = (uint32_t) pRegions->size();
4743          // update Region key table for fast lookup          // update Region key table for fast lookup
4744          UpdateRegionKeyTable();          UpdateRegionKeyTable();
4745          // done          // done
# Line 4783  namespace { Line 4885  namespace {
4885                  for (uint s = 0; group->GetScript(s); ++s) {                  for (uint s = 0; group->GetScript(s); ++s) {
4886                      Script* script = group->GetScript(s);                      Script* script = group->GetScript(s);
4887                      if (script->pChunk) {                      if (script->pChunk) {
4888                          uint32_t offset = script->pChunk->GetFilePos() -                          uint32_t offset = uint32_t(
4889                                            script->pChunk->GetPos() -                              script->pChunk->GetFilePos() -
4890                                            CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize());                              script->pChunk->GetPos() -
4891                                CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize())
4892                            );
4893                          if (offset == soughtOffset)                          if (offset == soughtOffset)
4894                          {                          {
4895                              _ScriptPooolRef ref;                              _ScriptPooolRef ref;
# Line 4910  namespace { Line 5014  namespace {
5014       */       */
5015      void Instrument::RemoveScript(Script* pScript) {      void Instrument::RemoveScript(Script* pScript) {
5016          LoadScripts();          LoadScripts();
5017          for (int i = pScriptRefs->size() - 1; i >= 0; --i) {          for (ssize_t i = pScriptRefs->size() - 1; i >= 0; --i) {
5018              if ((*pScriptRefs)[i].script == pScript) {              if ((*pScriptRefs)[i].script == pScript) {
5019                  pScriptRefs->erase( pScriptRefs->begin() + i );                  pScriptRefs->erase( pScriptRefs->begin() + i );
5020              }              }
# Line 4932  namespace { Line 5036  namespace {
5036       * gigedit.       * gigedit.
5037       */       */
5038      uint Instrument::ScriptSlotCount() const {      uint Instrument::ScriptSlotCount() const {
5039          return pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size();          return uint(pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size());
5040      }      }
5041    
5042      /** @brief Whether script execution shall be skipped.      /** @brief Whether script execution shall be skipped.
# Line 5348  namespace { Line 5452  namespace {
5452          int iTotalSamples = WavePoolCount;          int iTotalSamples = WavePoolCount;
5453    
5454          // check if samples should be loaded from extension files          // check if samples should be loaded from extension files
5455            // (only for old gig files < 2 GB)
5456          int lastFileNo = 0;          int lastFileNo = 0;
5457          if (!HasMonolithicLargeFilePolicy()) {          if (!file->IsNew() && !(file->GetCurrentFileSize() >> 31)) {
5458              for (int i = 0 ; i < WavePoolCount ; i++) {              for (int i = 0 ; i < WavePoolCount ; i++) {
5459                  if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i];                  if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i];
5460              }              }
5461          }          }
5462          String name(pRIFF->GetFileName());          String name(pRIFF->GetFileName());
5463          int nameLen = name.length();          int nameLen = (int) name.length();
5464          char suffix[6];          char suffix[6];
5465          if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4;          if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4;
5466    
# Line 5371  namespace { Line 5476  namespace {
5476                          __notify_progress(pProgress, subprogress);                          __notify_progress(pProgress, subprogress);
5477    
5478                          file_offset_t waveFileOffset = wave->GetFilePos();                          file_offset_t waveFileOffset = wave->GetFilePos();
5479                          pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo));                          pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo, iSampleIndex));
5480    
5481                          iSampleIndex++;                          iSampleIndex++;
5482                      }                      }
# Line 5524  namespace { Line 5629  namespace {
5629              mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s);              mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s);
5630              mSamples[pFile->GetSample(i)] = s;              mSamples[pFile->GetSample(i)] = s;
5631          }          }
5632            
5633            // clone script groups and their scripts
5634            for (int iGroup = 0; pFile->GetScriptGroup(iGroup); ++iGroup) {
5635                ScriptGroup* sg = pFile->GetScriptGroup(iGroup);
5636                ScriptGroup* dg = AddScriptGroup();
5637                dg->Name = "COPY" + ToString(iCallCount) + "_" + sg->Name;
5638                for (int iScript = 0; sg->GetScript(iScript); ++iScript) {
5639                    Script* ss = sg->GetScript(iScript);
5640                    Script* ds = dg->AddScript();
5641                    ds->CopyAssign(ss);
5642                }
5643            }
5644    
5645          //BUG: For some reason this method only works with this additional          //BUG: For some reason this method only works with this additional
5646          //     Save() call in between here.          //     Save() call in between here.
5647          //          //
# Line 5609  namespace { Line 5726  namespace {
5726          if (!_3crc) return;          if (!_3crc) return;
5727    
5728          // get the index of the sample          // get the index of the sample
5729          int iWaveIndex = -1;          int iWaveIndex = GetWaveTableIndexOf(pSample);
         File::SampleList::iterator iter = pSamples->begin();  
         File::SampleList::iterator end  = pSamples->end();  
         for (int index = 0; iter != end; ++iter, ++index) {  
             if (*iter == pSample) {  
                 iWaveIndex = index;  
                 break;  
             }  
         }  
5730          if (iWaveIndex < 0) throw gig::Exception("Could not update crc, could not find sample");          if (iWaveIndex < 0) throw gig::Exception("Could not update crc, could not find sample");
5731    
5732          // write the CRC-32 checksum to disk          // write the CRC-32 checksum to disk
5733          _3crc->SetPos(iWaveIndex * 8);          _3crc->SetPos(iWaveIndex * 8);
5734          uint32_t tmp = 1;          uint32_t one = 1;
5735          _3crc->WriteUint32(&tmp); // unknown, always 1?          _3crc->WriteUint32(&one); // always 1
5736          _3crc->WriteUint32(&crc);          _3crc->WriteUint32(&crc);
5737      }      }
5738    
5739        uint32_t File::GetSampleChecksum(Sample* pSample) {
5740            // get the index of the sample
5741            int iWaveIndex = GetWaveTableIndexOf(pSample);
5742            if (iWaveIndex < 0) throw gig::Exception("Could not retrieve reference crc of sample, could not resolve sample's wave table index");
5743    
5744            return GetSampleChecksumByIndex(iWaveIndex);
5745        }
5746    
5747        uint32_t File::GetSampleChecksumByIndex(int index) {
5748            if (index < 0) throw gig::Exception("Could not retrieve reference crc of sample, invalid wave pool index of sample");
5749    
5750            RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC);
5751            if (!_3crc) throw gig::Exception("Could not retrieve reference crc of sample, no checksums stored for this file yet");
5752            uint8_t* pData = (uint8_t*) _3crc->LoadChunkData();
5753            if (!pData) throw gig::Exception("Could not retrieve reference crc of sample, no checksums stored for this file yet");
5754    
5755            // read the CRC-32 checksum directly from disk
5756            size_t pos = index * 8;
5757            if (pos + 8 > _3crc->GetNewSize())
5758                throw gig::Exception("Could not retrieve reference crc of sample, could not seek to required position in crc chunk");
5759    
5760            uint32_t one = load32(&pData[pos]); // always 1
5761            if (one != 1)
5762                throw gig::Exception("Could not retrieve reference crc of sample, because reference checksum table is damaged");
5763    
5764            return load32(&pData[pos+4]);
5765        }
5766    
5767        int File::GetWaveTableIndexOf(gig::Sample* pSample) {
5768            if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned
5769            File::SampleList::iterator iter = pSamples->begin();
5770            File::SampleList::iterator end  = pSamples->end();
5771            for (int index = 0; iter != end; ++iter, ++index)
5772                if (*iter == pSample)
5773                    return index;
5774            return -1;
5775        }
5776    
5777        /**
5778         * Checks whether the file's "3CRC" chunk was damaged. This chunk contains
5779         * the CRC32 check sums of all samples' raw wave data.
5780         *
5781         * @return true if 3CRC chunk is OK, or false if 3CRC chunk is damaged
5782         */
5783        bool File::VerifySampleChecksumTable() {
5784            RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC);
5785            if (!_3crc) return false;
5786            if (_3crc->GetNewSize() <= 0) return false;
5787            if (_3crc->GetNewSize() % 8) return false;
5788            if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned
5789            if (_3crc->GetNewSize() != pSamples->size() * 8) return false;
5790    
5791            const file_offset_t n = _3crc->GetNewSize() / 8;
5792    
5793            uint32_t* pData = (uint32_t*) _3crc->LoadChunkData();
5794            if (!pData) return false;
5795    
5796            for (file_offset_t i = 0; i < n; ++i) {
5797                uint32_t one = pData[i*2];
5798                if (one != 1) return false;
5799            }
5800    
5801            return true;
5802        }
5803    
5804        /**
5805         * Recalculates CRC32 checksums for all samples and rebuilds this gig
5806         * file's checksum table with those new checksums. This might usually
5807         * just be necessary if the checksum table was damaged.
5808         *
5809         * @e IMPORTANT: The current implementation of this method only works
5810         * with files that have not been modified since it was loaded, because
5811         * it expects that no externally caused file structure changes are
5812         * required!
5813         *
5814         * Due to the expectation above, this method is currently protected
5815         * and actually only used by the command line tool "gigdump" yet.
5816         *
5817         * @returns true if Save() is required to be called after this call,
5818         *          false if no further action is required
5819         */
5820        bool File::RebuildSampleChecksumTable() {
5821            // make sure sample chunks were scanned
5822            if (!pSamples) GetFirstSample();
5823    
5824            bool bRequiresSave = false;
5825    
5826            // make sure "3CRC" chunk exists with required size
5827            RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC);
5828            if (!_3crc) {
5829                _3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8);
5830                // the order of einf and 3crc is not the same in v2 and v3
5831                RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF);
5832                if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf);
5833                bRequiresSave = true;
5834            } else if (_3crc->GetNewSize() != pSamples->size() * 8) {
5835                _3crc->Resize(pSamples->size() * 8);
5836                bRequiresSave = true;
5837            }
5838    
5839            if (bRequiresSave) { // refill CRC table for all samples in RAM ...
5840                uint32_t* pData = (uint32_t*) _3crc->LoadChunkData();
5841                {
5842                    File::SampleList::iterator iter = pSamples->begin();
5843                    File::SampleList::iterator end  = pSamples->end();
5844                    for (; iter != end; ++iter) {
5845                        gig::Sample* pSample = (gig::Sample*) *iter;
5846                        int index = GetWaveTableIndexOf(pSample);
5847                        if (index < 0) throw gig::Exception("Could not rebuild crc table for samples, wave table index of a sample could not be resolved");
5848                        pData[index*2]   = 1; // always 1
5849                        pData[index*2+1] = pSample->CalculateWaveDataChecksum();
5850                    }
5851                }
5852            } else { // no file structure changes necessary, so directly write to disk and we are done ...
5853                // make sure file is in write mode
5854                pRIFF->SetMode(RIFF::stream_mode_read_write);
5855                {
5856                    File::SampleList::iterator iter = pSamples->begin();
5857                    File::SampleList::iterator end  = pSamples->end();
5858                    for (; iter != end; ++iter) {
5859                        gig::Sample* pSample = (gig::Sample*) *iter;
5860                        int index = GetWaveTableIndexOf(pSample);
5861                        if (index < 0) throw gig::Exception("Could not rebuild crc table for samples, wave table index of a sample could not be resolved");
5862                        pSample->crc  = pSample->CalculateWaveDataChecksum();
5863                        SetSampleChecksum(pSample, pSample->crc);
5864                    }
5865                }
5866            }
5867    
5868            return bRequiresSave;
5869        }
5870    
5871      Group* File::GetFirstGroup() {      Group* File::GetFirstGroup() {
5872          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
5873          // there must always be at least one group          // there must always be at least one group
# Line 5841  namespace { Line 6082  namespace {
6082          }          }
6083      }      }
6084    
     /** @brief Returns the version number of libgig's Giga file format extension.  
      *  
      * libgig added several new features which were not available with the  
      * original GigaStudio software. For those purposes libgig's own custom RIFF  
      * chunks were added to the Giga file format.  
      *  
      * This method returns the version number of the Giga file format extension  
      * used in this Giga file. Currently there are 3 possible values that might  
      * be returned by this method:  
      *  
      * - @c 0: This gig file is not using any libgig specific file format  
      *         extension at all.  
      * - @c 1: This gig file uses the RT instrument script format extension.  
      * - @c 2: This gig file additionally provides support for monolithic  
      *         large gig files (larger than 2 GB).  
      *  
      * @note This method is currently protected and shall not be used as public  
      * API method, since its method signature might change in future.  
      */  
     uint File::GetFormatExtensionVersion() const {  
         RIFF::List* lst3LS = pRIFF->GetSubList(LIST_TYPE_3LS);  
         if (!lst3LS) return 0; // is not using custom Giga format extensions at all  
         RIFF::Chunk* ckFFmt = lst3LS->GetSubChunk(CHUNK_ID_FFMT);  
         if (!ckFFmt) return 1; // uses custom Giga format extension(s) but had no format version saved  
         uint8_t* pData = (uint8_t*) ckFFmt->LoadChunkData();  
         return load32(pData);  
     }  
   
     /** @brief Returns true in case this file is stored as one, single monolithic gig file.  
      *  
      * To avoid issues with operating systems which did not support large files  
      * (larger than 2 GB) the original Giga file format avoided to ever save gig  
      * files larger than 2 GB, instead such large Giga files were splitted into  
      * several files, each one not being larger than 2 GB. It used a predefined  
      * file name scheme for them like this:  
      * @code  
      * foo.gig  
      * foo.gx01  
      * foo.gx02  
      * foo.gx03  
      * ...  
      * @endcode  
      * So when like in this example foo.gig was loaded, all other files  
      * (foo.gx01, ...) were automatically loaded as well to make up the overall  
      * large gig file (provided they were located at the same directory). Such  
      * additional .gxYY files were called "extension files".  
      *  
      * Since nowadays all modern systems support large files, libgig always  
      * saves large gig files as one single monolithic gig file instead, that  
      * is libgig won't split such a large gig file into separate files like the  
      * original GigaStudio software did. It uses a custom Giga file format  
      * extension for this feature.  
      *  
      * For still being able though to load old splitted gig files and the new  
      * large monolithic ones, this method is used to determine which loading  
      * policy must be used for this gig file.  
      *  
      * @note This method is currently protected and shall not be used as public  
      * API method, since its method signature might change in future and since  
      * this method should not be directly relevant for applications based on  
      * libgig.  
      */  
     bool File::HasMonolithicLargeFilePolicy() const {  
         RIFF::List* lst3LS = pRIFF->GetSubList(LIST_TYPE_3LS);  
         if (!lst3LS) return false;  
         RIFF::Chunk* ckFFmt = lst3LS->GetSubChunk(CHUNK_ID_FFMT);  
         if (!ckFFmt) return false;  
         uint8_t* pData = (uint8_t*) ckFFmt->LoadChunkData();  
         uint32_t formatBitField = load32(&pData[4]);  
         return formatBitField & 1;  
     }  
   
6085      /**      /**
6086       * Apply all the gig file's current instruments, samples, groups and settings       * Apply all the gig file's current instruments, samples, groups and settings
6087       * to the respective RIFF chunks. You have to call Save() to make changes       * to the respective RIFF chunks. You have to call Save() to make changes
# Line 5927  namespace { Line 6096  namespace {
6096      void File::UpdateChunks(progress_t* pProgress) {      void File::UpdateChunks(progress_t* pProgress) {
6097          bool newFile = pRIFF->GetSubList(LIST_TYPE_INFO) == NULL;          bool newFile = pRIFF->GetSubList(LIST_TYPE_INFO) == NULL;
6098    
         b64BitWavePoolOffsets = pVersion && pVersion->major == 3;  
   
6099          // update own gig format extension chunks          // update own gig format extension chunks
6100          // (not part of the GigaStudio 4 format)          // (not part of the GigaStudio 4 format)
6101          RIFF::List* lst3LS = pRIFF->GetSubList(LIST_TYPE_3LS);          RIFF::List* lst3LS = pRIFF->GetSubList(LIST_TYPE_3LS);
# Line 5936  namespace { Line 6103  namespace {
6103              lst3LS = pRIFF->AddSubList(LIST_TYPE_3LS);              lst3LS = pRIFF->AddSubList(LIST_TYPE_3LS);
6104          }          }
6105          // Make sure <3LS > chunk is placed before <ptbl> chunk. The precise          // Make sure <3LS > chunk is placed before <ptbl> chunk. The precise
6106          // location of <3LS > is irrelevant, however it MUST BE located BEFORE          // location of <3LS > is irrelevant, however it should be located
6107          // the actual wave data, otherwise the <3LS > chunk becomes          // before  the actual wave data
         // inaccessible on gig files larger than 4GB !  
6108          RIFF::Chunk* ckPTBL = pRIFF->GetSubChunk(CHUNK_ID_PTBL);          RIFF::Chunk* ckPTBL = pRIFF->GetSubChunk(CHUNK_ID_PTBL);
6109          pRIFF->MoveSubChunk(lst3LS, ckPTBL);          pRIFF->MoveSubChunk(lst3LS, ckPTBL);
6110    
         // Update <FFmt> chunk with informations about our file format  
         // extensions. Currently this <FFmt> chunk has the following  
         // layout:  
         //  
         // <uint32> -> (libgig's) File Format Extension version  
         // <uint32> -> Format bit field:  
         //             bit 0: If flag is not set use separate .gx01  
         //                    extension files if file is larger than 2 GB  
         //                    like with the original Giga format, if flag  
         //                    is set use 64 bit sample references and keep  
         //                    everything as one single monolithic gig file.  
         RIFF::Chunk* ckFFmt = lst3LS->GetSubChunk(CHUNK_ID_FFMT);  
         if (!ckFFmt) {  
             const int iChunkSize = 2 * sizeof(uint32_t);  
             ckFFmt = lst3LS->AddSubChunk(CHUNK_ID_FFMT, iChunkSize);  
         }  
         {  
             uint8_t* pData = (uint8_t*) ckFFmt->LoadChunkData();  
             store32(&pData[0], GIG_FILE_EXT_VERSION);  
             // for now we always save gig files larger than 2 GB as one  
             // single monolithic file (saving those with extension files is  
             // currently not supported and probably also not desired anymore  
             // nowadays).  
             uint32_t formatBitfield = 1;  
             store32(&pData[4], formatBitfield);  
         }  
6111          // This must be performed before writing the chunks for instruments,          // This must be performed before writing the chunks for instruments,
6112          // because the instruments' script slots will write the file offsets          // because the instruments' script slots will write the file offsets
6113          // of the respective instrument script chunk as reference.          // of the respective instrument script chunk as reference.
# Line 5980  namespace { Line 6120  namespace {
6120              }              }
6121          }          }
6122    
6123            // in case no libgig custom format data was added, then remove the
6124            // custom "3LS " chunk again
6125            if (!lst3LS->CountSubChunks()) {
6126                pRIFF->DeleteSubChunk(lst3LS);
6127                lst3LS = NULL;
6128            }
6129    
6130          // first update base class's chunks          // first update base class's chunks
6131          DLS::File::UpdateChunks(pProgress);          DLS::File::UpdateChunks(pProgress);
6132    
# Line 6038  namespace { Line 6185  namespace {
6185          // Note that there are several fields with unknown use. These          // Note that there are several fields with unknown use. These
6186          // are set to zero.          // are set to zero.
6187    
6188          int sublen = pSamples->size() / 8 + 49;          int sublen = int(pSamples->size() / 8 + 49);
6189          int einfSize = (Instruments + 1) * sublen;          int einfSize = (Instruments + 1) * sublen;
6190    
6191          RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF);          RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF);
# Line 6111  namespace { Line 6258  namespace {
6258                  store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops);                  store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops);
6259                  // next 8 bytes unknown                  // next 8 bytes unknown
6260                  store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx);                  store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx);
6261                  store32(&pData[(instrumentIdx + 1) * sublen + 40], pSamples->size());                  store32(&pData[(instrumentIdx + 1) * sublen + 40], (uint32_t) pSamples->size());
6262                  // next 4 bytes unknown                  // next 4 bytes unknown
6263    
6264                  totnbregions += instrument->Regions;                  totnbregions += instrument->Regions;
# Line 6129  namespace { Line 6276  namespace {
6276              store32(&pData[24], totnbloops);              store32(&pData[24], totnbloops);
6277              // next 8 bytes unknown              // next 8 bytes unknown
6278              // next 4 bytes unknown, not always 0              // next 4 bytes unknown, not always 0
6279              store32(&pData[40], pSamples->size());              store32(&pData[40], (uint32_t) pSamples->size());
6280              // next 4 bytes unknown              // next 4 bytes unknown
6281          }          }
6282    
6283          // update 3crc chunk          // update 3crc chunk
6284    
6285          // The 3crc chunk contains CRC-32 checksums for the          // The 3crc chunk contains CRC-32 checksums for the
6286          // samples. The actual checksum values will be filled in          // samples. When saving a gig file to disk, we first update the 3CRC
6287          // later, by Sample::Write.          // chunk here (in RAM) with the old crc values which we read from the
6288            // 3CRC chunk when we opened the file (available with gig::Sample::crc
6289            // member variable). This step is required, because samples might have
6290            // been deleted by the user since the file was opened, which in turn
6291            // changes the order of the (i.e. old) checksums within the 3crc chunk.
6292            // If a sample was conciously modified by the user (that is if
6293            // Sample::Write() was called later on) then Sample::Write() will just
6294            // update the respective individual checksum(s) directly on disk and
6295            // leaves all other sample checksums untouched.
6296    
6297          RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC);          RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC);
6298          if (_3crc) {          if (_3crc) {
6299              _3crc->Resize(pSamples->size() * 8);              _3crc->Resize(pSamples->size() * 8);
6300          } else if (newFile) {          } else /*if (newFile)*/ {
6301              _3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8);              _3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8);
             _3crc->LoadChunkData();  
   
6302              // the order of einf and 3crc is not the same in v2 and v3              // the order of einf and 3crc is not the same in v2 and v3
6303              if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf);              if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf);
6304          }          }
6305            { // must be performed in RAM here ...
6306                uint32_t* pData = (uint32_t*) _3crc->LoadChunkData();
6307                if (pData) {
6308                    File::SampleList::iterator iter = pSamples->begin();
6309                    File::SampleList::iterator end  = pSamples->end();
6310                    for (int index = 0; iter != end; ++iter, ++index) {
6311                        gig::Sample* pSample = (gig::Sample*) *iter;
6312                        pData[index*2]   = 1; // always 1
6313                        pData[index*2+1] = pSample->crc;
6314                    }
6315                }
6316            }
6317      }      }
6318            
6319      void File::UpdateFileOffsets() {      void File::UpdateFileOffsets() {

Legend:
Removed from v.2912  
changed lines
  Added in v.3117

  ViewVC Help
Powered by ViewVC