Skip to content

Commit

Permalink
Samples may be uncompressed in sf3
Browse files Browse the repository at this point in the history
Fix #201
  • Loading branch information
davy7125 committed Jul 28, 2024
1 parent 600912a commit 7fb4416
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions sources/lib/sf3/sfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7fb4416

Please sign in to comment.