From 7fb4416bdfb43c458fa58289ce3cb5cb0186f774 Mon Sep 17 00:00:00 2001 From: Davy Date: Sun, 28 Jul 2024 17:09:03 +0200 Subject: [PATCH] Samples may be uncompressed in sf3 Fix #201 --- sources/lib/sf3/sfont.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/sources/lib/sf3/sfont.cpp b/sources/lib/sf3/sfont.cpp index f9b2d2af..cb8826fd 100644 --- a/sources/lib/sf3/sfont.cpp +++ b/sources/lib/sf3/sfont.cpp @@ -848,8 +848,31 @@ void SoundFont::writeSmpl() foreach(Sample* s, samples) { // OGG flag is removed - s->sampletype &= ~0x10; - int len = writeUncompressedSample(s) / 2; // In sample data points (16 bits) + int len = 0; + if (s->sampletype & 0x10) + { + s->sampletype &= ~0x10; + len = writeUncompressedSample(s) / 2; // In sample data points (16 bits) + } + else + { + // The sample is not compressed in the sf3 file + + // Prepare input data + QFile f(path); + if (f.open(QIODevice::ReadOnly)) + { + f.seek(samplePos + s->start * sizeof(short)); + len = s->end - s->start; + short * ibuffer = new short[len]; + f.read((char*)ibuffer, len * sizeof(short)); + f.close(); + + write((char *)ibuffer, len * sizeof(short)); + } + else + fprintf(stderr, "cannot open <%s>\n", qPrintable(f.fileName())); + } s->start = currentSamplePos; currentSamplePos += len;