Commit graph

282 commits

Author SHA1 Message Date
Roderick van Domburg
0e2686863a
Major metadata refactoring and enhancement
* Expose all fields of recent protobufs

 * Add support for user-scoped playlists, user root playlists and
   playlist annotations

 * Convert messages with the Rust type system

 * Attempt to adhere to embargos (tracks and episodes scheduled for
   future release)

 * Return `Result`s with meaningful errors instead of panicking on
   `unwrap`s

 * Add foundation for future playlist editing

 * Up version in connection handshake to get all version-gated features
2021-12-07 23:22:24 +01:00
JasonLG1979
4370258716 Address clippy lint warnings for rust 1.57 2021-12-03 12:51:41 -06:00
Roderick van Domburg
47badd61e0
Update tokio and fix build 2021-11-27 14:26:13 +01:00
Roderick van Domburg
d19fd24074
Add spclient and HTTPS support
* Change metadata to use spclient
 * Add support for HTTPS proxies
 * Start purging unwraps and using Result instead
2021-11-26 23:28:37 +01:00
JasonLG1979
c006a23644 Improve --device ? functionality for the alsa backend
This makes `--device ?` only show compatible devices (ones that support 2 ch 44.1 Interleaved) and it shows what `librespot` format(s) they support.

This should be more useful to users as the info maps directly to `librespot`'s `--device` and `--format` options.
2021-11-20 13:51:24 -06:00
JasonLG1979
0e9fdbe6b4 Refactor main.rs
* Don't panic when parsing options. Instead list valid values and exit.
* Get rid of needless .expect in playback/src/audio_backend/mod.rs.
* Enforce reasonable ranges for option values (breaking).
* Don't evaluate options that would otherwise have no effect.
* Add pub const MIXERS to mixer/mod.rs very similar to the audio_backend's implementation. (non-breaking though)
* Use different option descriptions and error messages based on what backends are enabled at build time.
* Add a -q, --quiet option that changed the logging level to warn.
* Add a short name for every flag and option.
* Note removed options.
* Other misc cleanups.
2021-11-17 15:31:16 -06:00
Roderick van Domburg
ff3648434b
Change hand-picked RNGs back to SmallRng
While `Xoshiro256+` is faster on 64-bit, it has low linear complexity in the
lower three bits, which *are* used when generating dither.

