git/grrs/main

feature: add loudness normalization option

added a `loudness_normalization` option to the config that will append `--af=loudnorm=I=-16:TP=-1.5:LRA=11` to mpv arguments when enabled. updated the mpv spawn logic accordingly. closes 3331828
diff --git a/config.toml.example b/config.toml.example
index ac692a7..3341ae8 100644
--- a/config.toml.example
+++ b/config.toml.example
@@ -3,6 +3,8 @@
[player]
# startup volume (0 to 100)
startup_volume = 100
+# apply mpv's loudnorm audio filter to normalize the stream volume
+loudness_normalization = false
# the gensokyo radio stream url
stream_url = "https://stream.gensokyoradio.net/3"
diff --git a/pkg/grrs-git/PKGBUILD b/pkg/grrs-git/PKGBUILD
index c3bdb97..aade489 100644
--- a/pkg/grrs-git/PKGBUILD
+++ b/pkg/grrs-git/PKGBUILD
@@ -1,7 +1,7 @@
# Maintainer: Myn <hello@myn.sh>
pkgname=grrs-git
-pkgver=r28.c52b71d
+pkgver=r30.b907e00
pkgrel=1
pkgdesc="A minimal TUI for Gensokyo Radio"
arch=('x86_64')
diff --git a/src/config.rs b/src/config.rs
index b0f1b04..435ee93 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -16,12 +16,17 @@ pub struct AppConfig {
#[serde(default, deny_unknown_fields)]
pub struct PlayerConfig {
pub startup_volume: u8,
+ pub loudness_normalization: bool,
pub stream_url: String,
}
impl Default for PlayerConfig {
fn default() -> Self {
- Self { startup_volume: 100, stream_url: "https://stream.gensokyoradio.net/3".to_string() }
+ Self {
+ startup_volume: 100,
+ loudness_normalization: false,
+ stream_url: "https://stream.gensokyoradio.net/3".to_string(),
+ }
}
}
@@ -71,7 +76,6 @@ impl Default for SystemConfig {
}
}
-
impl AppConfig {
pub fn load_or_create(config_path: &PathBuf) -> Result<Self, String> {
if config_path.exists() {
diff --git a/src/main.rs b/src/main.rs
index 697ddcb..508045c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -53,15 +53,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Hard stop: Only spawn mpv if the config is valid
if !is_config_error {
let _ = fs::remove_file(&socket_path);
+
+ let mut mpv_args = vec![
+ "--no-video".to_string(),
+ "--really-quiet".to_string(),
+ "--no-terminal".to_string(),
+ volume_arg,
+ format!("--input-ipc-server={socket_path}"),
+ ];
+
+ if state.config.player.loudness_normalization {
+ mpv_args.push("--af=loudnorm=I=-16:TP=-1.5:LRA=11".to_string());
+ }
+ mpv_args.push(stream_url);
+
mpv_process = Command::new("mpv")
- .args([
- "--no-video",
- "--really-quiet",
- "--no-terminal",
- &volume_arg,
- &format!("--input-ipc-server={socket_path}"),
- &stream_url,
- ])
+ .args(mpv_args)
.stdout(Stdio::null())
.stderr(Stdio::null())
.stdin(Stdio::null())
diff --git a/src/models.rs b/src/models.rs
index 95801c7..7de82c9 100644
--- a/src/models.rs
+++ b/src/models.rs
@@ -65,7 +65,9 @@ pub struct MpvSong {
pub fn parse_mpv_media_title(title: &str) -> Option<MpvSong> {
let trimmed = title.trim();
- trimmed.find(" - ").map(|idx| MpvSong { artist: trimmed[..idx].trim().to_string(), title: trimmed[idx + 3..].trim().to_string() })
+ trimmed
+ .find(" - ")
+ .map(|idx| MpvSong { artist: trimmed[..idx].trim().to_string(), title: trimmed[idx + 3..].trim().to_string() })
}
#[derive(Default, Clone)]