/[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 2989 by schoenebeck, Sat Sep 24 14:00:46 2016 UTC revision 3115 by schoenebeck, Sat Apr 15 20:17:05 2017 UTC
# 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 1294  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 1396  namespace { Line 1397  namespace {
1397       * @see GetWaveDataCRC32Checksum()       * @see GetWaveDataCRC32Checksum()
1398       */       */
1399      bool Sample::VerifyWaveData(uint32_t* pActually) {      bool Sample::VerifyWaveData(uint32_t* pActually) {
1400          File* pFile = static_cast<File*>(GetParent());          //File* pFile = static_cast<File*>(GetParent());
1401          uint32_t crc = CalculateWaveDataChecksum();          uint32_t crc = CalculateWaveDataChecksum();
1402          if (pActually) *pActually = crc;          if (pActually) *pActually = crc;
1403          return crc == this->crc;          return crc == this->crc;
# Line 1416  namespace { Line 1417  namespace {
1417              if (nRead <= 0) break;              if (nRead <= 0) break;
1418              __calculateCRC(&buffer[0], nRead * FrameSize, crc);              __calculateCRC(&buffer[0], nRead * FrameSize, crc);
1419          }          }
1420          __encodeCRC(crc);          __finalizeCRC(crc);
1421          return crc;          return crc;
1422      }      }
1423    
# Line 1630  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 1829  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 3797  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 3846  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 4195  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 4246  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 4266  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 4443  namespace { Line 4444  namespace {
4444          EffectSend = 0;          EffectSend = 0;
4445          Attenuation = 0;          Attenuation = 0;
4446          FineTune = 0;          FineTune = 0;
4447          PitchbendRange = 0;          PitchbendRange = 2;
4448          PianoReleaseMode = false;          PianoReleaseMode = false;
4449          DimensionKeyRange.low = 0;          DimensionKeyRange.low = 0;
4450          DimensionKeyRange.high = 0;          DimensionKeyRange.high = 0;
# Line 4618  namespace { Line 4619  namespace {
4619    
4620             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);
4621             if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS);             if (!lst3LS) lst3LS = pCkInstrument->AddSubList(LIST_TYPE_3LS);
4622             const int slotCount = pScriptRefs->size();             const int slotCount = (int) pScriptRefs->size();
4623             const int headerSize = 3 * sizeof(uint32_t);             const int headerSize = 3 * sizeof(uint32_t);
4624             const int slotSize  = 2 * sizeof(uint32_t);             const int slotSize  = 2 * sizeof(uint32_t);
4625             const int totalChunkSize = headerSize + slotCount * slotSize;             const int totalChunkSize = headerSize + slotCount * slotSize;
# Line 4654  namespace { Line 4655  namespace {
4655         if (pScriptRefs && pScriptRefs->size() > 0) {         if (pScriptRefs && pScriptRefs->size() > 0) {
4656             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);             RIFF::List* lst3LS = pCkInstrument->GetSubList(LIST_TYPE_3LS);
4657             RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);             RIFF::Chunk* ckSCSL = lst3LS->GetSubChunk(CHUNK_ID_SCSL);
4658             const int slotCount = pScriptRefs->size();             const int slotCount = (int) pScriptRefs->size();
4659             const int headerSize = 3 * sizeof(uint32_t);             const int headerSize = 3 * sizeof(uint32_t);
4660             ckSCSL->SetPos(headerSize);             ckSCSL->SetPos(headerSize);
4661             for (int i = 0; i < slotCount; ++i) {             for (int i = 0; i < slotCount; ++i) {
4662                 uint32_t fileOffset =                 uint32_t fileOffset = uint32_t(
4663                      (*pScriptRefs)[i].script->pChunk->GetFilePos() -                      (*pScriptRefs)[i].script->pChunk->GetFilePos() -
4664                      (*pScriptRefs)[i].script->pChunk->GetPos() -                      (*pScriptRefs)[i].script->pChunk->GetPos() -
4665                      CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize());                      CHUNK_HEADER_SIZE(ckSCSL->GetFile()->GetFileOffsetSize())
4666                   );
4667                 ckSCSL->WriteUint32(&fileOffset);                 ckSCSL->WriteUint32(&fileOffset);
4668                 // jump over flags entry (containing the bypass flag)                 // jump over flags entry (containing the bypass flag)
4669                 ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos);                 ckSCSL->SetPos(sizeof(uint32_t), RIFF::stream_curpos);
# Line 4721  namespace { Line 4723  namespace {
4723          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);          RIFF::List* rgn = lrgn->AddSubList(LIST_TYPE_RGN);
4724          Region* pNewRegion = new Region(this, rgn);          Region* pNewRegion = new Region(this, rgn);
4725          pRegions->push_back(pNewRegion);          pRegions->push_back(pNewRegion);
4726          Regions = pRegions->size();          Regions = (uint32_t) pRegions->size();
4727          // update Region key table for fast lookup          // update Region key table for fast lookup
4728          UpdateRegionKeyTable();          UpdateRegionKeyTable();
4729          // done          // done
# Line 4867  namespace { Line 4869  namespace {
4869                  for (uint s = 0; group->GetScript(s); ++s) {                  for (uint s = 0; group->GetScript(s); ++s) {
4870                      Script* script = group->GetScript(s);                      Script* script = group->GetScript(s);
4871                      if (script->pChunk) {                      if (script->pChunk) {
4872                          uint32_t offset = script->pChunk->GetFilePos() -                          uint32_t offset = uint32_t(
4873                                            script->pChunk->GetPos() -                              script->pChunk->GetFilePos() -
4874                                            CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize());                              script->pChunk->GetPos() -
4875                                CHUNK_HEADER_SIZE(script->pChunk->GetFile()->GetFileOffsetSize())
4876                            );
4877                          if (offset == soughtOffset)                          if (offset == soughtOffset)
4878                          {                          {
4879                              _ScriptPooolRef ref;                              _ScriptPooolRef ref;
# Line 4994  namespace { Line 4998  namespace {
4998       */       */
4999      void Instrument::RemoveScript(Script* pScript) {      void Instrument::RemoveScript(Script* pScript) {
5000          LoadScripts();          LoadScripts();
5001          for (int i = pScriptRefs->size() - 1; i >= 0; --i) {          for (ssize_t i = pScriptRefs->size() - 1; i >= 0; --i) {
5002              if ((*pScriptRefs)[i].script == pScript) {              if ((*pScriptRefs)[i].script == pScript) {
5003                  pScriptRefs->erase( pScriptRefs->begin() + i );                  pScriptRefs->erase( pScriptRefs->begin() + i );
5004              }              }
# Line 5016  namespace { Line 5020  namespace {
5020       * gigedit.       * gigedit.
5021       */       */
5022      uint Instrument::ScriptSlotCount() const {      uint Instrument::ScriptSlotCount() const {
5023          return pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size();          return uint(pScriptRefs ? pScriptRefs->size() : scriptPoolFileOffsets.size());
5024      }      }
5025    
5026      /** @brief Whether script execution shall be skipped.      /** @brief Whether script execution shall be skipped.
# Line 5440  namespace { Line 5444  namespace {
5444              }              }
5445          }          }
5446          String name(pRIFF->GetFileName());          String name(pRIFF->GetFileName());
5447          int nameLen = name.length();          int nameLen = (int) name.length();
5448          char suffix[6];          char suffix[6];
5449          if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4;          if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4;
5450    
# Line 5756  namespace { Line 5760  namespace {
5760          if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned          if (!pSamples) GetFirstSample(); // make sure sample chunks were scanned
5761          if (_3crc->GetNewSize() != pSamples->size() * 8) return false;          if (_3crc->GetNewSize() != pSamples->size() * 8) return false;
5762    
5763          const int n = _3crc->GetNewSize() / 8;          const file_offset_t n = _3crc->GetNewSize() / 8;
5764    
5765          uint32_t* pData = (uint32_t*) _3crc->LoadChunkData();          uint32_t* pData = (uint32_t*) _3crc->LoadChunkData();
5766          if (!pData) return false;          if (!pData) return false;
5767    
5768          for (int i = 0; i < n; ++i) {          for (file_offset_t i = 0; i < n; ++i) {
5769              uint32_t one = pData[i*2];              uint32_t one = pData[i*2];
5770              if (one != 1) return false;              if (one != 1) return false;
5771          }          }
# Line 6153  namespace { Line 6157  namespace {
6157          // Note that there are several fields with unknown use. These          // Note that there are several fields with unknown use. These
6158          // are set to zero.          // are set to zero.
6159    
6160          int sublen = pSamples->size() / 8 + 49;          int sublen = int(pSamples->size() / 8 + 49);
6161          int einfSize = (Instruments + 1) * sublen;          int einfSize = (Instruments + 1) * sublen;
6162    
6163          RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF);          RIFF::Chunk* einf = pRIFF->GetSubChunk(CHUNK_ID_EINF);
# Line 6226  namespace { Line 6230  namespace {
6230                  store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops);                  store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops);
6231                  // next 8 bytes unknown                  // next 8 bytes unknown
6232                  store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx);                  store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx);
6233                  store32(&pData[(instrumentIdx + 1) * sublen + 40], pSamples->size());                  store32(&pData[(instrumentIdx + 1) * sublen + 40], (uint32_t) pSamples->size());
6234                  // next 4 bytes unknown                  // next 4 bytes unknown
6235    
6236                  totnbregions += instrument->Regions;                  totnbregions += instrument->Regions;
# Line 6244  namespace { Line 6248  namespace {
6248              store32(&pData[24], totnbloops);              store32(&pData[24], totnbloops);
6249              // next 8 bytes unknown              // next 8 bytes unknown
6250              // next 4 bytes unknown, not always 0              // next 4 bytes unknown, not always 0
6251              store32(&pData[40], pSamples->size());              store32(&pData[40], (uint32_t) pSamples->size());
6252              // next 4 bytes unknown              // next 4 bytes unknown
6253          }          }
6254    

Legend:
Removed from v.2989  
changed lines
  Added in v.3115

  ViewVC Help
Powered by ViewVC