From 68597535fa416931044d62cd86603526362eb1ce Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 4 Jul 2024 18:32:54 -0500 Subject: [PATCH] XM import: fix 16-bit sample loop --- src/engine/fileOps/xm.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/engine/fileOps/xm.cpp b/src/engine/fileOps/xm.cpp index f4474add5..45fb30c6d 100644 --- a/src/engine/fileOps/xm.cpp +++ b/src/engine/fileOps/xm.cpp @@ -555,12 +555,6 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) { s->loopStart=reader.readI(); s->loopEnd=reader.readI()+s->loopStart; - if (s->loopStart>s->loopEnd) { - s->loopStart^=s->loopEnd; - s->loopEnd^=s->loopStart; - s->loopStart^=s->loopEnd; - } - sampleVol[i][j]=reader.readC(); signed char fine=reader.readC(); @@ -582,6 +576,18 @@ bool DivEngine::loadXM(unsigned char* file, size_t len) { break; } + if (s->loopStart>s->loopEnd) { + s->loopStart^=s->loopEnd; + s->loopEnd^=s->loopStart; + s->loopStart^=s->loopEnd; + } + + if (flags&16) { + s->loopStart>>=1; + s->loopEnd>>=1; + } + + reader.readC(); // reserved s->centerRate=8363.0*pow(2.0,((double)note+((double)fine/128.0))/12.0);