@@ -17,7 +17,7 @@ use crate::config::Config;
1717use base64:: prelude:: { Engine , BASE64_URL_SAFE_NO_PAD } ;
1818
1919use symphonia:: core:: audio:: Channels ;
20- use symphonia:: core:: codecs :: CodecParameters ;
20+ use symphonia:: core:: formats :: Track ;
2121
2222use rusty_chromaprint:: { Configuration , FingerprintCompressor , Fingerprinter } ;
2323
@@ -56,12 +56,16 @@ const MAX_DURATION: usize = 120;
5656impl Analyzer for ChromaprintFingerprintAnalyzer {
5757 type Result = ChromaprintFingerprintResult ;
5858
59- fn initialize ( _config : & Config , codec_params : & CodecParameters ) -> Result < Self , AnalyzerError > {
60- let sample_rate = codec_params
61- . sample_rate
62- . ok_or ( AnalyzerError :: MissingSampleRate ) ?;
63- let channels = codec_params
59+ fn initialize ( _config : & Config , track : & Track ) -> Result < Self , AnalyzerError > {
60+ let spec = track
61+ . codec_params
62+ . as_ref ( )
63+ . and_then ( |params| params. audio ( ) )
64+ . ok_or ( AnalyzerError :: NoSupportedAudioTracks ) ?;
65+ let sample_rate = spec. sample_rate . ok_or ( AnalyzerError :: MissingSampleRate ) ?;
66+ let channels = spec
6467 . channels
68+ . as_ref ( )
6569 . map ( Channels :: count)
6670 . and_then ( |channel_count| u32:: try_from ( channel_count) . ok ( ) )
6771 . ok_or ( AnalyzerError :: MissingAudioChannels ) ?;
@@ -80,8 +84,15 @@ impl Analyzer for ChromaprintFingerprintAnalyzer {
8084 Ok ( analyzer)
8185 }
8286
83- fn feed ( & mut self , samples : & [ i16 ] ) -> Result < ( ) , AnalyzerError > {
87+ fn feed ( & mut self , samples : & [ f32 ] ) -> Result < ( ) , AnalyzerError > {
8488 let remaining = self . stream_size_max - self . stream_size ;
89+
90+ #[ allow( clippy:: cast_possible_truncation) ]
91+ let samples: Vec < i16 > = samples
92+ . iter ( )
93+ . map ( |& sample| ( sample * 32_768.0 ) . trunc ( ) as i16 )
94+ . collect ( ) ;
95+
8596 let chunk_size = samples. len ( ) . min ( remaining) ;
8697 self . stream_size += chunk_size;
8798 self . fingerprinter . consume ( & samples[ ..chunk_size] ) ;
0 commit comments