Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stb_vorbis: fix interleaved appends silence at end #97

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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