@@ -125,22 +125,28 @@ impl AtomicF64 {
125
125
/// voice based applications, e.g. see phone bandwidth) and 96000Hz (for very high
126
126
/// quality audio applications and spectrum manipulation).
127
127
/// Most common sample rates for musical applications are 44100 and 48000.
128
- /// - see <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer-samplerate>
128
+ ///
129
+ /// - see <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-samplerate>
130
+ /// > An implementation MUST support sample rates in at least the range 8000 to 96000.
129
131
///
130
132
/// # Panics
131
133
///
132
134
/// This function will panic if:
133
- /// - the given sample rate is zero
135
+ /// - the given sample rate is lower than 4000 or greater than 192000
134
136
///
135
137
#[ track_caller]
136
138
#[ inline( always) ]
137
139
pub ( crate ) fn assert_valid_sample_rate ( sample_rate : f32 ) {
140
+ let min_sample_rate = 4_000. ;
141
+ let max_sample_rate = 192_000. ;
138
142
// 1000 Hertz is a just a random cutoff, but it helps a if someone accidentally puts a
139
143
// timestamp in the sample_rate variable
140
144
assert ! (
141
- sample_rate > 1000. ,
142
- "NotSupportedError - Invalid sample rate: {:?}, should be greater than 1000" ,
143
- sample_rate
145
+ sample_rate >= min_sample_rate && sample_rate <= max_sample_rate,
146
+ "NotSupportedError - Invalid sample rate: {:?}, should be in the range [{:?}, {:?}]" ,
147
+ sample_rate,
148
+ min_sample_rate,
149
+ max_sample_rate,
144
150
) ;
145
151
}
146
152
@@ -228,20 +234,14 @@ mod tests {
228
234
229
235
#[ test]
230
236
#[ should_panic]
231
- fn test_invalid_sample_rate_zero ( ) {
232
- assert_valid_sample_rate ( 0. ) ;
233
- }
234
-
235
- #[ test]
236
- #[ should_panic]
237
- fn test_invalid_sample_rate_subzero ( ) {
238
- assert_valid_sample_rate ( -48000. ) ;
237
+ fn test_invalid_sample_rate_too_small ( ) {
238
+ assert_valid_sample_rate ( 3_000. ) ;
239
239
}
240
240
241
241
#[ test]
242
242
#[ should_panic]
243
- fn test_invalid_sample_rate_too_small ( ) {
244
- assert_valid_sample_rate ( 100 .) ;
243
+ fn test_invalid_sample_rate_too_big ( ) {
244
+ assert_valid_sample_rate ( 300_000 .) ;
245
245
}
246
246
247
247
#[ test]
0 commit comments