1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-06 03:50:06 +02:00

Add support for S32 output format

While at it, add a small tweak when converting "silent" samples
from float to integer. This ensures 0.0 converts to 0 and vice
versa.
This commit is contained in:
Roderick van Domburg 2021-03-13 23:43:24 +01:00
parent a4ef174fd0
commit 5f26a745d7
10 changed files with 81 additions and 18 deletions

View file

@ -41,6 +41,7 @@ fn open_device(dev_name: &str, format: AudioFormat) -> Result<(PCM, Frames), Box
let pcm = PCM::new(dev_name, Direction::Playback, false)?;
let (alsa_format, sample_size) = match format {
AudioFormat::F32 => (Format::float(), mem::size_of::<f32>()),
AudioFormat::S32 => (Format::s32(), mem::size_of::<i32>()),
AudioFormat::S16 => (Format::s16(), mem::size_of::<i16>()),
};
@ -157,6 +158,11 @@ impl AlsaSink {
let io = pcm.io_f32().unwrap();
io.writei(&self.buffer)
}
AudioFormat::S32 => {
let io = pcm.io_i32().unwrap();
let buf_s32: Vec<i32> = AudioPacket::f32_to_s32(&self.buffer);
io.writei(&buf_s32[..])
}
AudioFormat::S16 => {
let io = pcm.io_i16().unwrap();
let buf_s16: Vec<i16> = AudioPacket::f32_to_s16(&self.buffer);