Skip to content

Add loop callback to sfSoundStream - #422

Merged
eXpl0it3r merged 1 commit into
masterfrom
feature/sound-stream-loop
Nov 7, 2026
Merged

eXpl0it3r merged 1 commit into
masterfrom
feature/sound-stream-loop

Conversation

@eXpl0it3r

@eXpl0it3r eXpl0it3r commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

sf::SoundStream::onLoop couldn't be overridden from CSFML so far. Like onGetData and onSeek, it's now an optional callback passed to sfSoundStream_create, which keeps it consistent with sfSoundRecorder_create and avoids changing callbacks while the audio thread is running. If it's NULL, SFML's default behavior is used, i.e. seek to the beginning and continue from sample 0.

Additionally, sfSoundStreamChunk now uses the same types as sf::SoundStream::Chunk, a test checks the layout.

This replaces #397 with the approach discussed there. As sf::Music isn't really meant to be extended, sfMusic doesn't get overrides, custom streaming can be built on top of sfSoundStream instead. Thanks to @Marioalexsan for the initial work, the chunk changes are taken from #397.

Note that this breaks the API:

  • sfSoundStream_create takes a new onLoop parameter after onSeek
  • sfSoundStreamChunk::samples is const int16_t* and sfSoundStreamChunk::sampleCount is size_t

Returning false from the loop callback doesn't stop the stream, same as returning std::nullopt in SFML, see SFML/SFML#3777.

Closes #394

How to test this PR?

CI should succeed.

Create a looping sfSoundStream with a loop callback and check that it gets called whenever the stream reaches its end.

- Add an optional onLoop callback to sfSoundStream_create
- Use the same types for sfSoundStreamChunk as sf::SoundStream::Chunk

Co-authored-by: Miron Alexandru <mironalex@hotmail.com>
@eXpl0it3r
eXpl0it3r force-pushed the feature/sound-stream-loop branch from d4537a2 to 5cea0cc Compare November 7, 2026 15:49
@eXpl0it3r
eXpl0it3r merged commit f5f2629 into master Nov 7, 2026
62 checks passed
@eXpl0it3r
eXpl0it3r deleted the feature/sound-stream-loop branch November 7, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Protected SFML Methods cannot be consumed by CSFML consumers

1 participant