-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide memory buffer -> mixer Chunk conversion methods
This basically provides an API to access Mix_QuickLoad_WAV and Mix_QuickLoad_RAW with one caveat – thie API takes ownership of the buffers, while Mix_QuickLoad_* functions don't. Since Rust-SDL2 wraps Mix_Chunks in its own structure with its own buffer ownership flag it's easy to work around that and deallocate the buffer when Chunk is dropped. There are few design considerations here: * Taking ownership of the buffer. I couldn't come up with a way to get a Chunk based on a buffer while still keeping the code safe and making sure that as long as Chunk is alive the buffer is also alive *and* not making the change be terribly involved and disruptive * What's the best way to take an ownership of a buffer passed as a parameter? I came up with Box<[T]> as it seems universal enough, but I expect a more idiomatic Rust way may exist. I modified the mixer demo to show how the API is used, a beep is generated when no sound file is passed to the example.
- Loading branch information
Showing
2 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters