From: <sv...@op...> - 2024-08-29 22:03:10
|
Author: sagamusix Date: Thu Aug 29 21:33:38 2024 New Revision: 21535 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=21535 Log: [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: trunk/OpenMPT/soundlib/SampleFormatSFZ.cpp Modified: trunk/OpenMPT/soundlib/SampleFormatSFZ.cpp ============================================================================== --- trunk/OpenMPT/soundlib/SampleFormatSFZ.cpp Thu Aug 29 17:44:00 2024 (r21534) +++ trunk/OpenMPT/soundlib/SampleFormatSFZ.cpp Thu Aug 29 21:33:38 2024 (r21535) @@ -997,6 +997,8 @@ filenameModifier += P_(" (cross-fade)"); } + const SmpLength origSampleLength = sample.nLength; + // Sample offset if(region.offset && region.offset < sample.nLength) { @@ -1012,6 +1014,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); |