132 |
{ |
{ |
133 |
// Note: The 24 bits are truncated to 16 bits for now. |
// Note: The 24 bits are truncated to 16 bits for now. |
134 |
|
|
135 |
// Note: The calculation of the initial value of y is strange |
int y, dy, ddy, dddy; |
|
// and not 100% correct. What should the first two parameters |
|
|
// really be used for? Why are they two? The correct value for |
|
|
// y seems to lie somewhere between the values of the first |
|
|
// two parameters. |
|
|
// |
|
|
// Strange thing #2: The formula in SKIP_ONE gives values for |
|
|
// y that are twice as high as they should be. That's why |
|
|
// COPY_ONE shifts an extra step, and also why y is |
|
|
// initialized with a sum instead of a mean value. |
|
|
|
|
|
int y, dy, ddy; |
|
|
|
|
136 |
const int shift = 8 - truncatedBits; |
const int shift = 8 - truncatedBits; |
|
const int shift1 = shift + 1; |
|
137 |
|
|
138 |
#define GET_PARAMS(params) \ |
#define GET_PARAMS(params) \ |
139 |
y = (get24(params) + get24((params) + 3)); \ |
y = get24(params); \ |
140 |
dy = get24((params) + 6); \ |
dy = y - get24((params) + 3); \ |
141 |
ddy = get24((params) + 9) |
ddy = get24((params) + 6); \ |
142 |
|
dddy = get24((params) + 9) |
143 |
|
|
144 |
#define SKIP_ONE(x) \ |
#define SKIP_ONE(x) \ |
145 |
ddy -= (x); \ |
dddy -= (x); \ |
146 |
dy -= ddy; \ |
ddy -= dddy; \ |
147 |
y -= dy |
dy = -dy - ddy; \ |
148 |
|
y += dy |
149 |
|
|
150 |
#define COPY_ONE(x) \ |
#define COPY_ONE(x) \ |
151 |
SKIP_ONE(x); \ |
SKIP_ONE(x); \ |
152 |
*pDst = y >> shift1; \ |
*pDst = y >> shift; \ |
153 |
pDst += dstStep |
pDst += dstStep |
154 |
|
|
155 |
switch (compressionmode) { |
switch (compressionmode) { |
1134 |
VCFEnabled = vcfcutoff & 0x80; // bit 7 |
VCFEnabled = vcfcutoff & 0x80; // bit 7 |
1135 |
VCFCutoff = vcfcutoff & 0x7f; // lower 7 bits |
VCFCutoff = vcfcutoff & 0x7f; // lower 7 bits |
1136 |
VCFCutoffController = static_cast<vcf_cutoff_ctrl_t>(_3ewa->ReadUint8()); |
VCFCutoffController = static_cast<vcf_cutoff_ctrl_t>(_3ewa->ReadUint8()); |
1137 |
VCFVelocityScale = _3ewa->ReadUint8(); |
uint8_t vcfvelscale = _3ewa->ReadUint8(); |
1138 |
|
VCFCutoffControllerInvert = vcfvelscale & 0x80; // bit 7 |
1139 |
|
VCFVelocityScale = vcfvelscale & 0x7f; // lower 7 bits |
1140 |
_3ewa->ReadInt8(); // unknown |
_3ewa->ReadInt8(); // unknown |
1141 |
uint8_t vcfresonance = _3ewa->ReadUint8(); |
uint8_t vcfresonance = _3ewa->ReadUint8(); |
1142 |
VCFResonance = vcfresonance & 0x7f; // lower 7 bits |
VCFResonance = vcfresonance & 0x7f; // lower 7 bits |
1163 |
// this models a strange behaviour or bug in GSt: two of the |
// this models a strange behaviour or bug in GSt: two of the |
1164 |
// velocity response curves for release time are not used even |
// velocity response curves for release time are not used even |
1165 |
// if specified, instead another curve is chosen. |
// if specified, instead another curve is chosen. |
|
|
|
1166 |
if ((curveType == curve_type_nonlinear && depth == 0) || |
if ((curveType == curve_type_nonlinear && depth == 0) || |
1167 |
(curveType == curve_type_special && depth == 4)) { |
(curveType == curve_type_special && depth == 4)) { |
1168 |
curveType = curve_type_nonlinear; |
curveType = curve_type_nonlinear; |
1170 |
} |
} |
1171 |
pVelocityReleaseTable = GetVelocityTable(curveType, depth, 0); |
pVelocityReleaseTable = GetVelocityTable(curveType, depth, 0); |
1172 |
|
|
1173 |
|
curveType = VCFVelocityCurve; |
1174 |
|
depth = VCFVelocityDynamicRange; |
1175 |
|
|
1176 |
|
// even stranger GSt: two of the velocity response curves for |
1177 |
|
// filter cutoff are not used, instead another special curve |
1178 |
|
// is chosen. This curve is not used anywhere else. |
1179 |
|
if ((curveType == curve_type_nonlinear && depth == 0) || |
1180 |
|
(curveType == curve_type_special && depth == 4)) { |
1181 |
|
curveType = curve_type_special; |
1182 |
|
depth = 5; |
1183 |
|
} |
1184 |
|
pVelocityCutoffTable = GetVelocityTable(curveType, depth, |
1185 |
|
VCFCutoffController <= vcf_cutoff_ctrl_none2 ? VCFVelocityScale : 0); |
1186 |
|
|
1187 |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
1188 |
} |
} |
1189 |
|
|
1354 |
return pVelocityReleaseTable[MIDIKeyVelocity]; |
return pVelocityReleaseTable[MIDIKeyVelocity]; |
1355 |
} |
} |
1356 |
|
|
1357 |
|
double DimensionRegion::GetVelocityCutoff(uint8_t MIDIKeyVelocity) { |
1358 |
|
return pVelocityCutoffTable[MIDIKeyVelocity]; |
1359 |
|
} |
1360 |
|
|
1361 |
double* DimensionRegion::CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) { |
double* DimensionRegion::CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) { |
1362 |
|
|
1363 |
// line-segment approximations of the 15 velocity curves |
// line-segment approximations of the 15 velocity curves |
1391 |
const int spe4[] = { 1, 4, 23, 5, 49, 13, 57, 17, 92, 57, 122, 127, |
const int spe4[] = { 1, 4, 23, 5, 49, 13, 57, 17, 92, 57, 122, 127, |
1392 |
127, 127 }; |
127, 127 }; |
1393 |
|
|
1394 |
|
// this is only used by the VCF velocity curve |
1395 |
|
const int spe5[] = { 1, 2, 30, 5, 60, 19, 77, 70, 83, 85, 88, 106, |
1396 |
|
91, 127, 127, 127 }; |
1397 |
|
|
1398 |
const int* const curves[] = { non0, non1, non2, non3, non4, |
const int* const curves[] = { non0, non1, non2, non3, non4, |
1399 |
lin0, lin1, lin2, lin3, lin4, |
lin0, lin1, lin2, lin3, lin4, |
1400 |
spe0, spe1, spe2, spe3, spe4 }; |
spe0, spe1, spe2, spe3, spe4, spe5 }; |
1401 |
|
|
1402 |
double* const table = new double[128]; |
double* const table = new double[128]; |
1403 |
|
|
1449 |
for (int i = 0; i < dimensionBits; i++) { |
for (int i = 0; i < dimensionBits; i++) { |
1450 |
dimension_t dimension = static_cast<dimension_t>(_3lnk->ReadUint8()); |
dimension_t dimension = static_cast<dimension_t>(_3lnk->ReadUint8()); |
1451 |
uint8_t bits = _3lnk->ReadUint8(); |
uint8_t bits = _3lnk->ReadUint8(); |
1452 |
|
_3lnk->ReadUint8(); // probably the position of the dimension |
1453 |
|
_3lnk->ReadUint8(); // unknown |
1454 |
|
uint8_t zones = _3lnk->ReadUint8(); // new for v3: number of zones doesn't have to be == pow(2,bits) |
1455 |
if (dimension == dimension_none) { // inactive dimension |
if (dimension == dimension_none) { // inactive dimension |
1456 |
pDimensionDefinitions[i].dimension = dimension_none; |
pDimensionDefinitions[i].dimension = dimension_none; |
1457 |
pDimensionDefinitions[i].bits = 0; |
pDimensionDefinitions[i].bits = 0; |
1463 |
else { // active dimension |
else { // active dimension |
1464 |
pDimensionDefinitions[i].dimension = dimension; |
pDimensionDefinitions[i].dimension = dimension; |
1465 |
pDimensionDefinitions[i].bits = bits; |
pDimensionDefinitions[i].bits = bits; |
1466 |
pDimensionDefinitions[i].zones = 0x01 << bits; // = pow(2,bits) |
pDimensionDefinitions[i].zones = zones ? zones : 0x01 << bits; // = pow(2,bits) |
1467 |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
pDimensionDefinitions[i].split_type = (dimension == dimension_layer || |
1468 |
dimension == dimension_samplechannel || |
dimension == dimension_samplechannel || |
1469 |
dimension == dimension_releasetrigger || |
dimension == dimension_releasetrigger || |
1472 |
: split_type_normal; |
: split_type_normal; |
1473 |
pDimensionDefinitions[i].ranges = NULL; // it's not possible to check velocity dimensions for custom defined ranges at this point |
pDimensionDefinitions[i].ranges = NULL; // it's not possible to check velocity dimensions for custom defined ranges at this point |
1474 |
pDimensionDefinitions[i].zone_size = |
pDimensionDefinitions[i].zone_size = |
1475 |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128 / pDimensionDefinitions[i].zones |
(pDimensionDefinitions[i].split_type == split_type_normal) ? 128.0 / pDimensionDefinitions[i].zones |
1476 |
: 0; |
: 0; |
1477 |
Dimensions++; |
Dimensions++; |
1478 |
|
|
1479 |
// if this is a layer dimension, remember the amount of layers |
// if this is a layer dimension, remember the amount of layers |
1480 |
if (dimension == dimension_layer) Layers = pDimensionDefinitions[i].zones; |
if (dimension == dimension_layer) Layers = pDimensionDefinitions[i].zones; |
1481 |
} |
} |
1482 |
_3lnk->SetPos(6, RIFF::stream_curpos); // jump forward to next dimension definition |
_3lnk->SetPos(3, RIFF::stream_curpos); // jump forward to next dimension definition |
1483 |
} |
} |
1484 |
|
|
1485 |
// check velocity dimension (if there is one) for custom defined zone ranges |
// check velocity dimension (if there is one) for custom defined zone ranges |
1577 |
bits[i] = DimValues[i]; |
bits[i] = DimValues[i]; |
1578 |
switch (pDimensionDefinitions[i].split_type) { |
switch (pDimensionDefinitions[i].split_type) { |
1579 |
case split_type_normal: |
case split_type_normal: |
1580 |
bits[i] /= pDimensionDefinitions[i].zone_size; |
bits[i] = uint8_t(bits[i] / pDimensionDefinitions[i].zone_size); |
1581 |
break; |
break; |
1582 |
case split_type_customvelocity: |
case split_type_customvelocity: |
1583 |
bits[i] = VelocityTable[bits[i]]; |
bits[i] = VelocityTable[bits[i]]; |