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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ericoporto
Copy link
Contributor

fix #92

alternative to #95.

@sezero sezero requested a review from icculus March 5, 2024 00:19
@sezero
Copy link
Collaborator

sezero commented Mar 5, 2024

CC: @Wohlstand

@icculus
Copy link
Owner

icculus commented Mar 5, 2024

I'm fine with this; if no one has an objection (@Wohlstand?), let's merge it.

@icculus
Copy link
Owner

icculus commented Mar 5, 2024

We should also probably point Sean Barrett at this if it's useful in a general sense to stb_vorbis.

@sezero
Copy link
Collaborator

sezero commented Mar 5, 2024

We should also probably point Sean Barrett at this if it's useful in a general sense to stb_vorbis.

stb_vorbis_stream_length_in_samples is a PR in stb_vorbis not yet merged. Only thing that can be done with mainstream is that maybe @Wohlstand can amend this to his PR if the patch is correct.

@ericoporto
Copy link
Contributor Author

stb_vorbis_stream_length_in_samples is a PR in stb_vorbis not yet merged

Just for reference, it actually is in other PR that depends on the mentioned PR being merged.

@sezero
Copy link
Collaborator

sezero commented Mar 6, 2024

To me, this looks fine -- still waiting @Wohlstand to make a comment.

I guess the same change is needed in stb_vorbis_get_samples_float() and stb_vorbis_get_samples_short*(), no? (Haven't tested..) I'm willing to apply it to my fork after all is cleared (and it will be applied to all users of my fork.)

@Wohlstand
Copy link

Hello!
I'm not at home yet, yesterday I was very busy, I'll reply as soon as I'll get my home.

@ericoporto
Copy link
Contributor Author

I guess the same change is needed in stb_vorbis_get_samples_float() and stb_vorbis_get_samples_short*(), no? (Haven't tested..) I'm willing to apply it to my fork after all is cleared (and it will be applied to all users of my fork.)

I don't have an audio file that causes an issue with those for me to test, would have to come up with something in Audacity for this, the one in the issue was from the user of ags that noticed the issue and reported.

@Wohlstand
Copy link

To me, this looks fine -- still waiting @Wohlstand to make a comment.

I guess the same change is needed in stb_vorbis_get_samples_float() and stb_vorbis_get_samples_short*(), no? (Haven't tested..) I'm willing to apply it to my fork after all is cleared (and it will be applied to all users of my fork.)

Yea, I took a small look, and ye, as you said, the change is needed not just in one interleaved function: this problem exists in all other functions too. Mainstream Mixer as well as my MixerX fork doesn't use interleaved function (except of my experimental "turn into multi-track" feature to interpret extra channels as stereo/mono/etc. concurrent tracks with ability to mute each of them), and I guess, somebody reported this problem at the Mixer too, or I confuse some 🤔

@Wohlstand
Copy link

Also, pay attention that stb_vorbis_stream_length_in_samples function may return the SAMPLE_unknown (which is -1), or 0 (when any error ocurrs), so, be careful!

src/stb_vorbis.h Outdated
@@ -5656,6 +5657,11 @@ int stb_vorbis_get_samples_float_interleaved(stb_vorbis *f, int channels, float
break;
}
f->current_playback_loc += n;
if(f->current_playback_loc > lgs) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check for the lgs >= 0, otherwise, it may return 0 (on any error) or -1 when it has an invalid duration value.

Copy link
Contributor Author

@ericoporto ericoporto Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a && lgs >= 0 check as requested.

Copy link
Contributor Author

@ericoporto ericoporto Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait a minute, the return value should be positive as is an unsigned int, how could it be -1?

Dropping the previously added commit until a better rationality exists...

Copy link
Contributor Author

@ericoporto ericoporto Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the code and "-1 when it has an invalid duration value" doesn't exist, it can only be 0. Using lgs > 0 instead.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It CAN return -1, because of:

#define SAMPLE_unknown  0xffffffff

when it's a signed 32-bit integer, it's -1.

Copy link

@Wohlstand Wohlstand Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my end of the fork, I already replaced all the offsets from int into int64_t to match the mainstream Vorbis (otherwise it won't allow play large files, longer than 5 hours, and also depending on the sample rate), and the value of SAMPLE_unknown I simply replaced with -1: simple and easy.: https://github.com/WohlSoft/SDL-Mixer-X/blob/master/src/codecs/stb_vorbis/stb_vorbis.h

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SAMPLE_unknown

Why not to just use the SAMPLE_unknown value directly?

Copy link
Contributor Author

@ericoporto ericoporto Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your code there is a mix of int64_t and uint64_t, shouldn't it be all uint64_t ? I felt that it would be easier to match the eventual 64-bit upgrade by using an existent constant instead of the current manual 0xf...f.

I have a feeling there should be an existing type for this instead like size_t. If one doesn't exist, it should be typedef to ensure it all matches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, I won't change anything right now because GitHub PR is melting: https://www.githubstatus.com/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears GitHub is normalizing

@ericoporto ericoporto force-pushed the fix-stb-vorbis-interleaved branch 2 times, most recently from 91f1206 to fef554e Compare March 7, 2024 12:04
src/stb_vorbis.h Outdated
@@ -5656,6 +5657,11 @@ int stb_vorbis_get_samples_float_interleaved(stb_vorbis *f, int channels, float
break;
}
f->current_playback_loc += n;
if(f->current_playback_loc > lgs && lgs > 0 && lgs != UINT_MAX) {
Copy link

@Wohlstand Wohlstand Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to just use the SAMPLE_unknown directly? It's private code, and you are free to use that here.

if(f->current_playback_loc > lgs && lgs > 0 && lgs != SAMPLE_unknown) {

Copy link
Contributor Author

@ericoporto ericoporto Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted as request : https://github.com/icculus/SDL_sound/compare/fef554e25e79aef3dd24fa964e219f9a5b20a309..945fbbe3a09dd1ae043c2a6b02c9e622cd24f346

I stand-by what I said that stb_vorbis using ints directly is terrible and it should use size_t and SIZE_MAX instead or any other regular c type that is appropriate or typedef things to make sense instead of using naked int/uint mixed around...

I think in the end I would prefer if SDL_sound gave me an options to use external Xiph libraries instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decoding a particular OGG file appends a bit of silence at the end
4 participants