Use AudioFormat size for SDL

This commit is contained in:
Roderick van Domburg 2021-03-31 20:41:09 +02:00
parent d252eeedc5
commit 07d710e14f

View file

@ -3,7 +3,7 @@ use crate::audio::{AudioPacket, SamplesConverter};
use crate::config::AudioFormat; use crate::config::AudioFormat;
use crate::player::{NUM_CHANNELS, SAMPLE_RATE}; use crate::player::{NUM_CHANNELS, SAMPLE_RATE};
use sdl2::audio::{AudioQueue, AudioSpecDesired}; use sdl2::audio::{AudioQueue, AudioSpecDesired};
use std::{io, mem, thread, time}; use std::{io, thread, time};
pub enum SdlSink { pub enum SdlSink {
F32(AudioQueue<f32>), F32(AudioQueue<f32>),
@ -93,17 +93,17 @@ impl Sink for SdlSink {
let samples = packet.samples(); let samples = packet.samples();
match self { match self {
Self::F32(queue) => { Self::F32(queue) => {
drain_sink!(queue, mem::size_of::<f32>()); drain_sink!(queue, AudioFormat::F32.size());
queue.queue(samples) queue.queue(samples)
} }
Self::S32(queue) => { Self::S32(queue) => {
let samples_s32: &[i32] = &SamplesConverter::to_s32(samples); let samples_s32: &[i32] = &SamplesConverter::to_s32(samples);
drain_sink!(queue, mem::size_of::<i32>()); drain_sink!(queue, AudioFormat::S32.size());
queue.queue(samples_s32) queue.queue(samples_s32)
} }
Self::S16(queue) => { Self::S16(queue) => {
let samples_s16: &[i16] = &SamplesConverter::to_s16(samples); let samples_s16: &[i16] = &SamplesConverter::to_s16(samples);
drain_sink!(queue, mem::size_of::<i16>()); drain_sink!(queue, AudioFormat::S16.size());
queue.queue(samples_s16) queue.queue(samples_s16)
} }
}; };