Skip to content

Commit 3837cc2

Browse files
committed
Fix Alsa backend for 64-bit systems
1 parent 6379926 commit 3837cc2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

playback/src/audio_backend/alsa.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::process::exit;
1111
use std::{io, mem};
1212

1313
const BUFFERED_LATENCY: f32 = 0.125; // seconds
14-
const BUFFERED_PERIODS: u8 = 4;
14+
const BUFFERED_PERIODS: Frames = 4;
1515

1616
pub struct AlsaSink {
1717
pcm: Option<PCM>,
@@ -48,7 +48,7 @@ fn open_device(dev_name: &str, format: AudioFormat) -> Result<(PCM, Frames), Box
4848
// latency = period_size * periods / (rate * bytes_per_frame)
4949
// For stereo samples encoded as 32-bit float, one frame has a length of eight bytes.
5050
let mut period_size = ((SAMPLES_PER_SECOND * sample_size as u32) as f32
51-
* (BUFFERED_LATENCY / BUFFERED_PERIODS as f32)) as i32;
51+
* (BUFFERED_LATENCY / BUFFERED_PERIODS as f32)) as Frames;
5252

5353
// Set hardware parameters: 44100 Hz / stereo / 32-bit float or 16-bit signed integer
5454
{
@@ -58,7 +58,7 @@ fn open_device(dev_name: &str, format: AudioFormat) -> Result<(PCM, Frames), Box
5858
hwp.set_rate(SAMPLE_RATE, ValueOr::Nearest)?;
5959
hwp.set_channels(NUM_CHANNELS as u32)?;
6060
period_size = hwp.set_period_size_near(period_size, ValueOr::Greater)?;
61-
hwp.set_buffer_size_near(period_size * BUFFERED_PERIODS as i32)?;
61+
hwp.set_buffer_size_near(period_size * BUFFERED_PERIODS)?;
6262
pcm.hw_params(&hwp)?;
6363

6464
let swp = pcm.sw_params_current()?;
@@ -102,7 +102,7 @@ impl Sink for AlsaSink {
102102
self.pcm = Some(p);
103103
// Create a buffer for all samples for a full period
104104
self.buffer =
105-
Vec::with_capacity((period_size * BUFFERED_PERIODS as i32) as usize);
105+
Vec::with_capacity((period_size * BUFFERED_PERIODS) as usize);
106106
}
107107
Err(e) => {
108108
error!("Alsa error PCM open {}", e);

0 commit comments

Comments
 (0)