Skip to content

Commit c951a94

Browse files
committed
refactor: clippy fixes
1 parent 377fbb9 commit c951a94

File tree

10 files changed

+50
-91
lines changed

10 files changed

+50
-91
lines changed

benches/effects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn agc_enabled(bencher: Bencher) {
6060
#[cfg(feature = "experimental")]
6161
#[divan::bench]
6262
fn agc_disabled(bencher: Bencher) {
63-
bencher.with_inputs(|| music_wav()).bench_values(|source| {
63+
bencher.with_inputs(music_wav).bench_values(|source| {
6464
// Create the AGC source
6565
let amplified_source = source.automatic_gain_control(
6666
1.0, // target_level

examples/error_callback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() -> Result<(), Box<dyn Error>> {
1717
// Filter for where err is a DeviceNotAvailable error.
1818
if let cpal::StreamError::DeviceNotAvailable = err {
1919
if let Err(e) = tx.send(err) {
20-
eprintln!("Error emitting StreamError: {}", e);
20+
eprintln!("Error emitting StreamError: {e}");
2121
}
2222
}
2323
})
@@ -34,7 +34,7 @@ fn main() -> Result<(), Box<dyn Error>> {
3434
// Here we print the error that was emitted by the error callback.
3535
// but in a real application we may want to destroy the stream and
3636
// try to reopen it, either with the same device or a different one.
37-
eprintln!("Error with stream {}", err);
37+
eprintln!("Error with stream {err}");
3838
}
3939

4040
Ok(())

examples/limit_settings.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() {
4444

4545
// Show peak reduction
4646
let max_sample = samples.iter().fold(0.0f32, |acc, &x| acc.max(x.abs()));
47-
println!(" Peak amplitude after limiting: {:.3}", max_sample);
47+
println!(" Peak amplitude after limiting: {max_sample:.3}");
4848
println!();
4949

5050
println!("Example 4: Custom settings with builder pattern");
@@ -138,12 +138,11 @@ fn main() {
138138
strict_limiting.threshold
139139
);
140140
println!(" Original max amplitude: {AMPLITUDE}");
141-
println!(" Target threshold: {:.3}", target_linear);
142-
println!(" Early peak (0-500 samples): {:.3}", early_peak);
143-
println!(" Mid peak (1000-1500 samples): {:.3}", mid_peak);
144-
println!(" Settled peak (2000+ samples): {:.3}", settled_peak);
141+
println!(" Target threshold: {target_linear:.3}");
142+
println!(" Early peak (0-500 samples): {early_peak:.3}");
143+
println!(" Mid peak (1000-1500 samples): {mid_peak:.3}");
144+
println!(" Settled peak (2000+ samples): {settled_peak:.3}");
145145
println!(
146-
" ALL samples now well below 1.0: max = {:.3}",
147-
max_settled
146+
" ALL samples now well below 1.0: max = {max_settled:.3}"
148147
);
149148
}

examples/music_m4a.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::error::Error;
22

33
fn main() -> Result<(), Box<dyn Error>> {
44
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
5-
let sink = rodio::Sink::connect_new(&stream_handle.mixer());
5+
let sink = rodio::Sink::connect_new(stream_handle.mixer());
66

77
let file = std::fs::File::open("assets/music.m4a")?;
88
sink.append(rodio::Decoder::try_from(file)?);

src/conversions/sample_rate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ mod test {
352352
let duration =
353353
Duration::from_secs_f32(resampled.count() as f32 / to as f32);
354354

355-
let delta = if d < duration { duration - d } else { d - duration };
355+
let delta = duration.abs_diff(d);
356356
TestResult::from_bool(delta < Duration::from_millis(1))
357357
}
358358
}

src/decoder/symphonia.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl fmt::Display for SeekError {
267267
write!(f, "The decoder needs to know the length of the file/byte stream to be able to seek backwards. You can set that by using the `DecoderBuilder` or creating a decoder using `Decoder::try_from(some_file)`.")
268268
}
269269
SeekError::Demuxer(err) => {
270-
write!(f, "Demuxer failed to seek: {:?}", err)
270+
write!(f, "Demuxer failed to seek: {err:?}")
271271
}
272272
}
273273
}

src/math.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,15 @@ mod test {
165165

166166
assert!(
167167
relative_error < MAX_RELATIVE_ERROR,
168-
"Implementation precision failed for {}dB: exact {:.8}, got {:.8}, relative error: {:.2e}",
169-
db, exact_linear, actual_linear, relative_error
168+
"Implementation precision failed for {db}dB: exact {exact_linear:.8}, got {actual_linear:.8}, relative error: {relative_error:.2e}"
170169
);
171170

172171
// Sanity check: ensure we're in the right order of magnitude as Wikipedia data
173172
// This is lenient to account for rounding in the reference values
174173
let magnitude_ratio = actual_linear / wikipedia_linear;
175174
assert!(
176175
magnitude_ratio > 0.99 && magnitude_ratio < 1.01,
177-
"Result magnitude differs significantly from Wikipedia reference for {}dB: Wikipedia {}, got {}, ratio: {:.4}",
178-
db, wikipedia_linear, actual_linear, magnitude_ratio
176+
"Result magnitude differs significantly from Wikipedia reference for {db}dB: Wikipedia {wikipedia_linear}, got {actual_linear}, ratio: {magnitude_ratio:.4}"
179177
);
180178
}
181179
}
@@ -197,8 +195,7 @@ mod test {
197195

198196
assert!(
199197
relative_error < MAX_RELATIVE_ERROR,
200-
"Linear to dB conversion precision failed for {}: exact {:.8}, got {:.8}, relative error: {:.2e}",
201-
linear, exact_db, actual_db, relative_error
198+
"Linear to dB conversion precision failed for {linear}: exact {exact_db:.8}, got {actual_db:.8}, relative error: {relative_error:.2e}"
202199
);
203200
} else {
204201
// Use absolute error for values very close to 0 dB (linear ≈ 1.0)
@@ -207,8 +204,7 @@ mod test {
207204

208205
assert!(
209206
absolute_error < MAX_ABSOLUTE_ERROR,
210-
"Linear to dB conversion precision failed for {}: exact {:.8}, got {:.8}, absolute error: {:.2e}",
211-
linear, exact_db, actual_db, absolute_error
207+
"Linear to dB conversion precision failed for {linear}: exact {exact_db:.8}, got {actual_db:.8}, absolute error: {absolute_error:.2e}"
212208
);
213209
}
214210

@@ -223,8 +219,7 @@ mod test {
223219
if expected_db.abs() > 10.0 * f32::EPSILON {
224220
assert!(
225221
magnitude_ratio > 0.99 && magnitude_ratio < 1.01,
226-
"Result differs significantly from table reference for linear {}: expected {}dB, got {}dB, ratio: {:.4}",
227-
linear, expected_db, actual_db, magnitude_ratio
222+
"Result differs significantly from table reference for linear {linear}: expected {expected_db}dB, got {actual_db}dB, ratio: {magnitude_ratio:.4}"
228223
);
229224
}
230225
}
@@ -244,10 +239,7 @@ mod test {
244239

245240
assert!(
246241
error < MAX_ROUND_TRIP_ERROR,
247-
"Round-trip conversion failed for {}dB: got {:.8}dB, error: {:.2e}",
248-
original_db,
249-
round_trip_db,
250-
error
242+
"Round-trip conversion failed for {original_db}dB: got {round_trip_db:.8}dB, error: {error:.2e}"
251243
);
252244
}
253245

@@ -263,10 +255,7 @@ mod test {
263255

264256
assert!(
265257
relative_error < MAX_ROUND_TRIP_RELATIVE_ERROR,
266-
"Round-trip conversion failed for {}: got {:.8}, relative error: {:.2e}",
267-
original_linear,
268-
round_trip_linear,
269-
relative_error
258+
"Round-trip conversion failed for {original_linear}: got {round_trip_linear:.8}, relative error: {relative_error:.2e}"
270259
);
271260
}
272261
}

src/source/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,13 @@ impl fmt::Display for SeekError {
700700
SeekError::NotSupported { underlying_source } => {
701701
write!(
702702
f,
703-
"Seeking is not supported by source: {}",
704-
underlying_source
703+
"Seeking is not supported by source: {underlying_source}"
705704
)
706705
}
707706
#[cfg(feature = "symphonia")]
708-
SeekError::SymphoniaDecoder(err) => write!(f, "Error seeking: {}", err),
707+
SeekError::SymphoniaDecoder(err) => write!(f, "Error seeking: {err}"),
709708
#[cfg(feature = "hound")]
710-
SeekError::HoundDecoder(err) => write!(f, "Error seeking in wav source: {}", err),
709+
SeekError::HoundDecoder(err) => write!(f, "Error seeking in wav source: {err}"),
711710
SeekError::Other(_) => write!(f, "An error occurred"),
712711
}
713712
}

src/source/noise.rs

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ pub struct WhiteGaussian<R: Rng = SmallRng> {
342342
impl<R: Rng + SeedableRng> WhiteGaussian<R> {
343343
/// Get the mean (average) value of the noise distribution.
344344
pub fn mean(&self) -> f32 {
345-
self.sampler.distribution.mean() as f32
345+
self.sampler.distribution.mean()
346346
}
347347

348348
/// Get the standard deviation of the noise distribution.
349349
pub fn std_dev(&self) -> f32 {
350-
self.sampler.distribution.std_dev() as f32
350+
self.sampler.distribution.std_dev()
351351
}
352352
}
353353

@@ -709,7 +709,7 @@ mod tests {
709709
"Violet" => Box::new(Violet::new(TEST_SAMPLE_RATE)),
710710
"Brownian" => Box::new(Brownian::new(TEST_SAMPLE_RATE)),
711711
"Velvet" => Box::new(Velvet::new(TEST_SAMPLE_RATE)),
712-
_ => panic!("Unknown generator: {}", name),
712+
_ => panic!("Unknown generator: {name}"),
713713
}
714714
}
715715

@@ -724,7 +724,7 @@ mod tests {
724724
"Violet" => Box::new(Violet::new(TEST_SAMPLE_RATE)),
725725
"Brownian" => Box::new(Brownian::new(TEST_SAMPLE_RATE)),
726726
"Velvet" => Box::new(Velvet::new(TEST_SAMPLE_RATE)),
727-
_ => panic!("Unknown generator: {}", name),
727+
_ => panic!("Unknown generator: {name}"),
728728
}
729729
}
730730

@@ -775,11 +775,8 @@ mod tests {
775775
for i in 0..TEST_SAMPLES_MEDIUM {
776776
let sample = generator.next().unwrap();
777777
assert!(
778-
sample >= -1.0 && sample <= 1.0,
779-
"{} sample {} out of range [-1.0, 1.0]: {}",
780-
generator_name,
781-
i,
782-
sample
778+
(-1.0..=1.0).contains(&sample),
779+
"{generator_name} sample {i} out of range [-1.0, 1.0]: {sample}"
783780
);
784781
}
785782
}
@@ -793,10 +790,7 @@ mod tests {
793790
let sample = generator.next().unwrap();
794791
assert!(
795792
sample.is_finite(),
796-
"{} produced non-finite sample at index {}: {}",
797-
generator_name,
798-
i,
799-
sample
793+
"{generator_name} produced non-finite sample at index {i}: {sample}"
800794
);
801795
}
802796
}
@@ -809,9 +803,7 @@ mod tests {
809803
let seek_result = generator.try_seek(std::time::Duration::from_secs(1));
810804
assert!(
811805
seek_result.is_ok(),
812-
"{} should support seeking but returned error: {:?}",
813-
generator_name,
814-
seek_result
806+
"{generator_name} should support seeking but returned error: {seek_result:?}"
815807
);
816808
}
817809

