@@ -60,9 +60,9 @@ fn assert_valid_smoothing_time_constant(smoothing_time_constant: f64) {
60
60
}
61
61
}
62
62
63
- // [spec] If the value of this attribute is set to a value more than or equal
64
- // to maxDecibels, an IndexSizeError exception MUST be thrown.
65
- fn assert_valid_min_decibels ( min_decibels : f64 , max_decibels : f64 ) {
63
+ // [spec] If the value of minDecibels is set to a value more than or equal to maxDecibels, an
64
+ // IndexSizeError exception MUST be thrown.
65
+ fn assert_valid_decibels ( min_decibels : f64 , max_decibels : f64 ) {
66
66
if min_decibels >= max_decibels {
67
67
panic ! (
68
68
"IndexSizeError - Invalid min decibels: {:?} is greater than or equals to max decibels {:?}" ,
@@ -71,17 +71,6 @@ fn assert_valid_min_decibels(min_decibels: f64, max_decibels: f64) {
71
71
}
72
72
}
73
73
74
- // [spec] If the value of this attribute is set to a value less than or equal to
75
- // minDecibels, an IndexSizeError exception MUST be thrown.
76
- fn assert_valid_max_decibels ( max_decibels : f64 , min_decibels : f64 ) {
77
- if max_decibels <= min_decibels {
78
- panic ! (
79
- "IndexSizeError - Invalid max decibels: {:?} is lower than or equals to min decibels {:?}" ,
80
- max_decibels, min_decibels
81
- ) ;
82
- }
83
- }
84
-
85
74
// as the queue is composed of AtomicF32 having only 1 render quantum of extra
86
75
// room should be enough
87
76
const RING_BUFFER_SIZE : usize = MAX_FFT_SIZE + RENDER_QUANTUM_SIZE ;
@@ -237,18 +226,16 @@ impl Analyser {
237
226
self . min_decibels
238
227
}
239
228
240
- pub fn set_min_decibels ( & mut self , value : f64 ) {
241
- assert_valid_min_decibels ( value, self . max_decibels ( ) ) ;
242
- self . min_decibels = value;
243
- }
244
-
245
229
pub fn max_decibels ( & self ) -> f64 {
246
230
self . max_decibels
247
231
}
248
232
249
- pub fn set_max_decibels ( & mut self , value : f64 ) {
250
- assert_valid_max_decibels ( value, self . min_decibels ( ) ) ;
251
- self . max_decibels = value;
233
+ pub fn set_decibels ( & mut self , min : f64 , max : f64 ) {
234
+ // set them together to avoid invalid intermediate min/max combinations
235
+ assert_valid_decibels ( min, max) ;
236
+
237
+ self . min_decibels = min;
238
+ self . min_decibels = max;
252
239
}
253
240
254
241
pub fn frequency_bin_count ( & self ) -> usize {
@@ -636,14 +623,14 @@ mod tests {
636
623
#[ should_panic]
637
624
fn test_min_decibels_constraints_lt_max_decibels ( ) {
638
625
let mut analyser = Analyser :: new ( ) ;
639
- analyser. set_min_decibels ( DEFAULT_MAX_DECIBELS ) ;
626
+ analyser. set_decibels ( DEFAULT_MAX_DECIBELS , analyser . max_decibels ( ) ) ;
640
627
}
641
628
642
629
#[ test]
643
630
#[ should_panic]
644
631
fn test_max_decibels_constraints_lt_min_decibels ( ) {
645
632
let mut analyser = Analyser :: new ( ) ;
646
- analyser. set_max_decibels ( DEFAULT_MIN_DECIBELS ) ;
633
+ analyser. set_decibels ( analyser . min_decibels ( ) , DEFAULT_MIN_DECIBELS ) ;
647
634
}
648
635
649
636
#[ test]
0 commit comments