Merge pull request #100 from nicokoch/fix-underflow-linux
Fix underflow bug on linux
This commit is contained in:
commit
fd0e992e57
|
@ -31,7 +31,7 @@ impl Endpoint {
|
||||||
|
|
||||||
match alsa::snd_pcm_open(&mut playback_handle, device_name.as_ptr() as *const _,
|
match alsa::snd_pcm_open(&mut playback_handle, device_name.as_ptr() as *const _,
|
||||||
alsa::SND_PCM_STREAM_PLAYBACK, alsa::SND_PCM_NONBLOCK)
|
alsa::SND_PCM_STREAM_PLAYBACK, alsa::SND_PCM_NONBLOCK)
|
||||||
{
|
{
|
||||||
-2 |
|
-2 |
|
||||||
-16 /* determined empirically */ => return Err(FormatsEnumerationError::DeviceNotAvailable),
|
-16 /* determined empirically */ => return Err(FormatsEnumerationError::DeviceNotAvailable),
|
||||||
e => check_errors(e).expect("device not available")
|
e => check_errors(e).expect("device not available")
|
||||||
|
@ -118,7 +118,7 @@ impl Endpoint {
|
||||||
192000,
|
192000,
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut rates = Vec::new();
|
let mut rates = Vec::new();
|
||||||
for &rate in RATES.iter() {
|
for &rate in RATES.iter() {
|
||||||
if alsa::snd_pcm_hw_params_test_rate(playback_handle, hw_params.0, rate, 0) == 0 {
|
if alsa::snd_pcm_hw_params_test_rate(playback_handle, hw_params.0, rate, 0) == 0 {
|
||||||
rates.push(rate);
|
rates.push(rate);
|
||||||
|
@ -215,7 +215,7 @@ impl Voice {
|
||||||
let mut playback_handle = mem::uninitialized();
|
let mut playback_handle = mem::uninitialized();
|
||||||
match alsa::snd_pcm_open(&mut playback_handle, name.as_ptr(),
|
match alsa::snd_pcm_open(&mut playback_handle, name.as_ptr(),
|
||||||
alsa::SND_PCM_STREAM_PLAYBACK, alsa::SND_PCM_NONBLOCK)
|
alsa::SND_PCM_STREAM_PLAYBACK, alsa::SND_PCM_NONBLOCK)
|
||||||
{
|
{
|
||||||
-16 /* determined empirically */ => return Err(CreationError::DeviceNotAvailable),
|
-16 /* determined empirically */ => return Err(CreationError::DeviceNotAvailable),
|
||||||
e => check_errors(e).expect("Device unavailable")
|
e => check_errors(e).expect("Device unavailable")
|
||||||
}
|
}
|
||||||
|
@ -300,9 +300,9 @@ impl Voice {
|
||||||
let available = {
|
let available = {
|
||||||
let channel = self.channel.lock().expect("could not lock channel");
|
let channel = self.channel.lock().expect("could not lock channel");
|
||||||
let available = unsafe { alsa::snd_pcm_avail(*channel) };
|
let available = unsafe { alsa::snd_pcm_avail(*channel) };
|
||||||
|
|
||||||
if available == -32 {
|
if available == -32 {
|
||||||
0 // buffer underrun
|
self.buffer_len as alsa::snd_pcm_sframes_t // buffer underrun
|
||||||
} else if available < 0 {
|
} else if available < 0 {
|
||||||
check_errors(available as libc::c_int).expect("could not write to buffer");
|
check_errors(available as libc::c_int).expect("could not write to buffer");
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
|
Loading…
Reference in New Issue