@@ -822,30 +814,27 @@ mod tests {
822814
let source = create_generator_source(generator_name);
823815

824816
// All noise generators should be mono (1 channel)
825-
assert_eq!(source.channels(), 1, "{} should be mono", generator_name);
817+
assert_eq!(source.channels(), 1, "{generator_name} should be mono");
826818

827819
// All should have the expected sample rate
828820
assert_eq!(
829821
source.sample_rate(),
830822
TEST_SAMPLE_RATE,
831-
"{} should have correct sample rate",
832-
generator_name
823+
"{generator_name} should have correct sample rate"
833824
);
834825

835826
// All should have infinite duration
836827
assert_eq!(
837828
source.total_duration(),
838829
None,
839-
"{} should have infinite duration",
840-
generator_name
830+
"{generator_name} should have infinite duration"
841831
);
842832

843833
// All should return None for current_span_len (infinite streams)
844834
assert_eq!(
845835
source.current_span_len(),
846836
None,
847-
"{} should have no span length limit",
848-
generator_name
837+
"{generator_name} should have no span length limit"
849838
);
850839
}
851840

@@ -862,8 +851,8 @@ mod tests {
862851
}
863852

864853
// Should use the full range approximately
865-
assert!(min < -0.9, "Min sample should be close to -1.0: {}", min);
866-
assert!(max > 0.9, "Max sample should be close to 1.0: {}", max);
854+
assert!(min < -0.9, "Min sample should be close to -1.0: {min}");
855+
assert!(max > 0.9, "Max sample should be close to 1.0: {max}");
867856
}
868857

