AngryLawyer/rust-sdl2 — pull request #218 by nukep (2014-11-25 12:27:14+00:00)
Title: Rework the Audio module to use callbacks

I noticed nobody has touched the audio bindings for quite some time (aside from Rust nightly updates).
The bindings seemed _very_ incomplete, so I took some initiative to add to them.

Some problems with the previous audio wrappers:

* I haven't been able to get a program running without it crashing. I'm convinced nobody's actually using them.
* The code doesn't look very safe.
* You can't create an audio device using your own callback

What this version achieves:

* Two distinct AudioSpec structures for desired and obtained.
* In SDL2, `SDL_AudioSpec` is used to act as both desired and obtained,
where some fields are left unused in the desired version.
You can't ignore setting fields in Rust, so hence two structs.
* Use the new `AudioCallback` trait for callbacks.
* `AudioDevice::close()` has been removed in favor of using the `Drop` trait.
* Use generic types to automagically guess the correct AudioFormat.
For now, endianness is always set to native.
* Audio device lock guards

And I added an example at `examples/audio-whitenoise.rs`. :)