Skip to content

Commit

Permalink
audio: set thread priority with audio_thread_priority
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai committed Nov 14, 2023
1 parent 3cc5080 commit a970f9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
21 changes: 15 additions & 6 deletions shukusai/src/audio/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ impl Audio {
let mut tries = 0_usize;
let output = loop {
match AudioOutput::dummy() {
Ok(o) => { debug!("Audio Init [1/2] ... dummy output device"); break o; },
Ok(o) => { debug!("Audio Init [1/3] ... dummy output device"); break o; },
Err(e) => {
if tries == 5 {
warn!("Audio Init [1/2] ... output device error: {e:?} ... will continue to retry every {RETRY_SECONDS} seconds, but will only log when we succeed");
warn!("Audio Init [1/3] ... output device error: {e:?} ... will continue to retry every {RETRY_SECONDS} seconds, but will only log when we succeed");
} else if tries < 5 {
warn!("Audio Init [1/2] ... output device error: {e:?} ... retrying in {RETRY_SECONDS} seconds");
warn!("Audio Init [1/3] ... output device error: {e:?} ... retrying in {RETRY_SECONDS} seconds");
}
tries += 1;
},
Expand All @@ -187,16 +187,16 @@ impl Audio {
let media_controls = if media_controls {
match crate::audio::media_controls::init_media_controls(to_audio) {
Ok(mc) => {
debug!("Audio Init [2/2] ... media controls");
debug!("Audio Init [2/3] ... media controls");
Some(mc)
},
Err(e) => {
warn!("Audio Init [2/2] ... media controls failed: {e}");
warn!("Audio Init [2/3] ... media controls failed: {e}");
None
},
}
} else {
debug!("Audio Init [2/2] ... skipping media controls");
debug!("Audio Init [2/3] ... skipping media controls");
None
};

Expand All @@ -219,6 +219,15 @@ impl Audio {
from_kernel,
};

// Set real-time thread priority.
match audio_thread_priority::promote_current_thread_to_real_time(
0, // audio buffer frames (0 == default sensible value)
96_000, // audio sample rate (assume 96Hz)
) {
Ok(_) => ok_debug!("Audio Init [3/3] ... realtime priority"),
Err(_) => fail!("Audio Init [3/3] ... realtime priority"),
}

// Start `main()`.
Self::main(audio);
}
Expand Down
7 changes: 0 additions & 7 deletions shukusai/src/kernel/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,6 @@ impl Kernel {
match std::thread::Builder::new()
.name("Audio".to_string())
.spawn(move || {
#[cfg(unix)]
{
// SAFETY: libc is used to set niceness.
let nice = unsafe { libc::nice(-20) };
debug!("Audio ... spawned at niceness level: {nice}");
}

Audio::init(collection, audio, audio_send, audio_recv, media_controls);
}) {
Ok(_) => debug!("Kernel Init [11/13] ... spawned Audio"),
Expand Down

0 comments on commit a970f9a

Please sign in to comment.