869858
#[test]
@@ -905,8 +894,7 @@ mod tests {
905894

906895
assert!(
907896
within_bounds_percentage > 99.0,
908-
"Expected >99% of Gaussian samples within [-1.0, 1.0], got {:.1}%",
909-
within_bounds_percentage
897+
"Expected >99% of Gaussian samples within [-1.0, 1.0], got {within_bounds_percentage:.1}%"
910898
);
911899
}
912900

@@ -927,8 +915,7 @@ mod tests {
927915
// Pink noise should have some positive correlation (though not as strong as Brownian)
928916
assert!(
929917
avg_correlation > -0.1,
930-
"Pink noise should have low positive correlation, got: {}",
931-
avg_correlation
918+
"Pink noise should have low positive correlation, got: {avg_correlation}"
932919
);
933920
}
934921

@@ -949,8 +936,7 @@ mod tests {
949936
// Blue noise should have near-zero or negative correlation
950937
assert!(
951938
avg_correlation < 0.1,
952-
"Blue noise should have low correlation, got: {}",
953-
avg_correlation
939+
"Blue noise should have low correlation, got: {avg_correlation}"
954940
);
955941
}
956942

@@ -980,9 +966,7 @@ mod tests {
980966
// For violet noise (high-pass), differences should have comparable or higher variance
981967
assert!(
982968
diff_variance > signal_variance * 0.1,
983-
"Violet noise should have high-frequency characteristics, diff_var: {}, signal_var: {}",
984-
diff_variance,
985-
signal_variance
969+
"Violet noise should have high-frequency characteristics, diff_var: {diff_variance}, signal_var: {signal_variance}"
986970
);
987971
}
988972

