@@ -8,7 +8,9 @@ use gethostname::gethostname;
8
8
use librespot_core:: {
9
9
cache:: Cache , config:: DeviceType as LSDeviceType , config:: SessionConfig , version,
10
10
} ;
11
- use librespot_playback:: config:: { Bitrate as LSBitrate , PlayerConfig } ;
11
+ use librespot_playback:: config:: {
12
+ AudioFormat as LSAudioFormat , Bitrate as LSBitrate , PlayerConfig ,
13
+ } ;
12
14
use log:: { error, info, warn} ;
13
15
use reqwest:: Url ;
14
16
use serde:: { de:: Error , de:: Unexpected , Deserialize , Deserializer } ;
@@ -221,6 +223,56 @@ impl From<Bitrate> for LSBitrate {
221
223
}
222
224
}
223
225
226
+ /// Libspotify audio formats
227
+ static AUDIO_FORMAT_VALUES : & [ & str ] = & [ "F32" , "S32" , "S24" , "S24_3" , "S16" ] ;
228
+ #[ derive( Clone , Copy , Debug , Deserialize , PartialEq , StructOpt ) ]
229
+ pub enum AudioFormat {
230
+ F32 ,
231
+ S32 ,
232
+ S24 ,
233
+ S24_3 ,
234
+ S16 ,
235
+ }
236
+
237
+ impl FromStr for AudioFormat {
238
+ type Err = ParseError ;
239
+
240
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
241
+ match s {
242
+ "F32" => Ok ( AudioFormat :: F32 ) ,
243
+ "S32" => Ok ( AudioFormat :: S32 ) ,
244
+ "S24" => Ok ( AudioFormat :: S24 ) ,
245
+ "S24_3" => Ok ( AudioFormat :: S24_3 ) ,
246
+ "S16" => Ok ( AudioFormat :: S16 ) ,
247
+ _ => unreachable ! ( ) ,
248
+ }
249
+ }
250
+ }
251
+
252
+ impl ToString for AudioFormat {
253
+ fn to_string ( & self ) -> String {
254
+ match self {
255
+ AudioFormat :: F32 => "F32" . to_string ( ) ,
256
+ AudioFormat :: S32 => "S32" . to_string ( ) ,
257
+ AudioFormat :: S24 => "S24" . to_string ( ) ,
258
+ AudioFormat :: S24_3 => "S24_3" . to_string ( ) ,
259
+ AudioFormat :: S16 => "S16" . to_string ( ) ,
260
+ }
261
+ }
262
+ }
263
+
264
+ impl From < AudioFormat > for LSAudioFormat {
265
+ fn from ( audio_format : AudioFormat ) -> Self {
266
+ match audio_format {
267
+ AudioFormat :: F32 => LSAudioFormat :: F32 ,
268
+ AudioFormat :: S32 => LSAudioFormat :: S32 ,
269
+ AudioFormat :: S24 => LSAudioFormat :: S24 ,
270
+ AudioFormat :: S24_3 => LSAudioFormat :: S24_3 ,
271
+ AudioFormat :: S16 => LSAudioFormat :: S16 ,
272
+ }
273
+ }
274
+ }
275
+
224
276
#[ derive( Debug , Default , StructOpt ) ]
225
277
#[ structopt(
226
278
about = "A Spotify daemon" ,
@@ -346,6 +398,10 @@ pub struct SharedConfigValues {
346
398
#[ structopt( long, short = "B" , possible_values = & BITRATE_VALUES , value_name = "number" ) ]
347
399
bitrate : Option < Bitrate > ,
348
400
401
+ /// The audio format of the streamed audio data
402
+ #[ structopt( long, possible_values = & AUDIO_FORMAT_VALUES , value_name = "string" ) ]
403
+ audio_format : Option < AudioFormat > ,
404
+
349
405
/// Initial volume between 0 and 100
350
406
#[ structopt( long, value_name = "initial_volume" ) ]
351
407
initial_volume : Option < String > ,
@@ -452,6 +508,7 @@ impl fmt::Debug for SharedConfigValues {
452
508
. field ( "mixer" , & self . mixer )
453
509
. field ( "device_name" , & self . device_name )
454
510
. field ( "bitrate" , & self . bitrate )
511
+ . field ( "audio_format" , & self . audio_format )
455
512
. field ( "initial_volume" , & self . initial_volume )
456
513
. field ( "volume_normalisation" , & self . volume_normalisation )
457
514
. field ( "normalisation_pregain" , & self . normalisation_pregain )
@@ -521,7 +578,8 @@ impl SharedConfigValues {
521
578
zeroconf_port,
522
579
proxy,
523
580
device_type,
524
- use_mpris
581
+ use_mpris,
582
+ audio_format
525
583
) ;
526
584
527
585
// Handles boolean merging.
@@ -559,6 +617,7 @@ pub(crate) struct SpotifydConfig {
559
617
pub ( crate ) cache : Option < Cache > ,
560
618
pub ( crate ) backend : Option < String > ,
561
619
pub ( crate ) audio_device : Option < String > ,
620
+ pub ( crate ) audio_format : LSAudioFormat ,
562
621
#[ allow( unused) ]
563
622
pub ( crate ) control_device : Option < String > ,
564
623
#[ allow( unused) ]
@@ -601,6 +660,12 @@ pub(crate) fn get_internal_config(config: CliConfig) -> SpotifydConfig {
601
660
. unwrap_or ( Bitrate :: Bitrate160 )
602
661
. into ( ) ;
603
662
663
+ let audio_format: LSAudioFormat = config
664
+ . shared_config
665
+ . audio_format
666
+ . unwrap_or ( AudioFormat :: S16 )
667
+ . into ( ) ;
668
+
604
669
let backend = config
605
670
. shared_config
606
671
. backend
@@ -715,6 +780,7 @@ pub(crate) fn get_internal_config(config: CliConfig) -> SpotifydConfig {
715
780
cache,
716
781
backend : Some ( backend) ,
717
782
audio_device : config. shared_config . device ,
783
+ audio_format,
718
784
control_device : config. shared_config . control ,
719
785
mixer : config. shared_config . mixer ,
720
786
volume_controller,
0 commit comments