Commit graph

136 commits

Author SHA1 Message Date
Roderick van Domburg
7921f23927
Improve format handling and support MP3
- Switch from `lewton` to `Symphonia`. This is a pure Rust demuxer
  and decoder in active development that supports a wide range of
  formats, including Ogg Vorbis, MP3, AAC and FLAC for future HiFi
  support. At the moment only Ogg Vorbis and MP3 are enabled; all
  AAC files are DRM-protected.

- Bump MSRV to 1.51, required for `Symphonia`.

- Filter out all files whose format is not specified.

- Not all episodes seem to be encrypted. If we can't get an audio
  key, try and see if we can play the file without decryption.

- After seeking, report the actual position instead of the target.

- Remove the 0xa7 bytes offset from `Subfile`, `Symphonia` does
  not balk at Spotify's custom Ogg packet before it. This also
  simplifies handling of formats other than Ogg Vorbis.

- When there is no next track to load, signal the UI that the
  player has stopped. Before, the player would get stuck in an
  infinite reloading loop when there was only one track in the
  queue and that track could not be loaded.
2022-01-03 00:13:28 +01:00
Roderick van Domburg
286a031d94
Always seek to starting position 2021-12-30 21:52:15 +01:00
Roderick van Domburg
9b6e02fa0d
Prevent a few potential panics 2021-12-29 23:15:08 +01:00
Roderick van Domburg
e51f475a00
Further initial loading improvements
This should fix remaining cases of a client connecting, and failing
to start playback from *beyond* the beginning when `librespot` is
still loading that track.

This undoes the `suppress_loading_status` workaround from #430,
under the assumption that the race condition reported there has
since been fixed on Spotify's end.
2021-12-29 22:27:31 +01:00
Roderick van Domburg
332f9f04b1
Fix error hitting play when loading
Further changes:

 - Improve some debug and trace messages

 - Default to streaming download strategy

 - Synchronize mixer volume on loading play

 - Use default normalisation values when the file position isn't
   exactly what we need it to be

 - Update track position only when the decoder reports a
   successful seek
