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()); |
3227 |
} |
} |
3228 |
} |
} |
3229 |
|
|
3230 |
|
/// Updates the 3crc chunk with the checksum of a sample. The |
3231 |
|
/// update is done directly to disk, as this method is called |
3232 |
|
/// after File::Save() |
3233 |
void File::SetSampleChecksum(Sample* pSample, uint32_t crc) { |
void File::SetSampleChecksum(Sample* pSample, uint32_t crc) { |
3234 |
RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC); |
RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC); |
3235 |
if (!_3crc) return; |
if (!_3crc) return; |
3236 |
|
|
3237 |
|
// get the index of the sample |
3238 |
int iWaveIndex = -1; |
int iWaveIndex = -1; |
3239 |
File::SampleList::iterator iter = pSamples->begin(); |
File::SampleList::iterator iter = pSamples->begin(); |
3240 |
File::SampleList::iterator end = pSamples->end(); |
File::SampleList::iterator end = pSamples->end(); |
3246 |
} |
} |
3247 |
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"); |
3248 |
|
|
3249 |
|
// write the CRC-32 checksum to disk |
3250 |
_3crc->SetPos(iWaveIndex * 8); |
_3crc->SetPos(iWaveIndex * 8); |
3251 |
uint32_t tmp = 1; |
uint32_t tmp = 1; |
3252 |
_3crc->WriteUint32(&tmp); // unknown, always 1? |
_3crc->WriteUint32(&tmp); // unknown, always 1? |