541 |
// local buffer reallocation - hope this won't happen |
// local buffer reallocation - hope this won't happen |
542 |
if (this->pDecompressionBuffer) delete[] (int8_t*) this->pDecompressionBuffer; |
if (this->pDecompressionBuffer) delete[] (int8_t*) this->pDecompressionBuffer; |
543 |
this->pDecompressionBuffer = new int8_t[assumedsize << 1]; // double of current needed size |
this->pDecompressionBuffer = new int8_t[assumedsize << 1]; // double of current needed size |
544 |
this->DecompressionBufferSize = assumedsize; |
this->DecompressionBufferSize = assumedsize << 1; |
545 |
} |
} |
546 |
|
|
547 |
int16_t compressionmode, left, dleft, right, dright; |
int16_t compressionmode, left, dleft, right, dright; |
681 |
|
|
682 |
Sample::~Sample() { |
Sample::~Sample() { |
683 |
Instances--; |
Instances--; |
684 |
if (!Instances && pDecompressionBuffer) delete[] (int8_t*) pDecompressionBuffer; |
if (!Instances && pDecompressionBuffer) { |
685 |
|
delete[] (int8_t*) pDecompressionBuffer; |
686 |
|
pDecompressionBuffer = NULL; |
687 |
|
} |
688 |
if (FrameTable) delete[] FrameTable; |
if (FrameTable) delete[] FrameTable; |
689 |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
690 |
} |
} |
1086 |
Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : DLS::Region((DLS::Instrument*) pInstrument, rgnList) { |
Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : DLS::Region((DLS::Instrument*) pInstrument, rgnList) { |
1087 |
// Initialization |
// Initialization |
1088 |
Dimensions = 0; |
Dimensions = 0; |
1089 |
for (int i = 0; i < 32; i++) { |
for (int i = 0; i < 256; i++) { |
1090 |
pDimensionRegions[i] = NULL; |
pDimensionRegions[i] = NULL; |
1091 |
} |
} |
1092 |
Layers = 1; |
Layers = 1; |
1093 |
|
File* file = (File*) GetParent()->GetParent(); |
1094 |
|
int dimensionBits = (file->pVersion && file->pVersion->major == 3) ? 8 : 5; |
1095 |
|
|
1096 |
// Actual Loading |
// Actual Loading |
1097 |
|
|
1100 |
RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK); |
RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK); |
1101 |
if (_3lnk) { |
if (_3lnk) { |
1102 |
DimensionRegions = _3lnk->ReadUint32(); |
DimensionRegions = _3lnk->ReadUint32(); |
1103 |
for (int i = 0; i < 5; i++) { |
for (int i = 0; i < dimensionBits; i++) { |
1104 |
dimension_t dimension = static_cast<dimension_t>(_3lnk->ReadUint8()); |
dimension_t dimension = static_cast<dimension_t>(_3lnk->ReadUint8()); |
1105 |
uint8_t bits = _3lnk->ReadUint8(); |
uint8_t bits = _3lnk->ReadUint8(); |
1106 |
if (dimension == dimension_none) { // inactive dimension |
if (dimension == dimension_none) { // inactive dimension |
1143 |
else { // custom defined ranges |
else { // custom defined ranges |
1144 |
pDimDef->split_type = split_type_customvelocity; |
pDimDef->split_type = split_type_customvelocity; |
1145 |
pDimDef->ranges = new range_t[pDimDef->zones]; |
pDimDef->ranges = new range_t[pDimDef->zones]; |
1146 |
unsigned int bits[5] = {0,0,0,0,0}; |
uint8_t bits[8] = { 0 }; |
1147 |
int previousUpperLimit = -1; |
int previousUpperLimit = -1; |
1148 |
for (int velocityZone = 0; velocityZone < pDimDef->zones; velocityZone++) { |
for (int velocityZone = 0; velocityZone < pDimDef->zones; velocityZone++) { |
1149 |
bits[i] = velocityZone; |
bits[i] = velocityZone; |
1150 |
DimensionRegion* pDimRegion = GetDimensionRegionByBit(bits[4],bits[3],bits[2],bits[1],bits[0]); |
DimensionRegion* pDimRegion = GetDimensionRegionByBit(bits); |
1151 |
|
|
1152 |
pDimDef->ranges[velocityZone].low = previousUpperLimit + 1; |
pDimDef->ranges[velocityZone].low = previousUpperLimit + 1; |
1153 |
pDimDef->ranges[velocityZone].high = pDimRegion->VelocityUpperLimit; |
pDimDef->ranges[velocityZone].high = pDimRegion->VelocityUpperLimit; |
1197 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
1198 |
if (pDimensionDefinitions[i].ranges) delete[] pDimensionDefinitions[i].ranges; |
if (pDimensionDefinitions[i].ranges) delete[] pDimensionDefinitions[i].ranges; |
1199 |
} |
} |
1200 |
for (int i = 0; i < 32; i++) { |
for (int i = 0; i < 256; i++) { |
1201 |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
1202 |
} |
} |
1203 |
} |
} |
1215 |
* left channel, 1 for right channel or 0 for layer 0, 1 for layer 1, |
* left channel, 1 for right channel or 0 for layer 0, 1 for layer 1, |
1216 |
* etc.). |
* etc.). |
1217 |
* |
* |
1218 |
* @param Dim4Val MIDI controller value (0-127) for dimension 4 |
* @param DimValues MIDI controller values (0-127) for dimension 0 to 7 |
|
* @param Dim3Val MIDI controller value (0-127) for dimension 3 |
|
|
* @param Dim2Val MIDI controller value (0-127) for dimension 2 |
|
|
* @param Dim1Val MIDI controller value (0-127) for dimension 1 |
|
|
* @param Dim0Val MIDI controller value (0-127) for dimension 0 |
|
1219 |
* @returns adress to the DimensionRegion for the given situation |
* @returns adress to the DimensionRegion for the given situation |
1220 |
* @see pDimensionDefinitions |
* @see pDimensionDefinitions |
1221 |
* @see Dimensions |
* @see Dimensions |
1222 |
*/ |
*/ |
1223 |
DimensionRegion* Region::GetDimensionRegionByValue(uint Dim4Val, uint Dim3Val, uint Dim2Val, uint Dim1Val, uint Dim0Val) { |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
1224 |
uint8_t bits[5] = {Dim0Val,Dim1Val,Dim2Val,Dim3Val,Dim4Val}; |
uint8_t bits[8] = { 0 }; |
1225 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
1226 |
|
bits[i] = DimValues[i]; |
1227 |
switch (pDimensionDefinitions[i].split_type) { |
switch (pDimensionDefinitions[i].split_type) { |
1228 |
case split_type_normal: |
case split_type_normal: |
1229 |
bits[i] /= pDimensionDefinitions[i].zone_size; |
bits[i] /= pDimensionDefinitions[i].zone_size; |
1237 |
break; |
break; |
1238 |
} |
} |
1239 |
} |
} |
1240 |
return GetDimensionRegionByBit(bits[4],bits[3],bits[2],bits[1],bits[0]); |
return GetDimensionRegionByBit(bits); |
1241 |
} |
} |
1242 |
|
|
1243 |
/** |
/** |
1245 |
* numbers (zone index). You usually use <i>GetDimensionRegionByValue</i> |
* numbers (zone index). You usually use <i>GetDimensionRegionByValue</i> |
1246 |
* instead of calling this method directly! |
* instead of calling this method directly! |
1247 |
* |
* |
1248 |
* @param Dim4Bit Bit number for dimension 4 |
* @param DimBits Bit numbers for dimension 0 to 7 |
|
* @param Dim3Bit Bit number for dimension 3 |
|
|
* @param Dim2Bit Bit number for dimension 2 |
|
|
* @param Dim1Bit Bit number for dimension 1 |
|
|
* @param Dim0Bit Bit number for dimension 0 |
|
1249 |
* @returns adress to the DimensionRegion for the given dimension |
* @returns adress to the DimensionRegion for the given dimension |
1250 |
* bit numbers |
* bit numbers |
1251 |
* @see GetDimensionRegionByValue() |
* @see GetDimensionRegionByValue() |
1252 |
*/ |
*/ |
1253 |
DimensionRegion* Region::GetDimensionRegionByBit(uint8_t Dim4Bit, uint8_t Dim3Bit, uint8_t Dim2Bit, uint8_t Dim1Bit, uint8_t Dim0Bit) { |
DimensionRegion* Region::GetDimensionRegionByBit(const uint8_t DimBits[8]) { |
1254 |
return *(pDimensionRegions + ((((((((Dim4Bit << pDimensionDefinitions[3].bits) | Dim3Bit) |
return pDimensionRegions[((((((DimBits[7] << pDimensionDefinitions[6].bits | DimBits[6]) |
1255 |
<< pDimensionDefinitions[2].bits) | Dim2Bit) |
<< pDimensionDefinitions[5].bits | DimBits[5]) |
1256 |
<< pDimensionDefinitions[1].bits) | Dim1Bit) |
<< pDimensionDefinitions[4].bits | DimBits[4]) |
1257 |
<< pDimensionDefinitions[0].bits) | Dim0Bit) ); |
<< pDimensionDefinitions[3].bits | DimBits[3]) |
1258 |
|
<< pDimensionDefinitions[2].bits | DimBits[2]) |
1259 |
|
<< pDimensionDefinitions[1].bits | DimBits[1]) |
1260 |
|
<< pDimensionDefinitions[0].bits | DimBits[0]]; |
1261 |
} |
} |
1262 |
|
|
1263 |
/** |
/** |
1275 |
} |
} |
1276 |
|
|
1277 |
Sample* Region::GetSampleFromWavePool(unsigned int WavePoolTableIndex) { |
Sample* Region::GetSampleFromWavePool(unsigned int WavePoolTableIndex) { |
1278 |
|
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
1279 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
1280 |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
1281 |
Sample* sample = file->GetFirstSample(); |
Sample* sample = file->GetFirstSample(); |
1317 |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
1318 |
if (!lrgn) throw gig::Exception("Mandatory chunks in <ins > chunk not found."); |
if (!lrgn) throw gig::Exception("Mandatory chunks in <ins > chunk not found."); |
1319 |
pRegions = new Region*[Regions]; |
pRegions = new Region*[Regions]; |
1320 |
|
for (uint i = 0; i < Regions; i++) pRegions[i] = NULL; |
1321 |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
1322 |
unsigned int iRegion = 0; |
unsigned int iRegion = 0; |
1323 |
while (rgn) { |
while (rgn) { |
1341 |
if (pRegions) { |
if (pRegions) { |
1342 |
if (pRegions[i]) delete (pRegions[i]); |
if (pRegions[i]) delete (pRegions[i]); |
1343 |
} |
} |
|
delete[] pRegions; |
|
1344 |
} |
} |
1345 |
|
if (pRegions) delete[] pRegions; |
1346 |
} |
} |
1347 |
|
|
1348 |
/** |
/** |
1398 |
pInstruments = NULL; |
pInstruments = NULL; |
1399 |
} |
} |
1400 |
|
|
1401 |
|
File::~File() { |
1402 |
|
// free samples |
1403 |
|
if (pSamples) { |
1404 |
|
SamplesIterator = pSamples->begin(); |
1405 |
|
while (SamplesIterator != pSamples->end() ) { |
1406 |
|
delete (*SamplesIterator); |
1407 |
|
SamplesIterator++; |
1408 |
|
} |
1409 |
|
pSamples->clear(); |
1410 |
|
delete pSamples; |
1411 |
|
|
1412 |
|
} |
1413 |
|
// free instruments |
1414 |
|
if (pInstruments) { |
1415 |
|
InstrumentsIterator = pInstruments->begin(); |
1416 |
|
while (InstrumentsIterator != pInstruments->end() ) { |
1417 |
|
delete (*InstrumentsIterator); |
1418 |
|
InstrumentsIterator++; |
1419 |
|
} |
1420 |
|
pInstruments->clear(); |
1421 |
|
delete pInstruments; |
1422 |
|
} |
1423 |
|
} |
1424 |
|
|
1425 |
Sample* File::GetFirstSample() { |
Sample* File::GetFirstSample() { |
1426 |
if (!pSamples) LoadSamples(); |
if (!pSamples) LoadSamples(); |
1427 |
if (!pSamples) return NULL; |
if (!pSamples) return NULL; |