7 Commits
Author SHA1 Message Date
Jakub Stasiak 8dd9dff5dd Drop Chunk::from_wav_buffer(), it's unsound
Mix_QuickLoad_WAV performs buffer traversal assuming we passed it enough
data. This is not necessarily true and protecting against it would
duplicate some of the Mix_QuickLoad_WAV logic here. As this is less
useful than from_raw_buffer() let's drop it for now.
2020-03-05 20:10:50 +01:00
Jakub Stasiak 9dde795e3f 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.
2020-02-07 00:39:07 +01:00
Jakub Stasiak fd9813a690 Provide AudioFormatNum.SILENCE constant
With the current callback function signatures it'll be both easier to
use than AudioSpec.silence and it's correct in all cases.

Closes issue #934.
2019-11-01 11:55:24 +01:00
Jakub Stasiak ca33a65fa0 Remove an unused AudioFormatNum::zero() method 2019-10-25 10:33:02 +02:00
Jakub Stasiak c73811603b Always download SDL releases using HTTPS 2019-10-25 10:13:40 +02:00
Jakub Stasiak ca6bfb1224 Try to guide AudioDevice users towards the lock method
It took me a while to figure out how to update the callback data, maybe
this will help someone.
2019-10-24 23:12:35 +02:00
Jakub Stasiak 4e37c1b789 Fix clicking and volume control in the audio-wav example 2019-10-23 02:53:28 +02:00