2021-12-28 23:46:37 +01:00
Roderick van Domburg
0f78fc277e
Call stream_from_cdn with CdnUrl 2021-12-27 21:42:57 +01:00
Roderick van Domburg
8aa23ed0c6
Drop locks as soon as possible 2021-12-27 00:11:07 +01:00
Roderick van Domburg
b4f7a9e35e
Change to parking_lot and remove remaining panics 2021-12-26 23:02:02 +01:00
Roderick van Domburg
62461be1fc
Change panics into Result<_, librespot_core::Error> 2021-12-26 21:18:42 +01:00
Roderick van Domburg
a297c68913
Make ping estimation less chatty 2021-12-19 00:14:00 +01:00
Roderick van Domburg
0d51fd43dc
Remove unwraps from librespot-audio 2021-12-18 23:44:13 +01:00
Roderick van Domburg
d18a0d1803
Fix caching message when cache is disabled 2021-12-18 14:02:28 +01:00
Roderick van Domburg
9d88ac59c6
Configure User-Agent once 2021-12-18 13:39:41 +01:00
Roderick van Domburg
3b07a6bcb9
Support user-defined temp directories 2021-12-17 20:58:05 +01:00
Roderick van Domburg
2f7b9863d9
Implement CDN for audio files 2021-12-16 22:42:37 +01:00
Roderick van Domburg
f3bb679ab1
Rid of the last remaining clippy warnings 2021-12-08 21:00:42 +01:00
Roderick van Domburg
9b2ca1442e
Move FileId out of SpotifyId 2021-12-08 19:53:45 +01:00
Roderick van Domburg
f03a7e95c1
Merge remote-tracking branch 'librespot-org/dev' into new-api-wip 2021-12-08 19:11:53 +01:00
Roderick van Domburg
0e6b1ba9dc
Update version numbers to 0.3.1 2021-10-24 20:12:33 +02:00
Sasha Hilton
6a3377402a Update version numbers to 0.3.0 2021-10-13 15:10:18 +01:00
Roderick van Domburg
949ca4fded
Add and default to "auto" normalisation type (#844) 2021-09-20 19:22:02 +02:00
Roderick van Domburg
b016b69772
Fix clippy warnings 2021-09-01 21:25:32 +02:00
Roderick van Domburg
7cd1b7a26a
Merge branch 'dev' into new-api-client 2021-06-26 00:14:20 +02:00
Roderick van Domburg
0703630041
Use PacketType instead of hex identifiers 2021-06-22 23:57:38 +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
johannesd3
555274b5af
Move decoder to playback crate 2021-05-11 20:36:53 +02:00
Sasha Hilton
2ef3928691 Update version numbers to 0.2.0 2021-05-04 13:05:13 +01:00
johannesd3
4925adb4f1 Fix broken streaming mode 2021-04-21 11:26:49 +02:00
johannesd3
b4f9ae31e2 Fix clippy warnings 2021-04-10 14:06:41 +02:00
johannesd3
26c127c2ec Merge branch 'dev' into tokio_migration 2021-04-10 12:59:47 +02:00
johannesd3
ff499825e0 Add missing feature flag to tokio 2021-04-10 12:50:30 +02:00
johannesd3
b7350b71da Restore previous feature flags
Some of the feature flags librespot uses are not really additive but
rather mutual exclusive. A previous attempt to improve the situation
had other drawbacks, so it's better to postpone a decision and restore
the old behaviour.
2021-04-10 12:50:30 +02:00
Roderick van Domburg
e20b96c598 Merge remote-tracking branch 'upstream/dev' into hi-res-volume-control 2021-04-09 20:06:20 +02:00
Roderick van Domburg
d0ea9631d2 Optimize requantizer to work in f32, then round 2021-04-09 19:33:28 +02:00
johannesd3
7c3d89112d Fix clippy warnings 2021-04-09 10:45:43 +02:00
johannesd3
f5274f5ada Merge branch 'dev' into tokio_migration 2021-04-09 10:39:06 +02:00
Roderick van Domburg
78bc621ebb Move SamplesConverter into convert.rs 2021-04-05 21:30:40 +02:00
Roderick van Domburg
a200b25916 Fix formatting 2021-03-27 21:44:01 +01:00
Roderick van Domburg
cdbce21e71 Make S16 to F32 sample conversion less magical 2021-03-27 21:42:10 +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
philippe44
86dbaa8ed5
true/false don't need to be explicit
Co-authored-by: Johannesd3 <51954457+Johannesd3@users.noreply.github.com>
2021-03-20 12:11:49 -07: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
770ea15498 Add support for S24 and S24_3 output formats 2021-03-17 00:00:27 +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
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
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
ca255c17f0 Split file fetch.rs 2021-03-11 18:09:51 +01:00
johannesd3
e71a004e93 Refactor AudioFileFetch using async/await
Previously, polling `AudioFileFetch` consisted of three parts: Handling
stream loader commands, handling received data, and triggering preloading
in stream mode when the number of open requests is sufficiently small. The
first steps use channels which are polled, and if something's available,
it's handled. The third step is executed on every call of `poll`.

The first two could easily be refactored using a `tokio::select!`-loop.
Therefore, counting the number of open requests was also refactored to fit
into this scheme. They were previously counted using a shared
`AtomicUsize`. Now, the number of open requests is stored exclusively in
`AudioFileFetch`, increased on starting a request, and decreased by an
oneshot channel that is fired when a request is finished.

This allows us to `select` that channel in the loop too, and since
loading ahead makes only sense if the number of open requests decreases,
the third step is only executed in this case.

`AudioFileFetch` does not implement `Future` anymore, but is rather used
as helper struct in an async fn `audio_file_fetch`.
2021-03-11 18:08:00 +01:00
Evan Cameron
6a33eb4efa
minor cleanup 2021-02-28 21:54:19 -05:00