Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32bit support #28

Closed
seerickcode opened this issue Sep 2, 2021 · 2 comments
Closed

32bit support #28

seerickcode opened this issue Sep 2, 2021 · 2 comments

Comments

@seerickcode
Copy link
Contributor

seerickcode commented Sep 2, 2021

Trying to use this in a Raspberry PI 3 with a stock raspbian 32bit kernel/os.

consts::PCM_BUFFER_SIZE is set as a u64

This is causing issues with calls to quad_alsa_sys::snd_pcm_hw_params_set_buffer_size because it's also platform dependent, and will be built to expect an u32 or u64.

error[E0308]: mismatched types
  --> src/alsa_snd.rs:43:70
   |
43 |     if sys::snd_pcm_hw_params_set_buffer_size(pcm_handle, hw_params, consts::PCM_BUFFER_SIZE) < 0 {
   |                                                                      ^^^^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `u64`
   |
help: you can convert a `u64` to a `u32` and panic if the converted value doesn't fit
   |
43 |     if sys::snd_pcm_hw_params_set_buffer_size(pcm_handle, hw_params, consts::PCM_BUFFER_SIZE.try_into().unwrap()) < 0 {
   |                                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Also since quad_alsa_sys::snd_pcm_writei will return the frames written as a u32, this line fails:

error[E0308]: mismatched types
   --> src/alsa_snd.rs:128:29
    |
128 |         if frames_writen == -libc::EPIPE as i64 {
    |                             ^^^^^^^^^^^^^^^^^^^ expected `i32`, found `i64`
    |
help: you can convert `frames_writen` from `i32` to `i64`, matching the type of `-libc::EPIPE as i64`
    |
128 |         if i64::from(frames_writen) == -libc::EPIPE as i64 {
    |            ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

This later I can certainly do the i64 up convert as suggested, but for the first issue, with the snd_pcm_hw_params_set_buffer_size what is the best way to handle this?

I am still pretty new to rust. I make it a usize, but quad_alsa_sys is making this a u32 or u64 at compile time probably from the underlying C library. Is this something to be fixed in that library (quad_alsa_sys) to change the function to use usize?

If I force the const to u32 of course everything works fine, but that's now hard coding it to only work on 32bit systems.

@seerickcode
Copy link
Contributor Author

I think I figured it out digging into quad_alsa_sys..

diff --git a/src/alsa_snd.rs b/src/alsa_snd.rs
index 61c5c9f..9807ea6 100644
--- a/src/alsa_snd.rs
+++ b/src/alsa_snd.rs
@@ -10,7 +10,7 @@ mod consts {
     pub const DEVICE: &'static str = "default\0";
     pub const RATE: u32 = 44100;
     pub const CHANNELS: u32 = 2;
-    pub const PCM_BUFFER_SIZE: u64 = 4096;
+    pub const PCM_BUFFER_SIZE: ::std::os::raw::c_ulong = 4096;
 }
 
 unsafe fn setup_pcm_device() -> *mut sys::snd_pcm_t {
@@ -125,7 +125,7 @@ unsafe fn audio_thread(mut mixer: crate::mixer::Mixer) {
             buffer.as_ptr() as *const _,
             frames_to_deliver as _,
         );
-        if frames_writen == -libc::EPIPE as i64 {
+        if frames_writen == -libc::EPIPE as ::std::os::raw::c_long {
             println!("Underrun occured: -EPIPE, attempting recover");
 
             sys::snd_pcm_recover(pcm_handle, frames_writen as _, 0);

And now everything is happy

@not-fl3
Copy link
Owner

not-fl3 commented Sep 3, 2021

Solved with #29

@not-fl3 not-fl3 closed this as completed Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants