362 |
Manufacturer = 0; |
Manufacturer = 0; |
363 |
Product = 0; |
Product = 0; |
364 |
SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); |
SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); |
365 |
MIDIUnityNote = 64; |
MIDIUnityNote = 60; |
366 |
FineTune = 0; |
FineTune = 0; |
367 |
SMPTEFormat = smpte_format_no_offset; |
SMPTEFormat = smpte_format_no_offset; |
368 |
SMPTEOffset = 0; |
SMPTEOffset = 0; |
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()); |
1256 |
|
|
1257 |
pSample = NULL; |
pSample = NULL; |
1258 |
|
|
1259 |
memcpy(&Crossfade, &SamplerOptions, 4); |
if (_3ewl->GetSubChunk(CHUNK_ID_WSMP)) memcpy(&Crossfade, &SamplerOptions, 4); |
1260 |
|
else memset(&Crossfade, 0, 4); |
1261 |
|
|
1262 |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
if (!pVelocityTables) pVelocityTables = new VelocityTableMap; |
1263 |
|
|
1264 |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA); |
1422 |
LFO1ControlDepth = 0; |
LFO1ControlDepth = 0; |
1423 |
LFO3ControlDepth = 0; |
LFO3ControlDepth = 0; |
1424 |
EG1Attack = 0.0; |
EG1Attack = 0.0; |
1425 |
EG1Decay1 = 0.0; |
EG1Decay1 = 0.005; |
1426 |
EG1Sustain = 0; |
EG1Sustain = 1000; |
1427 |
EG1Release = 0.0; |
EG1Release = 0.3; |
1428 |
EG1Controller.type = eg1_ctrl_t::type_none; |
EG1Controller.type = eg1_ctrl_t::type_none; |
1429 |
EG1Controller.controller_number = 0; |
EG1Controller.controller_number = 0; |
1430 |
EG1ControllerInvert = false; |
EG1ControllerInvert = false; |
1439 |
EG2ControllerReleaseInfluence = 0; |
EG2ControllerReleaseInfluence = 0; |
1440 |
LFO1Frequency = 1.0; |
LFO1Frequency = 1.0; |
1441 |
EG2Attack = 0.0; |
EG2Attack = 0.0; |
1442 |
EG2Decay1 = 0.0; |
EG2Decay1 = 0.005; |
1443 |
EG2Sustain = 0; |
EG2Sustain = 1000; |
1444 |
EG2Release = 0.0; |
EG2Release = 0.3; |
1445 |
LFO2ControlDepth = 0; |
LFO2ControlDepth = 0; |
1446 |
LFO2Frequency = 1.0; |
LFO2Frequency = 1.0; |
1447 |
LFO2InternalDepth = 0; |
LFO2InternalDepth = 0; |
1448 |
EG1Decay2 = 0.0; |
EG1Decay2 = 0.0; |
1449 |
EG1InfiniteSustain = false; |
EG1InfiniteSustain = true; |
1450 |
EG1PreAttack = 1000; |
EG1PreAttack = 0; |
1451 |
EG2Decay2 = 0.0; |
EG2Decay2 = 0.0; |
1452 |
EG2InfiniteSustain = false; |
EG2InfiniteSustain = true; |
1453 |
EG2PreAttack = 1000; |
EG2PreAttack = 0; |
1454 |
VelocityResponseCurve = curve_type_nonlinear; |
VelocityResponseCurve = curve_type_nonlinear; |
1455 |
VelocityResponseDepth = 3; |
VelocityResponseDepth = 3; |
1456 |
ReleaseVelocityResponseCurve = curve_type_nonlinear; |
ReleaseVelocityResponseCurve = curve_type_nonlinear; |
1493 |
VCFVelocityDynamicRange = 0x04; |
VCFVelocityDynamicRange = 0x04; |
1494 |
VCFVelocityCurve = curve_type_linear; |
VCFVelocityCurve = curve_type_linear; |
1495 |
VCFType = vcf_type_lowpass; |
VCFType = vcf_type_lowpass; |
1496 |
memset(DimensionUpperLimits, 0, 8); |
memset(DimensionUpperLimits, 127, 8); |
1497 |
} |
} |
1498 |
|
|
1499 |
pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, |
pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, |
1542 |
// first update base class's chunk |
// first update base class's chunk |
1543 |
DLS::Sampler::UpdateChunks(); |
DLS::Sampler::UpdateChunks(); |
1544 |
|
|
1545 |
|
RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP); |
1546 |
|
uint8_t* pData = (uint8_t*) wsmp->LoadChunkData(); |
1547 |
|
pData[12] = Crossfade.in_start; |
1548 |
|
pData[13] = Crossfade.in_end; |
1549 |
|
pData[14] = Crossfade.out_start; |
1550 |
|
pData[15] = Crossfade.out_end; |
1551 |
|
|
1552 |
// make sure '3ewa' chunk exists |
// make sure '3ewa' chunk exists |
1553 |
RIFF::Chunk* _3ewa = pParentList->GetSubChunk(CHUNK_ID_3EWA); |
RIFF::Chunk* _3ewa = pParentList->GetSubChunk(CHUNK_ID_3EWA); |
1554 |
if (!_3ewa) _3ewa = pParentList->AddSubChunk(CHUNK_ID_3EWA, 140); |
if (!_3ewa) _3ewa = pParentList->AddSubChunk(CHUNK_ID_3EWA, 140); |
1555 |
uint8_t* pData = (uint8_t*) _3ewa->LoadChunkData(); |
pData = (uint8_t*) _3ewa->LoadChunkData(); |
1556 |
|
|
1557 |
// update '3ewa' chunk with DimensionRegion's current settings |
// update '3ewa' chunk with DimensionRegion's current settings |
1558 |
|
|
2256 |
// first update base class's chunks |
// first update base class's chunks |
2257 |
DLS::Region::UpdateChunks(); |
DLS::Region::UpdateChunks(); |
2258 |
|
|
2259 |
|
File* pFile = (File*) GetParent()->GetParent(); |
2260 |
|
bool version3 = pFile->pVersion && pFile->pVersion->major == 3; |
2261 |
|
|
2262 |
// update dimension region's chunks |
// update dimension region's chunks |
2263 |
for (int i = 0; i < DimensionRegions; i++) { |
for (int i = 0; i < DimensionRegions; i++) { |
2264 |
pDimensionRegions[i]->UpdateChunks(); |
DimensionRegion* d = pDimensionRegions[i]; |
2265 |
|
|
2266 |
|
// make sure '3ewa' chunk exists (we need to this before |
2267 |
|
// calling DimensionRegion::UpdateChunks, as |
2268 |
|
// DimensionRegion doesn't know which file version it is) |
2269 |
|
RIFF::Chunk* _3ewa = d->pParentList->GetSubChunk(CHUNK_ID_3EWA); |
2270 |
|
if (!_3ewa) d->pParentList->AddSubChunk(CHUNK_ID_3EWA, version3 ? 148 : 140); |
2271 |
|
|
2272 |
|
d->UpdateChunks(); |
2273 |
} |
} |
2274 |
|
|
2275 |
File* pFile = (File*) GetParent()->GetParent(); |
const int iMaxDimensions = version3 ? 8 : 5; |
2276 |
const int iMaxDimensions = (pFile->pVersion && pFile->pVersion->major == 3) ? 8 : 5; |
const int iMaxDimensionRegions = version3 ? 256 : 32; |
|
const int iMaxDimensionRegions = (pFile->pVersion && pFile->pVersion->major == 3) ? 256 : 32; |
|
2277 |
|
|
2278 |
// make sure '3lnk' chunk exists |
// make sure '3lnk' chunk exists |
2279 |
RIFF::Chunk* _3lnk = pCkRegion->GetSubChunk(CHUNK_ID_3LNK); |
RIFF::Chunk* _3lnk = pCkRegion->GetSubChunk(CHUNK_ID_3LNK); |
2280 |
if (!_3lnk) { |
if (!_3lnk) { |
2281 |
const int _3lnkChunkSize = (pFile->pVersion && pFile->pVersion->major == 3) ? 1092 : 172; |
const int _3lnkChunkSize = version3 ? 1092 : 172; |
2282 |
_3lnk = pCkRegion->AddSubChunk(CHUNK_ID_3LNK, _3lnkChunkSize); |
_3lnk = pCkRegion->AddSubChunk(CHUNK_ID_3LNK, _3lnkChunkSize); |
2283 |
memset(_3lnk->LoadChunkData(), 0, _3lnkChunkSize); |
memset(_3lnk->LoadChunkData(), 0, _3lnkChunkSize); |
2284 |
|
|
2302 |
} |
} |
2303 |
|
|
2304 |
// update wave pool table in '3lnk' chunk |
// update wave pool table in '3lnk' chunk |
2305 |
const int iWavePoolOffset = (pFile->pVersion && pFile->pVersion->major == 3) ? 68 : 44; |
const int iWavePoolOffset = version3 ? 68 : 44; |
2306 |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
for (uint i = 0; i < iMaxDimensionRegions; i++) { |
2307 |
int iWaveIndex = -1; |
int iWaveIndex = -1; |
2308 |
if (i < DimensionRegions) { |
if (i < DimensionRegions) { |
2457 |
RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG); |
RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG); |
2458 |
RIFF::List* pNewDimRgnListChunk = _3prg->AddSubList(LIST_TYPE_3EWL); |
RIFF::List* pNewDimRgnListChunk = _3prg->AddSubList(LIST_TYPE_3EWL); |
2459 |
pDimensionRegions[i] = new DimensionRegion(pNewDimRgnListChunk); |
pDimensionRegions[i] = new DimensionRegion(pNewDimRgnListChunk); |
2460 |
|
|
2461 |
|
// copy the upper limits for the other dimensions |
2462 |
|
memcpy(pDimensionRegions[i]->DimensionUpperLimits, |
2463 |
|
pDimensionRegions[i & ((1 << iCurrentBits) - 1)]->DimensionUpperLimits, 8); |
2464 |
|
|
2465 |
DimensionRegions++; |
DimensionRegions++; |
2466 |
} |
} |
2467 |
|
|
2468 |
|
// initialize the upper limits for this dimension |
2469 |
|
for (int z = 0, j = 0 ; z < pDimDef->zones ; z++, j += 1 << iCurrentBits) { |
2470 |
|
uint8_t upperLimit = (z + 1) * 128.0 / pDimDef->zones - 1; |
2471 |
|
for (int i = 0 ; i < 1 << iCurrentBits ; i++) { |
2472 |
|
pDimensionRegions[j + i]->DimensionUpperLimits[Dimensions] = upperLimit; |
2473 |
|
} |
2474 |
|
} |
2475 |
|
|
2476 |
Dimensions++; |
Dimensions++; |
2477 |
|
|
2478 |
// if this is a layer dimension, update 'Layers' attribute |
// if this is a layer dimension, update 'Layers' attribute |
2513 |
for (int i = iDimensionNr + 1; i < Dimensions; i++) |
for (int i = iDimensionNr + 1; i < Dimensions; i++) |
2514 |
iUpperBits += pDimensionDefinitions[i].bits; |
iUpperBits += pDimensionDefinitions[i].bits; |
2515 |
|
|
2516 |
|
RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG); |
2517 |
|
|
2518 |
// delete dimension regions which belong to the given dimension |
// delete dimension regions which belong to the given dimension |
2519 |
// (that is where the dimension's bit > 0) |
// (that is where the dimension's bit > 0) |
2520 |
for (int iUpperBit = 0; iUpperBit < 1 << iUpperBits; iUpperBit++) { |
for (int iUpperBit = 0; iUpperBit < 1 << iUpperBits; iUpperBit++) { |
2523 |
int iToDelete = iUpperBit << (pDimensionDefinitions[iDimensionNr].bits + iLowerBits) | |
int iToDelete = iUpperBit << (pDimensionDefinitions[iDimensionNr].bits + iLowerBits) | |
2524 |
iObsoleteBit << iLowerBits | |
iObsoleteBit << iLowerBits | |
2525 |
iLowerBit; |
iLowerBit; |
2526 |
|
|
2527 |
|
_3prg->DeleteSubChunk(pDimensionRegions[iToDelete]->pParentList); |
2528 |
delete pDimensionRegions[iToDelete]; |
delete pDimensionRegions[iToDelete]; |
2529 |
pDimensionRegions[iToDelete] = NULL; |
pDimensionRegions[iToDelete] = NULL; |
2530 |
DimensionRegions--; |
DimensionRegions--; |
2545 |
} |
} |
2546 |
} |
} |
2547 |
|
|
2548 |
|
// remove the this dimension from the upper limits arrays |
2549 |
|
for (int j = 0 ; j < 256 && pDimensionRegions[j] ; j++) { |
2550 |
|
DimensionRegion* d = pDimensionRegions[j]; |
2551 |
|
for (int i = iDimensionNr + 1; i < Dimensions; i++) { |
2552 |
|
d->DimensionUpperLimits[i - 1] = d->DimensionUpperLimits[i]; |
2553 |
|
} |
2554 |
|
d->DimensionUpperLimits[Dimensions - 1] = 127; |
2555 |
|
} |
2556 |
|
|
2557 |
// 'remove' dimension definition |
// 'remove' dimension definition |
2558 |
for (int i = iDimensionNr + 1; i < Dimensions; i++) { |
for (int i = iDimensionNr + 1; i < Dimensions; i++) { |
2559 |
pDimensionDefinitions[i - 1] = pDimensionDefinitions[i]; |
pDimensionDefinitions[i - 1] = pDimensionDefinitions[i]; |
3018 |
// order (INFO chunk will be moved to first position later) |
// order (INFO chunk will be moved to first position later) |
3019 |
pRIFF->AddSubChunk(CHUNK_ID_VERS, 8); |
pRIFF->AddSubChunk(CHUNK_ID_VERS, 8); |
3020 |
pRIFF->AddSubChunk(CHUNK_ID_COLH, 4); |
pRIFF->AddSubChunk(CHUNK_ID_COLH, 4); |
3021 |
|
pRIFF->AddSubChunk(CHUNK_ID_DLID, 16); |
3022 |
|
|
3023 |
|
GenerateDLSID(); |
3024 |
} |
} |
3025 |
|
|
3026 |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
3217 |
|
|
3218 |
// add mandatory chunks to get the chunks in right order |
// add mandatory chunks to get the chunks in right order |
3219 |
lstInstr->AddSubList(LIST_TYPE_INFO); |
lstInstr->AddSubList(LIST_TYPE_INFO); |
3220 |
|
lstInstr->AddSubChunk(CHUNK_ID_DLID, 16); |
3221 |
|
|
3222 |
Instrument* pInstrument = new Instrument(this, lstInstr); |
Instrument* pInstrument = new Instrument(this, lstInstr); |
3223 |
|
pInstrument->GenerateDLSID(); |
3224 |
|
|
3225 |
lstInstr->AddSubChunk(CHUNK_ID_INSH, 12); |
lstInstr->AddSubChunk(CHUNK_ID_INSH, 12); |
3226 |
|
|
3277 |
} |
} |
3278 |
} |
} |
3279 |
|
|
3280 |
|
/// Updates the 3crc chunk with the checksum of a sample. The |
3281 |
|
/// update is done directly to disk, as this method is called |
3282 |
|
/// after File::Save() |
3283 |
void File::SetSampleChecksum(Sample* pSample, uint32_t crc) { |
void File::SetSampleChecksum(Sample* pSample, uint32_t crc) { |
3284 |
RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC); |
RIFF::Chunk* _3crc = pRIFF->GetSubChunk(CHUNK_ID_3CRC); |
3285 |
if (!_3crc) return; |
if (!_3crc) return; |
3286 |
|
|
3287 |
|
// get the index of the sample |
3288 |
int iWaveIndex = -1; |
int iWaveIndex = -1; |
3289 |
File::SampleList::iterator iter = pSamples->begin(); |
File::SampleList::iterator iter = pSamples->begin(); |
3290 |
File::SampleList::iterator end = pSamples->end(); |
File::SampleList::iterator end = pSamples->end(); |
3296 |
} |
} |
3297 |
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"); |
3298 |
|
|
3299 |
|
// write the CRC-32 checksum to disk |
3300 |
_3crc->SetPos(iWaveIndex * 8); |
_3crc->SetPos(iWaveIndex * 8); |
3301 |
uint32_t tmp = 1; |
uint32_t tmp = 1; |
3302 |
_3crc->WriteUint32(&tmp); // unknown, always 1? |
_3crc->WriteUint32(&tmp); // unknown, always 1? |
3422 |
void File::UpdateChunks() { |
void File::UpdateChunks() { |
3423 |
bool newFile = pRIFF->GetSubList(LIST_TYPE_INFO) == NULL; |
bool newFile = pRIFF->GetSubList(LIST_TYPE_INFO) == NULL; |
3424 |
|
|
3425 |
|
b64BitWavePoolOffsets = pVersion && pVersion->major == 3; |
3426 |
|
|
3427 |
// first update base class's chunks |
// first update base class's chunks |
3428 |
DLS::File::UpdateChunks(); |
DLS::File::UpdateChunks(); |
3429 |
|
|