Skip to content

Commit 3b329b8

Browse files
ecoriagEdgar
and
Edgar
authored
fixed: tmpSourceSamplePositionF32P32 jumping to incorrect position causing distorted sound (earlephilhower#539)
Co-authored-by: Edgar <[email protected]>
1 parent c2adbdc commit 3b329b8

File tree

1 file changed

+2
-1
lines changed
  • src/libtinysoundfont

1 file changed

+2
-1
lines changed

src/libtinysoundfont/tsf.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,7 @@ static void tsf_voice_render_fast(tsf* f, struct tsf_voice* v, short* outputBuff
14401440
//double tmpSampleEndDbl = (double)v->sampleEnd, tmpLoopEndDbl = (double)tmpLoopEnd + 1.0;
14411441
//double tmpSourceSamplePosition = v->sourceSamplePosition;
14421442
fixed32p32 tmpSampleEndF32P32 = ((fixed32p32)(region->end)) << 32;
1443+
fixed32p32 tmpLoopStartF32P32 = ((fixed32p32)(tmpLoopStart + 1)) << 32;
14431444
fixed32p32 tmpLoopEndF32P32 = ((fixed32p32)(tmpLoopEnd + 1)) << 32;
14441445
fixed32p32 tmpSourceSamplePositionF32P32 = v->sourceSamplePositionF32P32;
14451446
struct tsf_voice_lowpass tmpLowpass = v->lowpass;
@@ -1513,7 +1514,7 @@ static void tsf_voice_render_fast(tsf* f, struct tsf_voice* v, short* outputBuff
15131514
// Next sample.
15141515
tmpSourceSamplePositionF32P32 += pitchRatioF32P32;
15151516
if (tmpSourceSamplePositionF32P32 >= tmpLoopEndF32P32 && isLooping)
1516-
tmpSourceSamplePositionF32P32 -= (tmpLoopEndF32P32 - tmpLoopStart + (1LL<<32));
1517+
tmpSourceSamplePositionF32P32 -= (tmpLoopEndF32P32 - tmpLoopStartF32P32 + (1LL<<32));
15171518
}
15181519

15191520
if (tmpSourceSamplePositionF32P32 >= tmpSampleEndF32P32 || v->ampenv.segment == TSF_SEGMENT_DONE)

0 commit comments

Comments
 (0)