/[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 1199 by persson, Sun May 20 10:11:39 2007 UTC revision 1209 by persson, Sun May 27 13:54:24 2007 UTC
# Line 1160  namespace { Line 1160  namespace {
1160       */       */
1161      unsigned long Sample::Write(void* pBuffer, unsigned long SampleCount) {      unsigned long Sample::Write(void* pBuffer, unsigned long SampleCount) {
1162          if (Compressed) throw gig::Exception("There is no support for writing compressed gig samples (yet)");          if (Compressed) throw gig::Exception("There is no support for writing compressed gig samples (yet)");
1163    
1164            // if this is the first write in this sample, reset the
1165            // checksum calculator
1166          if (pCkData->GetPos() == 0) {          if (pCkData->GetPos() == 0) {
1167              crc.reset();              crc.reset();
1168          }          }
1169          unsigned long res = DLS::Sample::Write(pBuffer, SampleCount);          unsigned long res = DLS::Sample::Write(pBuffer, SampleCount);
1170          crc.update((unsigned char *)pBuffer, SampleCount * FrameSize);          crc.update((unsigned char *)pBuffer, SampleCount * FrameSize);
1171    
1172            // if this is the last write, update the checksum chunk in the
1173            // file
1174          if (pCkData->GetPos() == pCkData->GetSize()) {          if (pCkData->GetPos() == pCkData->GetSize()) {
1175              File* pFile = static_cast<File*>(GetParent());              File* pFile = static_cast<File*>(GetParent());
1176              pFile->SetSampleChecksum(this, crc.getValue());              pFile->SetSampleChecksum(this, crc.getValue());
# Line 2968  namespace { Line 2973  namespace {
2973          // order (INFO chunk will be moved to first position later)          // order (INFO chunk will be moved to first position later)
2974          pRIFF->AddSubChunk(CHUNK_ID_VERS, 8);          pRIFF->AddSubChunk(CHUNK_ID_VERS, 8);
2975          pRIFF->AddSubChunk(CHUNK_ID_COLH, 4);          pRIFF->AddSubChunk(CHUNK_ID_COLH, 4);
2976            pRIFF->AddSubChunk(CHUNK_ID_DLID, 16);
2977    
2978            GenerateDLSID();
2979      }      }
2980    
2981      File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) {      File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) {
# Line 3164  namespace { Line 3172  namespace {
3172    
3173         // add mandatory chunks to get the chunks in right order         // add mandatory chunks to get the chunks in right order
3174         lstInstr->AddSubList(LIST_TYPE_INFO);         lstInstr->AddSubList(LIST_TYPE_INFO);
3175           lstInstr->AddSubChunk(CHUNK_ID_DLID, 16);
3176    
3177         Instrument* pInstrument = new Instrument(this, lstInstr);         Instrument* pInstrument = new Instrument(this, lstInstr);
3178           pInstrument->GenerateDLSID();
3179    
3180         lstInstr->AddSubChunk(CHUNK_ID_INSH, 12);         lstInstr->AddSubChunk(CHUNK_ID_INSH, 12);
3181    
# Line 3222  namespace { Line 3232  namespace {
3232          }          }
3233      }      }
3234    
3235        /// Updates the 3crc chunk with the checksum of a sample. The
3236        /// update is done directly to disk, as this method is called
3237        /// after File::Save()
3238      void File::SetSampleChecksum(Sample* pSample, uint32_t crc) {      void File::SetSampleChecksum(Sample* pSample, uint32_t crc) {
3239          RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC);          RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC);
3240          if (!_3crc) return;          if (!_3crc) return;
3241    
3242            // get the index of the sample
3243          int iWaveIndex = -1;          int iWaveIndex = -1;
3244          File::SampleList::iterator iter = pSamples->begin();          File::SampleList::iterator iter = pSamples->begin();
3245          File::SampleList::iterator end  = pSamples->end();          File::SampleList::iterator end  = pSamples->end();
# Line 3236  namespace { Line 3251  namespace {
3251          }          }
3252          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");
3253    
3254            // write the CRC-32 checksum to disk
3255          _3crc->SetPos(iWaveIndex * 8);          _3crc->SetPos(iWaveIndex * 8);
3256          uint32_t tmp = 1;          uint32_t tmp = 1;
3257          _3crc->WriteUint32(&tmp); // unknown, always 1?          _3crc->WriteUint32(&tmp); // unknown, always 1?

Legend:
Removed from v.1199  
changed lines
  Added in v.1209

  ViewVC Help
Powered by ViewVC