51 |
|
|
52 |
namespace gig { |
namespace gig { |
53 |
|
|
|
// *************** dimension_def_t *************** |
|
|
// * |
|
|
|
|
|
dimension_def_t& dimension_def_t::operator=(const dimension_def_t& arg) { |
|
|
dimension = arg.dimension; |
|
|
bits = arg.bits; |
|
|
zones = arg.zones; |
|
|
split_type = arg.split_type; |
|
|
ranges = arg.ranges; |
|
|
zone_size = arg.zone_size; |
|
|
if (ranges) { |
|
|
ranges = new range_t[zones]; |
|
|
for (int i = 0; i < zones; i++) |
|
|
ranges[i] = arg.ranges[i]; |
|
|
} |
|
|
return *this; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
54 |
// *************** progress_t *************** |
// *************** progress_t *************** |
55 |
// * |
// * |
56 |
|
|
348 |
} |
} |
349 |
FrameOffset = 0; // just for streaming compressed samples |
FrameOffset = 0; // just for streaming compressed samples |
350 |
|
|
351 |
LoopSize = LoopEnd - LoopStart; |
LoopSize = LoopEnd - LoopStart + 1; |
352 |
} |
} |
353 |
|
|
354 |
/** |
/** |
722 |
* @param SampleCount number of sample points to read |
* @param SampleCount number of sample points to read |
723 |
* @param pPlaybackState will be used to store and reload the playback |
* @param pPlaybackState will be used to store and reload the playback |
724 |
* state for the next ReadAndLoop() call |
* state for the next ReadAndLoop() call |
725 |
|
* @param pDimRgn dimension region with looping information |
726 |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
* @param pExternalDecompressionBuffer (optional) external buffer to use for decompression |
727 |
* @returns number of successfully read sample points |
* @returns number of successfully read sample points |
728 |
* @see CreateDecompressionBuffer() |
* @see CreateDecompressionBuffer() |
729 |
*/ |
*/ |
730 |
unsigned long Sample::ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, buffer_t* pExternalDecompressionBuffer) { |
unsigned long Sample::ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, |
731 |
|
DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer) { |
732 |
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
unsigned long samplestoread = SampleCount, totalreadsamples = 0, readsamples, samplestoloopend; |
733 |
uint8_t* pDst = (uint8_t*) pBuffer; |
uint8_t* pDst = (uint8_t*) pBuffer; |
734 |
|
|
735 |
SetPos(pPlaybackState->position); // recover position from the last time |
SetPos(pPlaybackState->position); // recover position from the last time |
736 |
|
|
737 |
if (this->Loops && GetPos() <= this->LoopEnd) { // honor looping if there are loop points defined |
if (pDimRgn->SampleLoops) { // honor looping if there are loop points defined |
738 |
|
|
739 |
switch (this->LoopType) { |
const DLS::sample_loop_t& loop = pDimRgn->pSampleLoops[0]; |
740 |
|
const uint32_t loopEnd = loop.LoopStart + loop.LoopLength; |
741 |
|
|
742 |
case loop_type_bidirectional: { //TODO: not tested yet! |
if (GetPos() <= loopEnd) { |
743 |
do { |
switch (loop.LoopType) { |
|
// if not endless loop check if max. number of loop cycles have been passed |
|
|
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
|
|
|
|
|
if (!pPlaybackState->reverse) { // forward playback |
|
|
do { |
|
|
samplestoloopend = this->LoopEnd - GetPos(); |
|
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
|
|
samplestoread -= readsamples; |
|
|
totalreadsamples += readsamples; |
|
|
if (readsamples == samplestoloopend) { |
|
|
pPlaybackState->reverse = true; |
|
|
break; |
|
|
} |
|
|
} while (samplestoread && readsamples); |
|
|
} |
|
|
else { // backward playback |
|
744 |
|
|
745 |
// as we can only read forward from disk, we have to |
case loop_type_bidirectional: { //TODO: not tested yet! |
746 |
// determine the end position within the loop first, |
do { |
747 |
// read forward from that 'end' and finally after |
// if not endless loop check if max. number of loop cycles have been passed |
748 |
// reading, swap all sample frames so it reflects |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
749 |
// backward playback |
|
750 |
|
if (!pPlaybackState->reverse) { // forward playback |
751 |
unsigned long swapareastart = totalreadsamples; |
do { |
752 |
unsigned long loopoffset = GetPos() - this->LoopStart; |
samplestoloopend = loopEnd - GetPos(); |
753 |
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
754 |
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
samplestoread -= readsamples; |
755 |
|
totalreadsamples += readsamples; |
756 |
SetPos(reverseplaybackend); |
if (readsamples == samplestoloopend) { |
757 |
|
pPlaybackState->reverse = true; |
758 |
// read samples for backward playback |
break; |
759 |
do { |
} |
760 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoreadinloop, pExternalDecompressionBuffer); |
} while (samplestoread && readsamples); |
761 |
samplestoreadinloop -= readsamples; |
} |
762 |
samplestoread -= readsamples; |
else { // backward playback |
|
totalreadsamples += readsamples; |
|
|
} while (samplestoreadinloop && readsamples); |
|
763 |
|
|
764 |
SetPos(reverseplaybackend); // pretend we really read backwards |
// as we can only read forward from disk, we have to |
765 |
|
// determine the end position within the loop first, |
766 |
|
// read forward from that 'end' and finally after |
767 |
|
// reading, swap all sample frames so it reflects |
768 |
|
// backward playback |
769 |
|
|
770 |
|
unsigned long swapareastart = totalreadsamples; |
771 |
|
unsigned long loopoffset = GetPos() - loop.LoopStart; |
772 |
|
unsigned long samplestoreadinloop = Min(samplestoread, loopoffset); |
773 |
|
unsigned long reverseplaybackend = GetPos() - samplestoreadinloop; |
774 |
|
|
775 |
|
SetPos(reverseplaybackend); |
776 |
|
|
777 |
|
// read samples for backward playback |
778 |
|
do { |
779 |
|
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], samplestoreadinloop, pExternalDecompressionBuffer); |
780 |
|
samplestoreadinloop -= readsamples; |
781 |
|
samplestoread -= readsamples; |
782 |
|
totalreadsamples += readsamples; |
783 |
|
} while (samplestoreadinloop && readsamples); |
784 |
|
|
785 |
|
SetPos(reverseplaybackend); // pretend we really read backwards |
786 |
|
|
787 |
|
if (reverseplaybackend == loop.LoopStart) { |
788 |
|
pPlaybackState->loop_cycles_left--; |
789 |
|
pPlaybackState->reverse = false; |
790 |
|
} |
791 |
|
|
792 |
if (reverseplaybackend == this->LoopStart) { |
// reverse the sample frames for backward playback |
793 |
pPlaybackState->loop_cycles_left--; |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
|
pPlaybackState->reverse = false; |
|
794 |
} |
} |
795 |
|
} while (samplestoread && readsamples); |
796 |
|
break; |
797 |
|
} |
798 |
|
|
799 |
// reverse the sample frames for backward playback |
case loop_type_backward: { // TODO: not tested yet! |
800 |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
// forward playback (not entered the loop yet) |
801 |
} |
if (!pPlaybackState->reverse) do { |
802 |
} while (samplestoread && readsamples); |
samplestoloopend = loopEnd - GetPos(); |
803 |
break; |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
804 |
} |
samplestoread -= readsamples; |
805 |
|
totalreadsamples += readsamples; |
806 |
case loop_type_backward: { // TODO: not tested yet! |
if (readsamples == samplestoloopend) { |
807 |
// forward playback (not entered the loop yet) |
pPlaybackState->reverse = true; |
808 |
if (!pPlaybackState->reverse) do { |
break; |
809 |
samplestoloopend = this->LoopEnd - GetPos(); |
} |
810 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
} while (samplestoread && readsamples); |
|
samplestoread -= readsamples; |
|
|
totalreadsamples += readsamples; |
|
|
if (readsamples == samplestoloopend) { |
|
|
pPlaybackState->reverse = true; |
|
|
break; |
|
|
} |
|
|
} while (samplestoread && readsamples); |
|
811 |
|
|
812 |
if (!samplestoread) break; |
if (!samplestoread) break; |
813 |
|
|
814 |
// as we can only read forward from disk, we have to |
// as we can only read forward from disk, we have to |
815 |
// determine the end position within the loop first, |
// determine the end position within the loop first, |
816 |
// read forward from that 'end' and finally after |
// read forward from that 'end' and finally after |
817 |
// reading, swap all sample frames so it reflects |
// reading, swap all sample frames so it reflects |
818 |
// backward playback |
// backward playback |
819 |
|
|
820 |
unsigned long swapareastart = totalreadsamples; |
unsigned long swapareastart = totalreadsamples; |
821 |
unsigned long loopoffset = GetPos() - this->LoopStart; |
unsigned long loopoffset = GetPos() - loop.LoopStart; |
822 |
unsigned long samplestoreadinloop = (this->LoopPlayCount) ? Min(samplestoread, pPlaybackState->loop_cycles_left * LoopSize - loopoffset) |
unsigned long samplestoreadinloop = (this->LoopPlayCount) ? Min(samplestoread, pPlaybackState->loop_cycles_left * loop.LoopLength - loopoffset) |
823 |
: samplestoread; |
: samplestoread; |
824 |
unsigned long reverseplaybackend = this->LoopStart + Abs((loopoffset - samplestoreadinloop) % this->LoopSize); |
unsigned long reverseplaybackend = loop.LoopStart + Abs((loopoffset - samplestoreadinloop) % loop.LoopLength); |
825 |
|
|
826 |
SetPos(reverseplaybackend); |
SetPos(reverseplaybackend); |
827 |
|
|
828 |
// read samples for backward playback |
// read samples for backward playback |
829 |
do { |
do { |
830 |
// if not endless loop check if max. number of loop cycles have been passed |
// if not endless loop check if max. number of loop cycles have been passed |
831 |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
832 |
samplestoloopend = this->LoopEnd - GetPos(); |
samplestoloopend = loopEnd - GetPos(); |
833 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoreadinloop, samplestoloopend), pExternalDecompressionBuffer); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoreadinloop, samplestoloopend), pExternalDecompressionBuffer); |
834 |
samplestoreadinloop -= readsamples; |
samplestoreadinloop -= readsamples; |
835 |
samplestoread -= readsamples; |
samplestoread -= readsamples; |
836 |
totalreadsamples += readsamples; |
totalreadsamples += readsamples; |
837 |
if (readsamples == samplestoloopend) { |
if (readsamples == samplestoloopend) { |
838 |
pPlaybackState->loop_cycles_left--; |
pPlaybackState->loop_cycles_left--; |
839 |
SetPos(this->LoopStart); |
SetPos(loop.LoopStart); |
840 |
} |
} |
841 |
} while (samplestoreadinloop && readsamples); |
} while (samplestoreadinloop && readsamples); |
842 |
|
|
843 |
SetPos(reverseplaybackend); // pretend we really read backwards |
SetPos(reverseplaybackend); // pretend we really read backwards |
844 |
|
|
845 |
// reverse the sample frames for backward playback |
// reverse the sample frames for backward playback |
846 |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
847 |
break; |
break; |
848 |
} |
} |
849 |
|
|
850 |
default: case loop_type_normal: { |
default: case loop_type_normal: { |
851 |
do { |
do { |
852 |
// if not endless loop check if max. number of loop cycles have been passed |
// if not endless loop check if max. number of loop cycles have been passed |
853 |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
if (this->LoopPlayCount && !pPlaybackState->loop_cycles_left) break; |
854 |
samplestoloopend = this->LoopEnd - GetPos(); |
samplestoloopend = loopEnd - GetPos(); |
855 |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
readsamples = Read(&pDst[totalreadsamples * this->FrameSize], Min(samplestoread, samplestoloopend), pExternalDecompressionBuffer); |
856 |
samplestoread -= readsamples; |
samplestoread -= readsamples; |
857 |
totalreadsamples += readsamples; |
totalreadsamples += readsamples; |
858 |
if (readsamples == samplestoloopend) { |
if (readsamples == samplestoloopend) { |
859 |
pPlaybackState->loop_cycles_left--; |
pPlaybackState->loop_cycles_left--; |
860 |
SetPos(this->LoopStart); |
SetPos(loop.LoopStart); |
861 |
} |
} |
862 |
} while (samplestoread && readsamples); |
} while (samplestoread && readsamples); |
863 |
break; |
break; |
864 |
|
} |
865 |
} |
} |
866 |
} |
} |
867 |
} |
} |
1436 |
VCFCutoffController <= vcf_cutoff_ctrl_none2 ? VCFVelocityScale : 0); |
VCFCutoffController <= vcf_cutoff_ctrl_none2 ? VCFVelocityScale : 0); |
1437 |
|
|
1438 |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
1439 |
|
VelocityTable = 0; |
1440 |
} |
} |
1441 |
|
|
1442 |
/** |
/** |
1956 |
delete pVelocityTables; |
delete pVelocityTables; |
1957 |
pVelocityTables = NULL; |
pVelocityTables = NULL; |
1958 |
} |
} |
1959 |
|
if (VelocityTable) delete[] VelocityTable; |
1960 |
} |
} |
1961 |
|
|
1962 |
/** |
/** |
2081 |
pDimensionDefinitions[i].bits = 0; |
pDimensionDefinitions[i].bits = 0; |
2082 |
pDimensionDefinitions[i].zones = 0; |
pDimensionDefinitions[i].zones = 0; |
2083 |
pDimensionDefinitions[i].split_type = split_type_bit; |
pDimensionDefinitions[i].split_type = split_type_bit; |
|
pDimensionDefinitions[i].ranges = NULL; |
|
2084 |
pDimensionDefinitions[i].zone_size = 0; |
pDimensionDefinitions[i].zone_size = 0; |
2085 |
} |
} |
2086 |
else { // active dimension |
else { // active dimension |
2090 |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
2091 |
dimension == dimension_samplechannel || |
dimension == dimension_samplechannel || |
2092 |
dimension == dimension_releasetrigger || |
dimension == dimension_releasetrigger || |
2093 |
|
dimension == dimension_keyboard || |
2094 |
dimension == dimension_roundrobin || |
dimension == dimension_roundrobin || |
2095 |
dimension == dimension_random) ? split_type_bit |
dimension == dimension_random) ? split_type_bit |
2096 |
: split_type_normal; |
: split_type_normal; |
|
pDimensionDefinitions[i].ranges = NULL; // it's not possible to check velocity dimensions for custom defined ranges at this point |
|
2097 |
pDimensionDefinitions[i].zone_size = |
pDimensionDefinitions[i].zone_size = |
2098 |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128.0 / pDimensionDefinitions[i].zones |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128.0 / pDimensionDefinitions[i].zones |
2099 |
: 0; |
: 0; |
2104 |
} |
} |
2105 |
_3lnk->SetPos(3, RIFF::stream_curpos); // jump forward to next dimension definition |
_3lnk->SetPos(3, RIFF::stream_curpos); // jump forward to next dimension definition |
2106 |
} |
} |
2107 |
|
for (int i = dimensionBits ; i < 8 ; i++) pDimensionDefinitions[i].bits = 0; |
2108 |
|
|
2109 |
// check velocity dimension (if there is one) for custom defined zone ranges |
// if there's a velocity dimension and custom velocity zone splits are used, |
2110 |
for (uint i = 0; i < Dimensions; i++) { |
// update the VelocityTables in the dimension regions |
2111 |
dimension_def_t* pDimDef = pDimensionDefinitions + i; |
UpdateVelocityTable(); |
|
if (pDimDef->dimension == dimension_velocity) { |
|
|
if (pDimensionRegions[0]->VelocityUpperLimit == 0) { |
|
|
// no custom defined ranges |
|
|
pDimDef->split_type = split_type_normal; |
|
|
pDimDef->ranges = NULL; |
|
|
} |
|
|
else { // custom defined ranges |
|
|
pDimDef->split_type = split_type_customvelocity; |
|
|
pDimDef->ranges = new range_t[pDimDef->zones]; |
|
|
UpdateVelocityTable(pDimDef); |
|
|
} |
|
|
} |
|
|
} |
|
2112 |
|
|
2113 |
// jump to start of the wave pool indices (if not already there) |
// jump to start of the wave pool indices (if not already there) |
|
File* file = (File*) GetParent()->GetParent(); |
|
2114 |
if (file->pVersion && file->pVersion->major == 3) |
if (file->pVersion && file->pVersion->major == 3) |
2115 |
_3lnk->SetPos(68); // version 3 has a different 3lnk structure |
_3lnk->SetPos(68); // version 3 has a different 3lnk structure |
2116 |
else |
else |
2208 |
} |
} |
2209 |
} |
} |
2210 |
|
|
2211 |
void Region::UpdateVelocityTable(dimension_def_t* pDimDef) { |
void Region::UpdateVelocityTable() { |
2212 |
// get dimension's index |
// get velocity dimension's index |
2213 |
int iDimensionNr = -1; |
int veldim = -1; |
2214 |
for (int i = 0; i < Dimensions; i++) { |
for (int i = 0 ; i < Dimensions ; i++) { |
2215 |
if (&pDimensionDefinitions[i] == pDimDef) { |
if (pDimensionDefinitions[i].dimension == gig::dimension_velocity) { |
2216 |
iDimensionNr = i; |
veldim = i; |
2217 |
break; |
break; |
2218 |
} |
} |
2219 |
} |
} |
2220 |
if (iDimensionNr < 0) throw gig::Exception("Invalid dimension_def_t pointer"); |
if (veldim == -1) return; |
2221 |
|
|
2222 |
|
int step = 1; |
2223 |
|
for (int i = 0 ; i < veldim ; i++) step <<= pDimensionDefinitions[i].bits; |
2224 |
|
int skipveldim = (step << pDimensionDefinitions[veldim].bits) - step; |
2225 |
|
int end = step * pDimensionDefinitions[veldim].zones; |
2226 |
|
|
2227 |
|
// loop through all dimension regions for all dimensions except the velocity dimension |
2228 |
|
int dim[8] = { 0 }; |
2229 |
|
for (int i = 0 ; i < DimensionRegions ; i++) { |
2230 |
|
|
2231 |
|
if (pDimensionRegions[i]->VelocityUpperLimit) { |
2232 |
|
// create the velocity table |
2233 |
|
uint8_t* table = pDimensionRegions[i]->VelocityTable; |
2234 |
|
if (!table) { |
2235 |
|
table = new uint8_t[128]; |
2236 |
|
pDimensionRegions[i]->VelocityTable = table; |
2237 |
|
} |
2238 |
|
int tableidx = 0; |
2239 |
|
int velocityZone = 0; |
2240 |
|
for (int k = i ; k < end ; k += step) { |
2241 |
|
DimensionRegion *d = pDimensionRegions[k]; |
2242 |
|
for (; tableidx <= d->VelocityUpperLimit ; tableidx++) table[tableidx] = velocityZone; |
2243 |
|
velocityZone++; |
2244 |
|
} |
2245 |
|
} else { |
2246 |
|
if (pDimensionRegions[i]->VelocityTable) { |
2247 |
|
delete[] pDimensionRegions[i]->VelocityTable; |
2248 |
|
pDimensionRegions[i]->VelocityTable = 0; |
2249 |
|
} |
2250 |
|
} |
2251 |
|
|
2252 |
uint8_t bits[8] = { 0 }; |
int j; |
2253 |
int previousUpperLimit = -1; |
int shift = 0; |
2254 |
for (int velocityZone = 0; velocityZone < pDimDef->zones; velocityZone++) { |
for (j = 0 ; j < Dimensions ; j++) { |
2255 |
bits[iDimensionNr] = velocityZone; |
if (j == veldim) i += skipveldim; // skip velocity dimension |
2256 |
DimensionRegion* pDimRegion = GetDimensionRegionByBit(bits); |
else { |
2257 |
|
dim[j]++; |
2258 |
pDimDef->ranges[velocityZone].low = previousUpperLimit + 1; |
if (dim[j] < pDimensionDefinitions[j].zones) break; |
2259 |
pDimDef->ranges[velocityZone].high = pDimRegion->VelocityUpperLimit; |
else { |
2260 |
previousUpperLimit = pDimDef->ranges[velocityZone].high; |
// skip unused dimension regions |
2261 |
// fill velocity table |
dim[j] = 0; |
2262 |
for (int i = pDimDef->ranges[velocityZone].low; i <= pDimDef->ranges[velocityZone].high; i++) { |
i += ((1 << pDimensionDefinitions[j].bits) - |
2263 |
VelocityTable[i] = velocityZone; |
pDimensionDefinitions[j].zones) << shift; |
2264 |
|
} |
2265 |
|
} |
2266 |
|
shift += pDimensionDefinitions[j].bits; |
2267 |
} |
} |
2268 |
|
if (j == Dimensions) break; |
2269 |
} |
} |
2270 |
} |
} |
2271 |
|
|
2320 |
// if this is a layer dimension, update 'Layers' attribute |
// if this is a layer dimension, update 'Layers' attribute |
2321 |
if (pDimDef->dimension == dimension_layer) Layers = pDimDef->zones; |
if (pDimDef->dimension == dimension_layer) Layers = pDimDef->zones; |
2322 |
|
|
2323 |
// if this is velocity dimension and got custom defined ranges, update velocity table |
UpdateVelocityTable(); |
|
if (pDimDef->dimension == dimension_velocity && |
|
|
pDimDef->split_type == split_type_customvelocity) { |
|
|
UpdateVelocityTable(pDimDef); |
|
|
} |
|
2324 |
} |
} |
2325 |
|
|
2326 |
/** @brief Delete an existing dimension. |
/** @brief Delete an existing dimension. |
2390 |
pDimensionDefinitions[Dimensions - 1].dimension = dimension_none; |
pDimensionDefinitions[Dimensions - 1].dimension = dimension_none; |
2391 |
pDimensionDefinitions[Dimensions - 1].bits = 0; |
pDimensionDefinitions[Dimensions - 1].bits = 0; |
2392 |
pDimensionDefinitions[Dimensions - 1].zones = 0; |
pDimensionDefinitions[Dimensions - 1].zones = 0; |
|
if (pDimensionDefinitions[Dimensions - 1].ranges) { |
|
|
delete[] pDimensionDefinitions[Dimensions - 1].ranges; |
|
|
pDimensionDefinitions[Dimensions - 1].ranges = NULL; |
|
|
} |
|
2393 |
|
|
2394 |
Dimensions--; |
Dimensions--; |
2395 |
|
|
2398 |
} |
} |
2399 |
|
|
2400 |
Region::~Region() { |
Region::~Region() { |
|
for (uint i = 0; i < Dimensions; i++) { |
|
|
if (pDimensionDefinitions[i].ranges) delete[] pDimensionDefinitions[i].ranges; |
|
|
} |
|
2401 |
for (int i = 0; i < 256; i++) { |
for (int i = 0; i < 256; i++) { |
2402 |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
if (pDimensionRegions[i]) delete pDimensionRegions[i]; |
2403 |
} |
} |
2422 |
* @see Dimensions |
* @see Dimensions |
2423 |
*/ |
*/ |
2424 |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
DimensionRegion* Region::GetDimensionRegionByValue(const uint DimValues[8]) { |
2425 |
uint8_t bits[8] = { 0 }; |
uint8_t bits; |
2426 |
|
int veldim = -1; |
2427 |
|
int velbitpos; |
2428 |
|
int bitpos = 0; |
2429 |
|
int dimregidx = 0; |
2430 |
for (uint i = 0; i < Dimensions; i++) { |
for (uint i = 0; i < Dimensions; i++) { |
2431 |
bits[i] = DimValues[i]; |
if (pDimensionDefinitions[i].dimension == dimension_velocity) { |
2432 |
switch (pDimensionDefinitions[i].split_type) { |
// the velocity dimension must be handled after the other dimensions |
2433 |
case split_type_normal: |
veldim = i; |
2434 |
bits[i] = uint8_t(bits[i] / pDimensionDefinitions[i].zone_size); |
velbitpos = bitpos; |
2435 |
break; |
} else { |
2436 |
case split_type_customvelocity: |
switch (pDimensionDefinitions[i].split_type) { |
2437 |
bits[i] = VelocityTable[bits[i]]; |
case split_type_normal: |
2438 |
break; |
bits = uint8_t(DimValues[i] / pDimensionDefinitions[i].zone_size); |
2439 |
case split_type_bit: // the value is already the sought dimension bit number |
break; |
2440 |
const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; |
case split_type_bit: // the value is already the sought dimension bit number |
2441 |
bits[i] = bits[i] & limiter_mask; // just make sure the value don't uses more bits than allowed |
const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; |
2442 |
break; |
bits = DimValues[i] & limiter_mask; // just make sure the value doesn't use more bits than allowed |
2443 |
|
break; |
2444 |
|
} |
2445 |
|
dimregidx |= bits << bitpos; |
2446 |
} |
} |
2447 |
|
bitpos += pDimensionDefinitions[i].bits; |
2448 |
} |
} |
2449 |
return GetDimensionRegionByBit(bits); |
DimensionRegion* dimreg = pDimensionRegions[dimregidx]; |
2450 |
|
if (veldim != -1) { |
2451 |
|
// (dimreg is now the dimension region for the lowest velocity) |
2452 |
|
if (dimreg->VelocityUpperLimit) // custom defined zone ranges |
2453 |
|
bits = dimreg->VelocityTable[DimValues[veldim]]; |
2454 |
|
else // normal split type |
2455 |
|
bits = uint8_t(DimValues[veldim] / pDimensionDefinitions[veldim].zone_size); |
2456 |
|
|
2457 |
|
dimregidx |= bits << velbitpos; |
2458 |
|
dimreg = pDimensionRegions[dimregidx]; |
2459 |
|
} |
2460 |
|
return dimreg; |
2461 |
} |
} |
2462 |
|
|
2463 |
/** |
/** |
2681 |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
2682 |
} |
} |
2683 |
|
|
|
File::~File() { |
|
|
// free extension files |
|
|
for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++) |
|
|
delete *i; |
|
|
} |
|
|
|
|
2684 |
Sample* File::GetFirstSample(progress_t* pProgress) { |
Sample* File::GetFirstSample(progress_t* pProgress) { |
2685 |
if (!pSamples) LoadSamples(pProgress); |
if (!pSamples) LoadSamples(pProgress); |
2686 |
if (!pSamples) return NULL; |
if (!pSamples) return NULL; |