MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / alsa_audio_thread

Function alsa_audio_thread

native/linux/src/lib.rs:860–909  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

858
859#[cfg(target_os = "linux")]
860fn alsa_audio_thread() {
861 use alsa::pcm::*;
862 use alsa::{Direction, ValueOr};
863 use std::sync::atomic::Ordering;
864
865 let pcm = match PCM::new("default", Direction::Playback, false) {
866 Ok(p) => p,
867 Err(_) => return,
868 };
869
870 let sample_rate = 44100u32;
871 let channels = 2u32;
872 let period_size = 1024;
873
874 {
875 let hwp = HwParams::any(&pcm).unwrap();
876 let _ = hwp.set_channels(channels);
877 let _ = hwp.set_rate(sample_rate, ValueOr::Nearest);
878 let _ = hwp.set_format(Format::float());
879 let _ = hwp.set_access(Access::RWInterleaved);
880 let _ = hwp.set_period_size(period_size, ValueOr::Nearest);
881 let _ = hwp.set_buffer_size(period_size * 4);
882 let _ = pcm.hw_params(&hwp);
883 }
884
885 let _ = pcm.prepare();
886
887 let frames = period_size as usize;
888 let mut mix_buf = vec![0.0f32; frames * channels as usize];
889
890 while AUDIO_RUNNING.load(Ordering::SeqCst) {
891 for s in mix_buf.iter_mut() { *s = 0.0; }
892
893 unsafe {
894 ENGINE.get_mut().map(|eng| {
895 eng.audio.mix_output(&mut mix_buf);
896 });
897 }
898
899 let io = pcm.io_f32().unwrap();
900 match io.writei(&mix_buf) {
901 Ok(_) => {}
902 Err(e) => {
903 let _ = pcm.try_recover(e, true);
904 }
905 }
906 }
907
908 let _ = pcm.drain();
909}
910
911#[no_mangle]
912pub extern "C" fn bloom_load_sound(path_ptr: *const u8) -> f64 {

Callers 1

bloom_init_audioFunction · 0.85

Calls 6

set_accessMethod · 0.80
prepareMethod · 0.80
iter_mutMethod · 0.80
get_mutMethod · 0.80
mix_outputMethod · 0.80
set_formatMethod · 0.45

Tested by

no test coverage detected