Weird SDL2 hardware audio permission issue on GNU/Linux


#1

I’m using rust-sdl2 (version 0.30.0) writing a SDL2 based app while learning both Rust and SDL2.
I get following error when I try to run it Arch based GNU/Linux distro:

$ RUST_BACKTRACE=1 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/flipper`
INFO: Starting flipper
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "Couldn\'t set hardware audio parameters: Operation not permitted"', /checkout/src/libcore/result.rs:906:4
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:397
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:611
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:572
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:522
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:498
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:71
   9: core::result::unwrap_failed
             at /checkout/src/libcore/macros.rs:41
  10: <core::result::Result<T, E>>::unwrap
             at /checkout/src/libcore/result.rs:772
  11: flipper::main
             at src/main.rs:133
  12: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:99
  13: std::rt::lang_start
             at /checkout/src/libstd/panicking.rs:459
             at /checkout/src/libstd/panic.rs:361
             at /checkout/src/libstd/rt.rs:61
  14: main
  15: __libc_start_main
  16: _start

Same code works fine on MacOS and used to work fine.

Sounds part used to work on my GNU/Linux system untill this comment: https://github.com/kesara/flipper/commit/25f826081deae3ee5da1117c26be488cf0ca7ac9

Anyone had similar issues?
Thanks in advance.


#2

I was able to run it after chaing AudioSpecDesired from 42100 to 44100 for white noise generation function.
But it doesn’t generate any white noise after that change.
I see following log message:
ALSA lib pcm.c:8323:(snd_pcm_recover) underrun occurred