Skip to content

Fix wav decoder streaming indefinitely#217

Open
pohy wants to merge 1 commit intogopxl:mainfrom
pohy:main
Open

Fix wav decoder streaming indefinitely#217
pohy wants to merge 1 commit intogopxl:mainfrom
pohy:main

Conversation

@pohy
Copy link
Copy Markdown

@pohy pohy commented Nov 26, 2025

This was happening for very short audio files

This was happening for very short audio files
Copy link
Copy Markdown
Contributor

@MarkKremer MarkKremer left a comment

Choose a reason for hiding this comment

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

Nice catch and thank you for the PR!

I have one question.

Comment on lines +220 to +223
if err == io.EOF {
d.pos = d.h.DataSize
return 0, false
}
Copy link
Copy Markdown
Contributor

@MarkKremer MarkKremer Dec 3, 2025

Choose a reason for hiding this comment

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

How do you feel about not setting the position to the end? I think it might be slightly more "correct" if s.Position() reported the position the streamer has actually read to even though it doesn't match s.Len().

One thing I want to make sure of is that the reader may return some samples and an io.EOF at the same time. Therefore, it's better to not early return and instead, parse all the samples and return false at the end. Otherwise we may miss some samples. From the io.Reader docs:

When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read. It may return the (non-nil) error from the same call or return the error (and n == 0) from a subsequent call.

This is different from how beep.Streamer works. We only return !ok if n == 0. We can easily fix this by making this change at the end of the function instead of the early return:

- return n / bytesPerFrame, true
+ return n / bytesPerFrame, n > 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can accept the PR and make the change for you if you want. Just curious if you have a reason for doing it this way.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That actually sounds more correct.
Honestly, I was just trying to fix my problem quickly. 😅

On the other hand, I am using the streamer's position to determine whether it has finished or not.
If the position remains in an "unfinished state", I'd have to use an extra bool set from beep.Callback to track whether the streamer has finished. Not a big issue, but doesn't feel as elegant.

I agree with ensuring all samples are streamed.
How about checking for EOF just before the "final" return?

if err == io.EOF {
	d.pos = d.h.DataSize
}
return n / bytesPerFrame, n > 0

I can push the changes as well.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return n / bytesPerFrame, true

  • return n / bytesPerFrame, n >

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return n / bytesPerFrame, true

  • return n / bytesPerFrame, n >

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return n / bytesPerFrame, true

  • return n / bytesPerFrame, n >

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Updatable packages: …
Packages version: 0.119.0-beta

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Updatable packages: …
Packages version: 0.119.0-beta

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Updatable packages: …
Packages version: 0.119.0-beta

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Updatable packages: …
Packages version: 0.119.0-beta

@nsarlsalhy334-source
Copy link
Copy Markdown

Screenshot_٢٠٢٥١٢٠٧-٠١٠٤٠٠_NHLauncher.jpg

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.

3 participants