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) { |
232 |
unsigned int Sample::Instances = 0; |
unsigned int Sample::Instances = 0; |
233 |
buffer_t Sample::InternalDecompressionBuffer; |
buffer_t Sample::InternalDecompressionBuffer; |
234 |
|
|
235 |
Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
236 |
Instances++; |
Instances++; |
237 |
|
FileNo = fileNo; |
238 |
|
|
239 |
RIFF::Chunk* _3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
RIFF::Chunk* _3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
240 |
if (!_3gix) throw gig::Exception("Mandatory chunks in <wave> list chunk not found."); |
if (!_3gix) throw gig::Exception("Mandatory chunks in <wave> list chunk not found."); |
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 |
1153 |
VCFType = vcf_type_lowpassturbo; |
VCFType = vcf_type_lowpassturbo; |
1154 |
} |
} |
1155 |
|
|
1156 |
// get the corresponding velocity->volume table from the table map or create & calculate that table if it doesn't exist yet |
pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, |
1157 |
uint32_t tableKey = (VelocityResponseCurve<<16) | (VelocityResponseDepth<<8) | VelocityResponseCurveScaling; |
VelocityResponseDepth, |
1158 |
|
VelocityResponseCurveScaling); |
1159 |
|
|
1160 |
|
curve_type_t curveType = ReleaseVelocityResponseCurve; |
1161 |
|
uint8_t depth = ReleaseVelocityResponseDepth; |
1162 |
|
|
1163 |
|
// this models a strange behaviour or bug in GSt: two of the |
1164 |
|
// velocity response curves for release time are not used even |
1165 |
|
// if specified, instead another curve is chosen. |
1166 |
|
if ((curveType == curve_type_nonlinear && depth == 0) || |
1167 |
|
(curveType == curve_type_special && depth == 4)) { |
1168 |
|
curveType = curve_type_nonlinear; |
1169 |
|
depth = 3; |
1170 |
|
} |
1171 |
|
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)); |
1188 |
|
} |
1189 |
|
|
1190 |
|
// get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet |
1191 |
|
double* DimensionRegion::GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) |
1192 |
|
{ |
1193 |
|
double* table; |
1194 |
|
uint32_t tableKey = (curveType<<16) | (depth<<8) | scaling; |
1195 |
if (pVelocityTables->count(tableKey)) { // if key exists |
if (pVelocityTables->count(tableKey)) { // if key exists |
1196 |
pVelocityAttenuationTable = (*pVelocityTables)[tableKey]; |
table = (*pVelocityTables)[tableKey]; |
1197 |
} |
} |
1198 |
else { |
else { |
1199 |
pVelocityAttenuationTable = |
table = CreateVelocityTable(curveType, depth, scaling); |
1200 |
CreateVelocityTable(VelocityResponseCurve, |
(*pVelocityTables)[tableKey] = table; // put the new table into the tables map |
|
VelocityResponseDepth, |
|
|
VelocityResponseCurveScaling); |
|
|
(*pVelocityTables)[tableKey] = pVelocityAttenuationTable; // put the new table into the tables map |
|
1201 |
} |
} |
1202 |
|
return table; |
|
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
|
1203 |
} |
} |
1204 |
|
|
1205 |
leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) { |
leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) { |
1350 |
return pVelocityAttenuationTable[MIDIKeyVelocity]; |
return pVelocityAttenuationTable[MIDIKeyVelocity]; |
1351 |
} |
} |
1352 |
|
|
1353 |
|
double DimensionRegion::GetVelocityRelease(uint8_t MIDIKeyVelocity) { |
1354 |
|
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 |
|
|
1626 |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
if ((int32_t)WavePoolTableIndex == -1) return NULL; |
1627 |
File* file = (File*) GetParent()->GetParent(); |
File* file = (File*) GetParent()->GetParent(); |
1628 |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex]; |
1629 |
|
unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex]; |
1630 |
Sample* sample = file->GetFirstSample(pProgress); |
Sample* sample = file->GetFirstSample(pProgress); |
1631 |
while (sample) { |
while (sample) { |
1632 |
if (sample->ulWavePoolOffset == soughtoffset) return static_cast<gig::Sample*>(pSample = sample); |
if (sample->ulWavePoolOffset == soughtoffset && |
1633 |
|
sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(pSample = sample); |
1634 |
sample = file->GetNextSample(); |
sample = file->GetNextSample(); |
1635 |
} |
} |
1636 |
return NULL; |
return NULL; |
1773 |
pInstruments->clear(); |
pInstruments->clear(); |
1774 |
delete pInstruments; |
delete pInstruments; |
1775 |
} |
} |
1776 |
|
// free extension files |
1777 |
|
for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++) |
1778 |
|
delete *i; |
1779 |
} |
} |
1780 |
|
|
1781 |
Sample* File::GetFirstSample(progress_t* pProgress) { |
Sample* File::GetFirstSample(progress_t* pProgress) { |
1792 |
} |
} |
1793 |
|
|
1794 |
void File::LoadSamples(progress_t* pProgress) { |
void File::LoadSamples(progress_t* pProgress) { |
1795 |
RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL); |
RIFF::File* file = pRIFF; |
|
if (wvpl) { |
|
|
// just for progress calculation |
|
|
int iSampleIndex = 0; |
|
|
int iTotalSamples = wvpl->CountSubLists(LIST_TYPE_WAVE); |
|
|
|
|
|
unsigned long wvplFileOffset = wvpl->GetFilePos(); |
|
|
RIFF::List* wave = wvpl->GetFirstSubList(); |
|
|
while (wave) { |
|
|
if (wave->GetListType() == LIST_TYPE_WAVE) { |
|
|
// notify current progress |
|
|
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
|
|
__notify_progress(pProgress, subprogress); |
|
|
|
|
|
if (!pSamples) pSamples = new SampleList; |
|
|
unsigned long waveFileOffset = wave->GetFilePos(); |
|
|
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset)); |
|
1796 |
|
|
1797 |
iSampleIndex++; |
// just for progress calculation |
1798 |
|
int iSampleIndex = 0; |
1799 |
|
int iTotalSamples = WavePoolCount; |
1800 |
|
|
1801 |
|
// check if samples should be loaded from extension files |
1802 |
|
int lastFileNo = 0; |
1803 |
|
for (int i = 0 ; i < WavePoolCount ; i++) { |
1804 |
|
if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i]; |
1805 |
|
} |
1806 |
|
String name(pRIFF->Filename); |
1807 |
|
int nameLen = pRIFF->Filename.length(); |
1808 |
|
char suffix[6]; |
1809 |
|
if (nameLen > 4 && pRIFF->Filename.substr(nameLen - 4) == ".gig") nameLen -= 4; |
1810 |
|
|
1811 |
|
for (int fileNo = 0 ; ; ) { |
1812 |
|
RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL); |
1813 |
|
if (wvpl) { |
1814 |
|
unsigned long wvplFileOffset = wvpl->GetFilePos(); |
1815 |
|
RIFF::List* wave = wvpl->GetFirstSubList(); |
1816 |
|
while (wave) { |
1817 |
|
if (wave->GetListType() == LIST_TYPE_WAVE) { |
1818 |
|
// notify current progress |
1819 |
|
const float subprogress = (float) iSampleIndex / (float) iTotalSamples; |
1820 |
|
__notify_progress(pProgress, subprogress); |
1821 |
|
|
1822 |
|
if (!pSamples) pSamples = new SampleList; |
1823 |
|
unsigned long waveFileOffset = wave->GetFilePos(); |
1824 |
|
pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo)); |
1825 |
|
|
1826 |
|
iSampleIndex++; |
1827 |
|
} |
1828 |
|
wave = wvpl->GetNextSubList(); |
1829 |
} |
} |
1830 |
wave = wvpl->GetNextSubList(); |
|
1831 |
|
if (fileNo == lastFileNo) break; |
1832 |
|
|
1833 |
|
// open extension file (*.gx01, *.gx02, ...) |
1834 |
|
fileNo++; |
1835 |
|
sprintf(suffix, ".gx%02d", fileNo); |
1836 |
|
name.replace(nameLen, 5, suffix); |
1837 |
|
file = new RIFF::File(name); |
1838 |
|
ExtensionFiles.push_back(file); |
1839 |
} |
} |
1840 |
__notify_progress(pProgress, 1.0); // notify done |
else throw gig::Exception("Mandatory <wvpl> chunk not found."); |
1841 |
} |
} |
1842 |
else throw gig::Exception("Mandatory <wvpl> chunk not found."); |
|
1843 |
|
__notify_progress(pProgress, 1.0); // notify done |
1844 |
} |
} |
1845 |
|
|
1846 |
Instrument* File::GetFirstInstrument() { |
Instrument* File::GetFirstInstrument() { |