Also, while `Xoshiro128StarStar` access one less variable from the heap,
multiplication is generally slower than addition in hardware.
2021-10-21 19:31:58 +02:00
Roderick van Domburg
4c89a721ee
Improve dithering CPU usage (#866) 2021-10-19 22:33:04 +02:00
JasonLG1979
9ef53f5ffb simplify buffer resizing
This way is less verbose, much more simple and less brittle.
2021-10-07 08:44:29 -05:00
Jason Gray
4c1b2278ab
Fix clippy comparison chain warning (#857) 2021-10-04 20:59:18 +02:00
Jason Gray
8d70fd910e
Implement common SinkError and SinkResult (#820)
* Make error messages more consistent and concise.

* `impl From<AlsaError> for io::Error` so `AlsaErrors` can be thrown to player as `io::Errors`. This little bit of boilerplate goes a long way to simplifying things further down in the code. And will make any needed future changes easier.

* Bonus: handle ALSA backend buffer sizing a little better.
2021-09-27 20:46:26 +02:00
Jason Gray
89577d1fc1
Improve player (#823)
* Improve error handling
* Harmonize `Seek`: Make the decoders and player use the same math for converting between samples and milliseconds
* Reduce duplicate calls: Make decoder seek in PCM, not ms
* Simplify decoder errors with `thiserror`
2021-09-20 19:29:12 +02:00
Roderick van Domburg
949ca4fded
Add and default to "auto" normalisation type (#844) 2021-09-20 19:22:02 +02:00
Roderick van Domburg
30717c3db7
Merge pull request #842 from roderickvd/2db-normalisation-threshold
Update default normalisation threshold
2021-09-03 21:48:42 +02:00
Roderick van Domburg
2fcd24164d
Merge pull request #840 from roderickvd/attenuate-last
Attenuate after normalisation
2021-09-02 22:09:30 +02:00
Roderick van Domburg
fe644bc0d7
Update default normalisation threshold 2021-09-02 22:04:30 +02:00
Roderick van Domburg
b016b69772
Fix clippy warnings 2021-09-01 21:25:32 +02:00
Roderick van Domburg
d8e35bf0c4
Remove clamping of float samples 2021-09-01 20:55:28 +02:00
Roderick van Domburg
7da4d0e473
Attenuate after normalisation 2021-09-01 20:54:47 +02:00
Roderick van Domburg
c67e268dc8
Improve Alsa mixer command-line options 2021-08-26 22:35:45 +02:00
Roderick van Domburg
43a8b91a3d
Revert name to softvol 2021-07-09 22:17:29 +02:00
Jason Gray
68bec41e08
Improve Alsa backend buffer (#811)
* Reuse the buffer for the life of the Alsa sink
* Don't depend on capacity being exact when sizing the buffer
* Always give the PCM a period's worth of audio even when draining the buffer
* Refactoring and code cleanup
2021-07-06 08:37:29 +02:00
Jason Gray
9ff33980d6
Better errors in PulseAudio backend (#801)
* More meaningful error messages
* Use F32 if a user requests F64 (F64 is not supported by PulseAudio)
* Move all code that can fail to `start` where errors can be returned to prevent panics
* Use drain in `stop`
2021-06-30 21:14:23 +02:00
Reinier Balt
751ccf63bb
Make convert and decoder public (#814) 2021-06-30 09:54:02 +02:00
Roderick van Domburg
7cd1b7a26a
Merge branch 'dev' into new-api-client 2021-06-26 00:14:20 +02:00
JasonLG1979
bb2477831b Don't explicitly set the number of periods
Doing so on configs that have less than the 4 periods we were asking for caused a crash. Instead ask for a buffer time of 500ms.
2021-06-25 17:10:50 -05:00
Roderick van Domburg
a7326815bd
Merge pull request #802 from JasonLG1979/fix_pipe_backend
Better errors in pipe backend
2021-06-19 22:38:47 +02:00
Roderick van Domburg
113ac94c07
Update protobufs (#796)
* Import Spotify 1.1.61.583 (Windows) protobufs
* Import Spotify 1.1.33.569 protobufs missing in 1.1.61.583
* Remove unused protobufs, no longer present in 1.1.61.583
2021-06-19 22:29:48 +02:00
JasonLG1979
336e714dba Fix clippy warning 2021-06-18 15:30:22 -05:00
JasonLG1979
5ffce0662a Fix clippy warnings
Fix the clippy warnings caused by https://github.com/librespot-org/librespot/pull/797
2021-06-18 15:11:07 -05:00
Jason Gray
2466e0b3c1
Merge branch 'librespot-org:dev' into fix_pipe_backend 2021-06-18 14:12:32 -05:00
Jason Gray
4c77854ffe
Better errors alsa backend (#797)
Better error handling in Alsa backend

* More consistent error messages
* Bail on fatal errors in player
* Capture and log the original error as a warning when trying to write to PCM before trying to recover
2021-06-18 20:25:09 +02:00
JasonLG1979
0bece0d867 Fix pipe backend
* Move all code that can fail to `start` where errors can be returned to prevent a panic!
* Replace unwrap
2021-06-18 04:54:20 -05:00
JasonLG1979
4af095e741 Improve ALSA buffer size
* Go back to 4 periods at 125ms.
* Deal strictly in period time and periods to set ALSA buffer.
* Rename `buffer` to `period_buffer`.
* Add comments and change some other var names to add clarity.
* Let ALSA calculate the size of `period_buffer`.
2021-06-08 23:44:20 -05:00
Roderick van Domburg
d4f466ef58
Revert math::round_half_to_even
This caused quite a bump in CPU usage, which be acceptable if this
actually improved sound quality. However, it turns out that this
function only has one decimal precision, i.e. it would consider
all values from `0.50..0.60` (exclusive) as `0.5` which is in
error for our purposes.
2021-05-31 23:35:48 +02:00
Roderick van Domburg
ad19b69bfb
Various code improvements (#777)
* Remove deprecated use of std::u16::MAX
* Use `FromStr` for fallible `&str` conversions
* DRY up strings into constants
* Change `as_ref().map()` into `as_deref()`
* Use `Duration` for time constants and functions
* Optimize `Vec` with response times
* Move comments for `rustdoc` to parse
2021-05-31 22:32:39 +02:00
Roderick van Domburg
bae1834988
Fix output on big-endian systems (#778) 2021-05-30 20:57:46 +02:00
Roderick van Domburg
fe2d5ca7c6
Store and process samples in 64 bit (#773) 2021-05-30 20:09:39 +02:00
Roderick van Domburg
8062bd2518
Improve sample rounding and clean up noise shaping leftovers (#771) 2021-05-29 22:53:19 +02:00
Roderick van Domburg
19f0555e7c
Fix leftovers from merging diverging branches 2021-05-27 23:44:45 +02:00
Roderick van Domburg
f2d31b73bb
Print normalisation pregain in verbose mode 2021-05-26 23:14:24 +02:00
Roderick van Domburg
8abc0becaf
Print normalisation setup once and add units (#759) 2021-05-26 22:03:52 +02:00
Roderick van Domburg
11dfedea3b
Remove with-vorbis and with-tremor features (#750) 2021-05-26 21:43:20 +02:00
Roderick van Domburg
bb3dd64c87
Implement dithering (#694)
Dithering lowers digital-to-analog conversion ("requantization") error, linearizing output, lowering distortion and replacing it with a constant, fixed noise level, which is more pleasant to the ear than the distortion.

Guidance:

- On S24, S24_3 and S24, the default is to use triangular dithering. Depending on personal preference you may use Gaussian dithering instead; it's not as good objectively, but it may be preferred subjectively if you are looking for a more "analog" sound akin to tape hiss.

- Advanced users who know that they have a DAC without noise shaping have a third option: high-passed dithering, which is like triangular dithering except that it moves dithering noise up in frequency where it is less audible. Note: 99% of DACs are of delta-sigma design with noise shaping, so unless you have a multibit / R2R DAC, or otherwise know what you are doing, this is not for you.

- Don't dither or shape noise on S32 or F32. On F32 it's not supported anyway (there are no integer conversions and so no rounding errors) and on S32 the noise level is so far down that it is simply inaudible even after volume normalisation and control.

New command line option:

--dither DITHER Specify the dither algorithm to use - [none, gpdf,
                tpdf, tpdf_hp]. Defaults to 'tpdf' for formats S16
                S24, S24_3 and 'none' for other formats.

Notes:

This PR also features some opportunistic improvements. Worthy of mention are:
- matching reference Vorbis sample conversion techniques for lower noise
- a cleanup of the convert API
2021-05-26 21:19:17 +02:00
Roderick van Domburg
eca505c387
Improve volume controls
This is a squashed commit featuring the following:

Connect:
- Synchronize player volume with mixer volume on playback
- Fix step size on volume up/down events
- Remove no-op mixer started/stopped logic

Playback:
- Move from `connect` to `playback` crate
- Make cubic volume control available to all mixers with `--volume-ctrl cubic`
- Normalize volumes to `[0.0..1.0]` instead of `[0..65535]` for greater precision and performance (breaking)
- Add `--volume-range` option to set dB range and control `log` and `cubic` volume control curves
- Fix `log` and `cubic` volume controls to be mute at zero volume

Alsa mixer:
- Complete rewrite (breaking)
- Query card dB range for the `log` volume control unless specified otherwise
- Query dB range from Alsa softvol (previously only from hardware)
- Use `--device` name for `--mixer-card` unless specified otherwise
- Fix consistency for `cubic` between cards that report minimum volume as mute, and cards that report some dB value
- Fix `--volume-ctrl {linear|log}` to work as expected
- Removed `--mixer-linear-volume` option; use `--volume-ctrl linear` instead
2021-05-24 15:53:32 +02:00
Roderick van Domburg
9b44fd4f4a
Skip processing when normalisation is disabled 2021-05-17 21:27:34 +02:00
Roderick van Domburg
a4ad6d4aa8
Fix default normalisation threshold [#745] 2021-05-16 22:30:35 +02:00
johannesd3
041f084d7f Fix warnings 2021-05-13 22:42:55 +02:00
johannesd3
555274b5af
Move decoder to playback crate 2021-05-11 20:36:53 +02:00
Sasha Hilton
96dca284c9
Merge pull request #675 from Johannesd3/limit-cache-size
Add size limit to cache
2021-05-01 01:16:19 +01:00
johannesd3
de6bc32dea
Add documentation, logging and tests 2021-04-21 11:29:32 +02:00
johannesd3
e9dc9cd839
Add size limit to cache 2021-04-21 11:29:08 +02:00
Roderick van Domburg
d44b74ea57 Add dB unit in warning message 2021-04-16 20:49:21 +02:00
Roderick van Domburg
ffa284c42a Fix basic volume normalisation 2021-04-16 15:54:38 +02:00
Roderick van Domburg
7226bfd55a
Remove warning for Rodio on Alsa (fixed upstream) (#696) 2021-04-15 08:42:19 +02:00
johannesd3
b4f9ae31e2 Fix clippy warnings 2021-04-10 14:06:41 +02:00
johannesd3
a576194b0e Fix bug in rodio backend 2021-04-10 13:31:42 +02:00
johannesd3
26c127c2ec Merge branch 'dev' into tokio_migration 2021-04-10 12:59:47 +02:00
johannesd3
5435ab3270 Fix compile errors in backends
fe37186 added the restriction that `Sink`s must be `Send`. It turned
out later that this restrictions was unnecessary, and since some
`Sink`s aren't `Send` yet, this restriction is lifted again.

librespot-org/librespot#601 refactored the `RodioSink` in order to make
it `Send`. These changes are partly reverted in favour of the initial
simpler design.

Furthermore, there were some compile errors in the gstreamer backend
which are hereby fixed.
2021-04-10 12:50:30 +02:00
Roderick van Domburg
928a673653 DRY up constructors 2021-04-05 23:14:02 +02:00
Roderick van Domburg
07d710e14f Use AudioFormat size for SDL 2021-03-31 20:41:09 +02:00
Roderick van Domburg
d252eeedc5 Warn about broken backends 2021-03-27 22:53:05 +01:00
Roderick van Domburg
cc60dc11dc Fix buffer size in JACK Audio backend 2021-03-27 22:52:43 +01:00
Roderick van Domburg
bfca1ec15e Minor code improvements and crates bump 2021-03-27 21:13:14 +01:00
Roderick van Domburg
74b2fea338 Refactor sample conversion into separate struct 2021-03-21 22:16:47 +01:00
Roderick van Domburg
a1326ba9f4 First round of refactoring
- DRY-ups

 - Remove incorrect optimization attempt in the libvorbis decoder,
   that skewed 0.0 samples non-linear

 - PortAudio and SDL backends do not support S24 output. The PortAudio
   bindings could, but not through this API.
2021-03-18 22:06:43 +01:00
Roderick van Domburg
b94879de62 Fix GStreamer buffer pool size [ref #660 review] 2021-03-18 20:51:53 +01:00
Roderick van Domburg
770ea15498 Add support for S24 and S24_3 output formats 2021-03-17 00:00:27 +01:00
Roderick van Domburg
9dcaeee6d4 Default to S16 output 2021-03-16 20:22:00 +01:00
Roderick van Domburg
309e26456e Rename steepness to knee 2021-03-14 14:28:16 +01:00
Roderick van Domburg
5f26a745d7 Add support for S32 output format
While at it, add a small tweak when converting "silent" samples
from float to integer. This ensures 0.0 converts to 0 and vice
versa.
2021-03-13 23:43:24 +01:00
Roderick van Domburg
a4ef174fd0 Fix Alsa backend for 64-bit systems 2021-03-12 23:50:17 +01:00
Roderick van Domburg
5257be7824 Add command-line option to set F32 or S16 bit output
Usage: `--format {F32|S16}`. Default is F32.

 - Implemented for all backends, except for JACK audio which itself
 only supports 32-bit output at this time. Setting JACK audio to S16
 will panic and instruct the user to set output to F32.

 - The F32 default works fine for Rodio on macOS, but not on Raspian 10
 with Alsa as host. Therefore users on Linux systems are warned to set
 output to S16 in case of garbled sound with Rodio. This seems an issue
 with cpal incorrectly detecting the output stream format.

 - While at it, DRY up lots of code in the backends and by that virtue,
 also enable OggData passthrough on the subprocess backend.

 - I tested Rodio, ALSA, pipe and subprocess quite a bit, and call on
 others to join in and test the other backends.
2021-03-12 23:09:15 +01:00
Roderick van Domburg
1672eb87ab Fix build on Rust < 1.50.0 2021-03-12 23:09:15 +01:00
Roderick van Domburg
f29e5212c4 High-resolution volume control and normalisation
- Store and output samples as 32-bit floats instead of 16-bit integers.
   This provides 24-25 bits of transparency, allowing for 42-48 dB of
   headroom to do volume control and normalisation without throwing
   away bits or dropping dynamic range below 96 dB CD quality.

 - Perform volume control and normalisation in 64-bit arithmetic.

 - Add a dynamic limiter with configurable threshold, attack time,
   release or decay time, and steepness for the sigmoid transfer
   function. This mimics the native Spotify limiter, offering greater
   dynamic range than the old limiter, that just reduced overall gain
   to prevent clipping.

 - Make the configurable threshold also apply to the old limiter, which
   is still available.

Resolves: librespot-org/librespot#608
2021-03-12 23:09:15 +01:00
johannesd3
059b9029de Remove redundant field names 2021-03-10 22:41:46 +01:00
johannesd3
5616004dbe Fix many clippy lints
...and other small improvements
2021-03-10 22:41:44 +01:00
Evan Cameron
6a33eb4efa
minor cleanup 2021-02-28 21:54:19 -05:00
johannesd3
45f42acb82 Refactor 'find_available_alternatives' 2021-02-23 22:22:52 +01:00
johannesd3
5aeb733ad9 Clean up dependencies in librespot-playback
* Use futures-util instead of futures
* Use tokio channels instead of futures channels
* Removed "extern crate"s
2021-02-23 22:22:52 +01:00
johannesd3
c0942f14e8 Restore rodiojack support
Probably more simple than the previous approach which
doubles the code: Instead of implementing the `Open` trait,
we simply use custom SinkBuilder, one for the default host,
and one for the "jack" host.
2021-02-23 22:22:51 +01:00
johannesd3
678d1777fd Merge branch 'dev' into tokio_migration 2021-02-23 22:22:49 +01:00
johannesd3
1fc5267a71 Revert "Merge pull request #548 from Lcchy/rodiojack-backend"
This reverts commit f483075b2c, reversing
changes made to ea8ece36d9.
2021-02-23 22:20:58 +01:00
Philippe G
34bc286d9b ogg passthrough
rename
2021-02-22 13:45:53 -08:00
johannesd3
007e653f3d Restore original blocking player behaviour 2021-02-21 17:04:44 +01:00
johannesd3
b77f0a18ce Fix formatting 2021-02-13 10:29:00 +01:00
johannesd3
689415a6f1 Improved error handling in rodio backend 2021-02-12 19:34:40 +01:00
johannesd3
b2f1be4374 Make RodioSink Send and improve error handling 2021-02-12 19:34:28 +01:00
johannesd3
2f05ddfbc2 Fix bugs in player 2021-02-12 18:19:04 +01:00
johannesd3
872fab62d8 Merge branch 'dev' into tokio_migration 2021-02-10 21:51:33 +01:00
Sasha Hilton
59f87dcb37 Amend conditional compilation to fail on unsupported systems 2021-02-10 01:44:05 +00:00
Sasha Hilton
aad4dba8a8 Merge branch 'dev' into rodiojack-backend 2021-02-10 01:07:02 +00:00
Lcchy
52438b1cc2 Use rodio for jackaudio backend 2021-02-09 17:45:21 +01:00
Sasha Hilton
b72485cf46
Merge pull request #593 from Johannesd3/fix-issue-591 2021-02-09 13:54:47 +00:00
johannesd3
2f660f74ec Small refactor 2021-02-09 09:15:55 +01:00
Sasha Hilton
24486c8c83
Merge pull request #573 from librespot-org/album-normalisation
Add option to choose between track or album normalisation gain
2021-02-05 04:19:09 +00:00
johannesd3
f67ceb5f6d Small refactoring 2021-02-02 02:19:15 +01:00
johannesd3
3446864838 Handle corrupt cache files (#591) 2021-02-02 02:18:58 +01:00
Johannesd3
ed20f357dc
Fix playback in pulseaudio backend (#577)
* Fix playback in pulseaudio backend

* Add comment regarding safety
2021-01-29 02:01:38 +00:00
johannesd3
fe37186804 Make librespot_playback work 2021-01-25 09:04:33 +01:00