Skip to content

Commit

Permalink
resample.c (rs_plain): Bug fixed about PRECALC_LOOPS counter.
Browse files Browse the repository at this point in the history
Original form: i = (le - ofs) / incr + 1;           (Original)
Fixed form:    i = (le - ofs + incr - 1) / incr;    (Correct)
[ from timidity++ v2.7.0-to-v2.8.0 diff, 1999-11-19  Masanao Izumo <mo@goice.co.jp> ]
  • Loading branch information
sezero committed Oct 21, 2017
1 parent e141c9b commit 80f3924
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions timidity/resample.c
Expand Up @@ -27,6 +27,8 @@
#include "tables.h"
#include "resample.h"

#define PRECALC_LOOP_COUNT(start, end, incr) (((end) - (start) + (incr) - 1) / (incr))

/*************** resampling with fixed increment *****************/

static sample_t *rs_plain(MidiSong *song, int v, Sint32 *countptr)
Expand All @@ -51,7 +53,7 @@ static sample_t *rs_plain(MidiSong *song, int v, Sint32 *countptr)

/* Precalc how many times we should go through the loop.
NOTE: Assumes that incr > 0 and that ofs <= le */
i = (le - ofs) / incr + 1;
i = PRECALC_LOOP_COUNT(ofs, le, incr);

if (i > count)
{
Expand Down Expand Up @@ -101,7 +103,7 @@ static sample_t *rs_loop(MidiSong *song, Voice *vp, Sint32 count)
while (ofs >= le)
ofs -= ll;
/* Precalc how many times we should go through the loop */
i = (le - ofs) / incr + 1;
i = PRECALC_LOOP_COUNT(ofs, le, incr);
if (i > count)
{
i = count;
Expand Down Expand Up @@ -138,12 +140,12 @@ static sample_t *rs_bidir(MidiSong *song, Voice *vp, Sint32 count)
i;
/* Play normally until inside the loop region */

if (ofs <= ls)
if (incr > 0 && ofs < ls)
{
/* NOTE: Assumes that incr > 0, which is NOT always the case
when doing bidirectional looping. I have yet to see a case
where both ofs <= ls AND incr < 0, however. */
i = (ls - ofs) / incr + 1;
i = PRECALC_LOOP_COUNT(ofs, ls, incr);
if (i > count)
{
i = count;
Expand All @@ -164,7 +166,7 @@ static sample_t *rs_bidir(MidiSong *song, Voice *vp, Sint32 count)
while(count)
{
/* Precalc how many times we should go through the loop */
i = ((incr > 0 ? le : ls) - ofs) / incr + 1;
i = PRECALC_LOOP_COUNT(ofs, incr > 0 ? le : ls, incr);
if (i > count)
{
i = count;
Expand Down Expand Up @@ -349,7 +351,7 @@ static sample_t *rs_vib_loop(MidiSong *song, Voice *vp, Sint32 count)
ofs -= ll;
/* Precalc how many times to go through the loop, taking
the vibrato control ratio into account this time. */
i = (le - ofs) / incr + 1;
i = PRECALC_LOOP_COUNT(ofs, le, incr);
if(i > count) i = count;
if(i > cc)
{
Expand Down Expand Up @@ -400,9 +402,9 @@ static sample_t *rs_vib_bidir(MidiSong *song, Voice *vp, Sint32 count)
vibflag = 0;

/* Play normally until inside the loop region */
while (count && (ofs <= ls))
while (count && incr > 0 && ofs < ls)
{
i = (ls - ofs) / incr + 1;
i = PRECALC_LOOP_COUNT(ofs, ls, incr);
if (i > count) i = count;
if (i > cc)
{
Expand Down Expand Up @@ -431,7 +433,7 @@ static sample_t *rs_vib_bidir(MidiSong *song, Voice *vp, Sint32 count)
while (count)
{
/* Precalc how many times we should go through the loop */
i = ((incr > 0 ? le : ls) - ofs) / incr + 1;
i = PRECALC_LOOP_COUNT(ofs, incr > 0 ? le : ls, incr);
if(i > count) i = count;
if(i > cc)
{
Expand Down

0 comments on commit 80f3924

Please sign in to comment.