@@ -998,8 +982,7 @@ mod tests {
998982
// Average should be close to zero due to leak factor
999983
assert!(
1000984
average.abs() < 0.5,
1001-
"Brownian noise average too far from zero: {}",
1002-
average
985+
"Brownian noise average too far from zero: {average}"
1003986
);
1004987

1005988
// Brownian noise should have strong positive correlation between consecutive samples
@@ -1011,8 +994,7 @@ mod tests {
1011994

1012995
assert!(
1013996
avg_correlation > 0.1,
1014-
"Brownian noise should have strong positive correlation: {}",
1015-
avg_correlation
997+
"Brownian noise should have strong positive correlation: {avg_correlation}"
1016998
);
1017999
}
10181000

@@ -1033,9 +1015,7 @@ mod tests {
10331015
assert!(
10341016
impulse_count > (VELVET_DEFAULT_DENSITY * 0.75) as usize
10351017
&& impulse_count < (VELVET_DEFAULT_DENSITY * 1.25) as usize,
1036-
"Impulse count out of range: expected ~{}, got {}",
1037-
VELVET_DEFAULT_DENSITY,
1038-
impulse_count
1018+
"Impulse count out of range: expected ~{VELVET_DEFAULT_DENSITY}, got {impulse_count}"
10391019
);
10401020
}
10411021

@@ -1055,9 +1035,7 @@ mod tests {
10551035
let actual_density = impulse_count as f32;
10561036
assert!(
10571037
(actual_density - density).abs() < 200.0,
1058-
"Custom density not achieved: expected ~{}, got {}",
1059-
density,
1060-
actual_density
1038+
"Custom density not achieved: expected ~{density}, got {actual_density}"
10611039
);
10621040
}
10631041
}

0 commit comments

Comments
 (0)