Skip to content

Commit

Permalink
stb_vorbis: fix interleaved appends silence at end
Browse files Browse the repository at this point in the history
Co-Authored-By: Ozkan Sezer <[email protected]>
  • Loading branch information
2 people authored and icculus committed Jan 12, 2025
1 parent 16e6265 commit 474dbf7
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/stb_vorbis.h
Original file line number Diff line number Diff line change
Expand Up @@ -5512,6 +5512,21 @@ int stb_vorbis_get_frame_short_interleaved(stb_vorbis *f, int num_c, short *buff
return len;
}

static int fixup_current_playback_loc(stb_vorbis *f, int n)
{
unsigned int lgs;

f->current_playback_loc += n;
lgs = stb_vorbis_stream_length_in_samples(f);
if (f->current_playback_loc > lgs && lgs > 0 && lgs != SAMPLE_unknown) {
int r = n - (f->current_playback_loc - (int)lgs);
f->current_playback_loc = lgs;
return r;
}

return n;
}

int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short *buffer, int num_shorts)
{
float **outputs;
Expand All @@ -5528,8 +5543,7 @@ int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short
if (n == len) break;
if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) break;
}
f->current_playback_loc += n;
return n;
return fixup_current_playback_loc(f, n);
}

int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, int len)
Expand All @@ -5546,8 +5560,7 @@ int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, in
if (n == len) break;
if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) break;
}
f->current_playback_loc += n;
return n;
return fixup_current_playback_loc(f, n);
}

#ifndef STB_VORBIS_NO_STDIO
Expand Down Expand Up @@ -5655,8 +5668,7 @@ int stb_vorbis_get_samples_float_interleaved(stb_vorbis *f, int channels, float
if (!stb_vorbis_get_frame_float(f, NULL, &outputs))
break;
}
f->current_playback_loc += n;
return n;
return fixup_current_playback_loc(f, n);
}

int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, int num_samples)
Expand All @@ -5682,8 +5694,7 @@ int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, in
if (!stb_vorbis_get_frame_float(f, NULL, &outputs))
break;
}
f->current_playback_loc += n;
return n;
return fixup_current_playback_loc(f, n);
}
#endif // STB_VORBIS_NO_PULLDATA_API

Expand Down

0 comments on commit 474dbf7

Please sign in to comment.