1152 |
* |
* |
1153 |
* Note: there is currently no support for writing compressed samples. |
* Note: there is currently no support for writing compressed samples. |
1154 |
* |
* |
1155 |
|
* For 16 bit samples, the data in the source buffer should be |
1156 |
|
* int16_t (using native endianness). For 24 bit, the buffer |
1157 |
|
* should contain three bytes per sample, little-endian. |
1158 |
|
* |
1159 |
* @param pBuffer - source buffer |
* @param pBuffer - source buffer |
1160 |
* @param SampleCount - number of sample points to write |
* @param SampleCount - number of sample points to write |
1161 |
* @throws DLS::Exception if current sample size is too small |
* @throws DLS::Exception if current sample size is too small |
1170 |
if (pCkData->GetPos() == 0) { |
if (pCkData->GetPos() == 0) { |
1171 |
crc.reset(); |
crc.reset(); |
1172 |
} |
} |
1173 |
unsigned long res = DLS::Sample::Write(pBuffer, SampleCount); |
if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small"); |
1174 |
|
unsigned long res; |
1175 |
|
if (BitDepth == 24) { |
1176 |
|
res = pCkData->Write(pBuffer, SampleCount * FrameSize, 1) / FrameSize; |
1177 |
|
} else { // 16 bit |
1178 |
|
res = Channels == 2 ? pCkData->Write(pBuffer, SampleCount << 1, 2) >> 1 |
1179 |
|
: pCkData->Write(pBuffer, SampleCount, 2); |
1180 |
|
} |
1181 |
crc.update((unsigned char *)pBuffer, SampleCount * FrameSize); |
crc.update((unsigned char *)pBuffer, SampleCount * FrameSize); |
1182 |
|
|
1183 |
// if this is the last write, update the checksum chunk in the |
// if this is the last write, update the checksum chunk in the |
1550 |
* It will be called automatically when File::Save() was called. |
* It will be called automatically when File::Save() was called. |
1551 |
*/ |
*/ |
1552 |
void DimensionRegion::UpdateChunks() { |
void DimensionRegion::UpdateChunks() { |
1553 |
|
// check if wsmp is going to be created by |
1554 |
|
// DLS::Sampler::UpdateChunks |
1555 |
|
bool wsmp_created = !pParentList->GetSubChunk(CHUNK_ID_WSMP); |
1556 |
|
|
1557 |
// first update base class's chunk |
// first update base class's chunk |
1558 |
DLS::Sampler::UpdateChunks(); |
DLS::Sampler::UpdateChunks(); |
1559 |
|
|
1567 |
// make sure '3ewa' chunk exists |
// make sure '3ewa' chunk exists |
1568 |
RIFF::Chunk* _3ewa = pParentList->GetSubChunk(CHUNK_ID_3EWA); |
RIFF::Chunk* _3ewa = pParentList->GetSubChunk(CHUNK_ID_3EWA); |
1569 |
if (!_3ewa) _3ewa = pParentList->AddSubChunk(CHUNK_ID_3EWA, 140); |
if (!_3ewa) _3ewa = pParentList->AddSubChunk(CHUNK_ID_3EWA, 140); |
1570 |
|
else if (wsmp_created) { |
1571 |
|
// make sure the chunk order is: wsmp, 3ewa |
1572 |
|
pParentList->MoveSubChunk(_3ewa, 0); |
1573 |
|
} |
1574 |
pData = (uint8_t*) _3ewa->LoadChunkData(); |
pData = (uint8_t*) _3ewa->LoadChunkData(); |
1575 |
|
|
1576 |
// update '3ewa' chunk with DimensionRegion's current settings |
// update '3ewa' chunk with DimensionRegion's current settings |
2486 |
|
|
2487 |
// initialize the upper limits for this dimension |
// initialize the upper limits for this dimension |
2488 |
for (int z = 0, j = 0 ; z < pDimDef->zones ; z++, j += 1 << iCurrentBits) { |
for (int z = 0, j = 0 ; z < pDimDef->zones ; z++, j += 1 << iCurrentBits) { |
2489 |
uint8_t upperLimit = (z + 1) * 128.0 / pDimDef->zones - 1; |
uint8_t upperLimit = uint8_t((z + 1) * 128.0 / pDimDef->zones - 1); |
2490 |
for (int i = 0 ; i < 1 << iCurrentBits ; i++) { |
for (int i = 0 ; i < 1 << iCurrentBits ; i++) { |
2491 |
pDimensionRegions[j + i]->DimensionUpperLimits[Dimensions] = upperLimit; |
pDimensionRegions[j + i]->DimensionUpperLimits[Dimensions] = upperLimit; |
2492 |
} |
} |
2804 |
if (!lart) lart = pCkInstrument->AddSubList(LIST_TYPE_LART); |
if (!lart) lart = pCkInstrument->AddSubList(LIST_TYPE_LART); |
2805 |
// make sure '3ewg' RIFF chunk exists |
// make sure '3ewg' RIFF chunk exists |
2806 |
RIFF::Chunk* _3ewg = lart->GetSubChunk(CHUNK_ID_3EWG); |
RIFF::Chunk* _3ewg = lart->GetSubChunk(CHUNK_ID_3EWG); |
2807 |
if (!_3ewg) _3ewg = lart->AddSubChunk(CHUNK_ID_3EWG, 12); |
if (!_3ewg) { |
2808 |
|
File* pFile = (File*) GetParent(); |
2809 |
|
|
2810 |
|
// 3ewg is bigger in gig3, as it includes the iMIDI rules |
2811 |
|
int size = (pFile->pVersion && pFile->pVersion->major == 3) ? 16416 : 12; |
2812 |
|
_3ewg = lart->AddSubChunk(CHUNK_ID_3EWG, size); |
2813 |
|
memset(_3ewg->LoadChunkData(), 0, size); |
2814 |
|
} |
2815 |
// update '3ewg' RIFF chunk |
// update '3ewg' RIFF chunk |
2816 |
uint8_t* pData = (uint8_t*) _3ewg->LoadChunkData(); |
uint8_t* pData = (uint8_t*) _3ewg->LoadChunkData(); |
2817 |
store16(&pData[0], EffectSend); |
store16(&pData[0], EffectSend); |
3036 |
}; |
}; |
3037 |
|
|
3038 |
File::File() : DLS::File() { |
File::File() : DLS::File() { |
3039 |
|
*pVersion = VERSION_3; |
3040 |
pGroups = NULL; |
pGroups = NULL; |
3041 |
pInfo->FixedStringLengths = FixedStringLengths; |
pInfo->FixedStringLengths = FixedStringLengths; |
3042 |
pInfo->ArchivalLocation = String(256, ' '); |
pInfo->ArchivalLocation = String(256, ' '); |
3514 |
int totnbusedchannels = 0; |
int totnbusedchannels = 0; |
3515 |
int totnbregions = 0; |
int totnbregions = 0; |
3516 |
int totnbdimregions = 0; |
int totnbdimregions = 0; |
3517 |
|
int totnbloops = 0; |
3518 |
int instrumentIdx = 0; |
int instrumentIdx = 0; |
3519 |
|
|
3520 |
memset(&pData[48], 0, sublen - 48); |
memset(&pData[48], 0, sublen - 48); |
3524 |
int nbusedsamples = 0; |
int nbusedsamples = 0; |
3525 |
int nbusedchannels = 0; |
int nbusedchannels = 0; |
3526 |
int nbdimregions = 0; |
int nbdimregions = 0; |
3527 |
|
int nbloops = 0; |
3528 |
|
|
3529 |
memset(&pData[(instrumentIdx + 1) * sublen + 48], 0, sublen - 48); |
memset(&pData[(instrumentIdx + 1) * sublen + 48], 0, sublen - 48); |
3530 |
|
|
3548 |
} |
} |
3549 |
} |
} |
3550 |
} |
} |
3551 |
|
if (d->SampleLoops) nbloops++; |
3552 |
} |
} |
3553 |
nbdimregions += region->DimensionRegions; |
nbdimregions += region->DimensionRegions; |
3554 |
} |
} |
3559 |
store32(&pData[(instrumentIdx + 1) * sublen + 12], 1); |
store32(&pData[(instrumentIdx + 1) * sublen + 12], 1); |
3560 |
store32(&pData[(instrumentIdx + 1) * sublen + 16], instrument->Regions); |
store32(&pData[(instrumentIdx + 1) * sublen + 16], instrument->Regions); |
3561 |
store32(&pData[(instrumentIdx + 1) * sublen + 20], nbdimregions); |
store32(&pData[(instrumentIdx + 1) * sublen + 20], nbdimregions); |
3562 |
// next 12 bytes unknown |
store32(&pData[(instrumentIdx + 1) * sublen + 24], nbloops); |
3563 |
|
// next 8 bytes unknown |
3564 |
store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx); |
store32(&pData[(instrumentIdx + 1) * sublen + 36], instrumentIdx); |
3565 |
store32(&pData[(instrumentIdx + 1) * sublen + 40], pSamples->size()); |
store32(&pData[(instrumentIdx + 1) * sublen + 40], pSamples->size()); |
3566 |
// next 4 bytes unknown |
// next 4 bytes unknown |
3567 |
|
|
3568 |
totnbregions += instrument->Regions; |
totnbregions += instrument->Regions; |
3569 |
totnbdimregions += nbdimregions; |
totnbdimregions += nbdimregions; |
3570 |
|
totnbloops += nbloops; |
3571 |
instrumentIdx++; |
instrumentIdx++; |
3572 |
} |
} |
3573 |
// first 4 bytes unknown - sometimes 0, sometimes length of einf part |
// first 4 bytes unknown - sometimes 0, sometimes length of einf part |
3577 |
store32(&pData[12], Instruments); |
store32(&pData[12], Instruments); |
3578 |
store32(&pData[16], totnbregions); |
store32(&pData[16], totnbregions); |
3579 |
store32(&pData[20], totnbdimregions); |
store32(&pData[20], totnbdimregions); |
3580 |
// next 12 bytes unknown |
store32(&pData[24], totnbloops); |
3581 |
// next 4 bytes unknown, always 0? |
// next 8 bytes unknown |
3582 |
|
// next 4 bytes unknown, not always 0 |
3583 |
store32(&pData[40], pSamples->size()); |
store32(&pData[40], pSamples->size()); |
3584 |
// next 4 bytes unknown |
// next 4 bytes unknown |
3585 |
} |
} |
3596 |
} else if (newFile) { |
} else if (newFile) { |
3597 |
_3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8); |
_3crc = pRIFF->AddSubChunk(CHUNK_ID_3CRC, pSamples->size() * 8); |
3598 |
_3crc->LoadChunkData(); |
_3crc->LoadChunkData(); |
3599 |
|
|
3600 |
|
// the order of einf and 3crc is not the same in v2 and v3 |
3601 |
|
if (einf && pVersion && pVersion->major == 3) pRIFF->MoveSubChunk(_3crc, einf); |
3602 |
} |
} |
3603 |
} |
} |
3604 |
|
|