Fix playback in pulseaudio backend (#577)

* Fix playback in pulseaudio backend

* Add comment regarding safety
This commit is contained in:
Johannesd3 2021-01-29 03:01:38 +01:00 committed by GitHub
parent efabb03631
commit ed20f357dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,7 +67,11 @@ impl Sink for PulseAudioSink {
fn write(&mut self, data: &[i16]) -> io::Result<()> { fn write(&mut self, data: &[i16]) -> io::Result<()> {
if let Some(s) = &self.s { if let Some(s) = &self.s {
let d: &[u8] = unsafe { std::mem::transmute(data) }; // SAFETY: An i16 consists of two bytes, so that the given slice can be interpreted
// as a byte array of double length. Each byte pointer is validly aligned, and so
// is the newly created slice.
let d: &[u8] =
unsafe { std::slice::from_raw_parts(data.as_ptr() as *const u8, data.len() * 2) };
match s.write(d) { match s.write(d) {
Ok(_) => Ok(()), Ok(_) => Ok(()),