From: <sv...@op...> - 2024-08-29 22:03:15
|
Author: sagamusix Date: Thu Aug 29 21:33:57 2024 New Revision: 21536 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=21536 Log: Merged revision(s) 21535 from trunk/OpenMPT: [Fix] SFZ: Reallocate sample data if it was trimmed excessively by "offset" and "end" opcodes. This is crucial for SFZs like those generated by Sforzando's SF2 conversion process, as the whole SF2 sample data chunk ends up in a single WAV file that is then referenced by each region and sliced accordingly. Note that such files still take an excessively long amount of time to load if the original SF2 was huge and instruments contained many regions, but at least you no longer run out of memory when doing so. ........ Modified: branches/OpenMPT-1.31/ (props changed) branches/OpenMPT-1.31/soundlib/SampleFormatSFZ.cpp Modified: branches/OpenMPT-1.31/soundlib/SampleFormatSFZ.cpp ============================================================================== --- branches/OpenMPT-1.31/soundlib/SampleFormatSFZ.cpp Thu Aug 29 21:33:38 2024 (r21535) +++ branches/OpenMPT-1.31/soundlib/SampleFormatSFZ.cpp Thu Aug 29 21:33:57 2024 (r21536) @@ -988,6 +988,8 @@ filenameModifier += P_(" (cross-fade)"); } + const SmpLength origSampleLength = sample.nLength; + // Sample offset if(region.offset && region.offset < sample.nLength) { @@ -1003,6 +1005,19 @@ } LimitMax(sample.nLength, region.end); + if(sample.nLength < origSampleLength && (origSampleLength - sample.nLength) >= 128 * 1024) + { + // If the sample was trimmed excessively, re-allocate to save memory. + // This is crucial for SFZs like those generated by Sforzando's SF2 conversion process, + // as the whole SF2 sample data chunk ends up in a single WAV file that is then referenced by each region and sliced accordingly. + if(auto newData = ModSample::AllocateSample(sample.nLength, sample.GetBytesPerSample())) + { + memcpy(newData, sample.samplev(), sample.nLength * sample.GetBytesPerSample()); + sample.FreeSample(); + sample.pData.pSample = newData; + } + } + if(region.invertPhase) { ctrlSmp::InvertSample(sample, 0, sample.nLength, *this); |