Skip to content

Commit

Permalink
Add support for rodiojack backend.
Browse files Browse the repository at this point in the history
The underlying `librespot` library already supports the JACK audio backend via `rodio`.
Enabling it in `spotifyd` turns out to be dead simple--just needed to add the config enum elements to pass it through!
  • Loading branch information
agdphd committed Apr 29, 2024
1 parent 614240d commit 1ac969e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
38 changes: 37 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ default = ["alsa_backend"]
portaudio_backend = ["librespot-playback/portaudio-backend"]
pulseaudio_backend = ["librespot-playback/pulseaudio-backend"]
rodio_backend = ["librespot-playback/rodio-backend"]
rodiojack_backend = ["librespot-playback/rodiojack-backend"]

[package.metadata.deb]
depends = "$auto, systemd, pulseaudio"
Expand Down
14 changes: 13 additions & 1 deletion docs/src/installation/Feature-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,16 @@ cargo build --release --no-default-features --features="rodio_backend"

On Linux you will need the development package for alsa and make/gcc. (`libasound2-dev`,`build-essential` on debian, `alsa-lib-devel`,`make`,`gcc` on fedora)

[mpris-specification]: https://specifications.freedesktop.org/mpris-spec/latest/
[mpris-specification]: https://specifications.freedesktop.org/mpris-spec/latest/

### JACK Audio Connection Kit

To use the [JACK](http://jackaudio.org) backend on Linux, compile with the `--features` flag to enable it:

```bash
cargo build --release --no-default-features --features="rodiojack_backend"
```

You will need the development packages for alsa, make/gcc, and JACK. (`libasound2-dev`, `build-essential`, and `libjack-dev` on Debian; `alsa-lib-devel`, `make`, `gcc`, and `jack-audio-connection-kit-devel` on Fedora.)

> __Note__: when Spotifyd starts with this backend, it will create a JACK output device named `cpal_client_out` with two ports: `out_0` for the left channel and `out_1` for the right.
11 changes: 10 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const CONFIG_FILE_NAME: &str = "spotifyd.conf";
feature = "pulseaudio_backend",
feature = "portaudio_backend",
feature = "alsa_backend",
feature = "rodio_backend"
feature = "rodio_backend",
feature = "rodiojack_backend",
feature = "jackaudio_backend",
)))]
compile_error!("At least one of the backend features is required!");
static BACKEND_VALUES: &[&str] = &[
Expand All @@ -36,6 +38,10 @@ static BACKEND_VALUES: &[&str] = &[
"portaudio",
#[cfg(feature = "rodio_backend")]
"rodio",
#[cfg(feature = "rodiojack_backend")]
"rodiojack",
#[cfg(feature = "jackaudio_backend")]
"jackaudio",
];

/// The backend used by librespot
Expand All @@ -46,6 +52,7 @@ pub enum Backend {
PortAudio,
PulseAudio,
Rodio,
RodioJack,
}

fn default_backend() -> Backend {
Expand All @@ -61,6 +68,7 @@ impl FromStr for Backend {
"portaudio" => Ok(Backend::PortAudio),
"pulseaudio" => Ok(Backend::PulseAudio),
"rodio" => Ok(Backend::Rodio),
"rodiojack" => Ok(Backend::RodioJack),
_ => unreachable!(),
}
}
Expand All @@ -73,6 +81,7 @@ impl ToString for Backend {
Backend::PortAudio => "portaudio".to_string(),
Backend::PulseAudio => "pulseaudio".to_string(),
Backend::Rodio => "rodio".to_string(),
Backend::RodioJack => "rodiojack".to_string(),
}
}
}
Expand Down

0 comments on commit 1ac969e

Please sign in to comment.