Skip to content

Commit e47684a

Browse files
committed
style: format doc comments and improve test formatting for clarity
1 parent de9deb8 commit e47684a

File tree

2 files changed

+85
-68
lines changed

2 files changed

+85
-68
lines changed

src/source/limit.rs

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -192,29 +192,29 @@ impl LimitSettings {
192192
}
193193

194194
/// Creates settings optimized for dynamic content like music and sound effects.
195-
///
195+
///
196196
/// Designed for content with varying dynamics where you want to preserve
197197
/// the natural feel while preventing occasional peaks from clipping.
198-
///
198+
///
199199
/// # Configuration
200-
///
200+
///
201201
/// - **Threshold**: -3.0 dBFS (more headroom than default)
202202
/// - **Knee width**: 6.0 dB (wide, transparent transition)
203203
/// - **Attack**: 5 ms (default, balanced response)
204204
/// - **Release**: 100 ms (default, smooth recovery)
205-
///
205+
///
206206
/// # Use Cases
207-
///
207+
///
208208
/// - Music playback with occasional loud peaks
209209
/// - Sound effects that need natural dynamics
210210
/// - Content where transparency is more important than tight control
211211
/// - Game audio with varying intensity levels
212-
///
212+
///
213213
/// # Examples
214-
///
214+
///
215215
/// ```
216216
/// use rodio::source::{SineWave, Source, LimitSettings};
217-
///
217+
///
218218
/// let music = SineWave::new(440.0).amplify(1.5);
219219
/// let limited = music.limit(LimitSettings::dynamic_content());
220220
/// ```
@@ -226,30 +226,30 @@ impl LimitSettings {
226226
}
227227

228228
/// Creates settings optimized for broadcast and streaming applications.
229-
///
229+
///
230230
/// Designed for consistent loudness and reliable peak control in scenarios
231231
/// where clipping absolutely cannot occur and consistent levels are critical.
232-
///
232+
///
233233
/// # Configuration
234-
///
234+
///
235235
/// - **Threshold**: -1.0 dBFS (default, tight control)
236236
/// - **Knee width**: 2.0 dB (narrower, more decisive limiting)
237237
/// - **Attack**: 3 ms (faster response to catch transients)
238238
/// - **Release**: 50 ms (faster recovery for consistent levels)
239-
///
239+
///
240240
/// # Use Cases
241-
///
241+
///
242242
/// - Live streaming where clipping would be catastrophic
243243
/// - Broadcast audio that must meet loudness standards
244244
/// - Voice chat applications requiring consistent levels
245245
/// - Podcast production for consistent listening experience
246246
/// - Game voice communication systems
247-
///
247+
///
248248
/// # Examples
249-
///
249+
///
250250
/// ```
251251
/// use rodio::source::{SineWave, Source, LimitSettings};
252-
///
252+
///
253253
/// let voice_chat = SineWave::new(440.0).amplify(2.0);
254254
/// let limited = voice_chat.limit(LimitSettings::broadcast());
255255
/// ```
@@ -262,116 +262,116 @@ impl LimitSettings {
262262
}
263263

264264
/// Creates settings optimized for mastering and final audio production.
265-
///
265+
///
266266
/// Designed for the final stage of audio production where tight peak control
267267
/// is needed while maintaining audio quality and preventing any clipping.
268-
///
268+
///
269269
/// # Configuration
270-
///
270+
///
271271
/// - **Threshold**: -0.5 dBFS (very tight, maximum loudness)
272272
/// - **Knee width**: 1.0 dB (narrow, precise control)
273273
/// - **Attack**: 1 ms (very fast, catches all transients)
274274
/// - **Release**: 200 ms (slower, maintains natural envelope)
275-
///
275+
///
276276
/// # Use Cases
277-
///
277+
///
278278
/// - Final mastering stage for tight peak control
279279
/// - Preparing audio for streaming platforms (after loudness processing)
280280
/// - Album mastering where consistent peak levels are critical
281281
/// - Audio post-production for film/video
282-
///
282+
///
283283
/// # Examples
284-
///
284+
///
285285
/// ```
286286
/// use rodio::source::{SineWave, Source, LimitSettings};
287-
///
287+
///
288288
/// let master_track = SineWave::new(440.0).amplify(3.0);
289289
/// let mastered = master_track.limit(LimitSettings::mastering());
290290
/// ```
291291
#[inline]
292292
pub fn mastering() -> Self {
293293
Self {
294-
threshold: -0.5, // Very tight for peak control
295-
knee_width: 1.0, // Narrow knee for precise control
296-
attack: Duration::from_millis(1), // Very fast attack
297-
release: Duration::from_millis(200), // Slower release for natural envelope
294+
threshold: -0.5, // Very tight for peak control
295+
knee_width: 1.0, // Narrow knee for precise control
296+
attack: Duration::from_millis(1), // Very fast attack
297+
release: Duration::from_millis(200), // Slower release for natural envelope
298298
}
299299
}
300300

301301
/// Creates settings optimized for live performance and real-time applications.
302-
///
302+
///
303303
/// Designed for scenarios where low latency is critical and the limiter
304304
/// must respond quickly to protect equipment and audiences.
305-
///
305+
///
306306
/// # Configuration
307-
///
307+
///
308308
/// - **Threshold**: -2.0 dBFS (some headroom for safety)
309309
/// - **Knee width**: 3.0 dB (moderate, good compromise)
310310
/// - **Attack**: 0.5 ms (extremely fast for protection)
311311
/// - **Release**: 30 ms (fast recovery for live feel)
312-
///
312+
///
313313
/// # Use Cases
314-
///
314+
///
315315
/// - Live concert sound reinforcement
316316
/// - DJ mixing and live electronic music
317317
/// - Real-time audio processing where latency matters
318318
/// - Equipment protection in live settings
319319
/// - Interactive audio applications and games
320-
///
320+
///
321321
/// # Examples
322-
///
322+
///
323323
/// ```
324324
/// use rodio::source::{SineWave, Source, LimitSettings};
325-
///
325+
///
326326
/// let live_input = SineWave::new(440.0).amplify(2.5);
327327
/// let protected = live_input.limit(LimitSettings::live_performance());
328328
/// ```
329329
#[inline]
330330
pub fn live_performance() -> Self {
331331
Self {
332-
threshold: -2.0, // Some headroom for safety
333-
knee_width: 3.0, // Moderate knee
334-
attack: Duration::from_micros(500), // Extremely fast for protection
335-
release: Duration::from_millis(30), // Fast recovery for live feel
332+
threshold: -2.0, // Some headroom for safety
333+
knee_width: 3.0, // Moderate knee
334+
attack: Duration::from_micros(500), // Extremely fast for protection
335+
release: Duration::from_millis(30), // Fast recovery for live feel
336336
}
337337
}
338338

339339
/// Creates settings optimized for gaming and interactive audio.
340-
///
340+
///
341341
/// Designed for games where audio levels can vary dramatically between
342342
/// quiet ambient sounds and loud action sequences, requiring responsive
343343
/// limiting that maintains immersion.
344-
///
344+
///
345345
/// # Configuration
346-
///
346+
///
347347
/// - **Threshold**: -3.0 dBFS (balanced headroom for dynamic range)
348348
/// - **Knee width**: 3.0 dB (moderate transition for natural feel)
349349
/// - **Attack**: 2 ms (fast enough for sound effects, not harsh)
350350
/// - **Release**: 75 ms (quick recovery for interactive responsiveness)
351-
///
351+
///
352352
/// # Use Cases
353-
///
353+
///
354354
/// - Game audio mixing for consistent player experience
355355
/// - Interactive audio applications requiring dynamic response
356356
/// - VR/AR audio where sudden loud sounds could be jarring
357357
/// - Mobile games needing battery-efficient processing
358358
/// - Streaming gameplay audio for viewers
359-
///
359+
///
360360
/// # Examples
361-
///
361+
///
362362
/// ```
363363
/// use rodio::source::{SineWave, Source, LimitSettings};
364-
///
364+
///
365365
/// let game_audio = SineWave::new(440.0).amplify(2.0);
366366
/// let limited = game_audio.limit(LimitSettings::gaming());
367367
/// ```
368368
#[inline]
369369
pub fn gaming() -> Self {
370370
Self {
371-
threshold: -3.0, // Balanced headroom for dynamics
372-
knee_width: 3.0, // Moderate for natural feel
373-
attack: Duration::from_millis(2), // Fast but not harsh
374-
release: Duration::from_millis(75), // Quick for interactivity
371+
threshold: -3.0, // Balanced headroom for dynamics
372+
knee_width: 3.0, // Moderate for natural feel
373+
attack: Duration::from_millis(2), // Fast but not harsh
374+
release: Duration::from_millis(75), // Quick for interactivity
375375
}
376376
}
377377

tests/limit.rs

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,16 @@ fn test_limiter_with_different_settings() {
100100
assert!(
101101
peak <= expected_peak + 0.1,
102102
"Threshold {}dB: peak {:.3} should be ≤ {:.3}",
103-
threshold_db, peak, expected_peak + 0.1
103+
threshold_db,
104+
peak,
105+
expected_peak + 0.1
104106
);
105107
assert!(
106108
peak >= expected_peak - 0.1,
107109
"Threshold {}dB: peak {:.3} should be ≥ {:.3}",
108-
threshold_db, peak, expected_peak - 0.1
110+
threshold_db,
111+
peak,
112+
expected_peak - 0.1
109113
);
110114
}
111115
}
@@ -114,33 +118,46 @@ fn test_limiter_with_different_settings() {
114118
fn test_limiter_stereo_processing() {
115119
// Test that stereo limiting works correctly
116120
use rodio::buffer::SamplesBuffer;
117-
121+
118122
// Create stereo test signal - left channel louder than right
119-
let left_samples = (0..1000).map(|i| (i as f32 * 0.01).sin() * 1.5).collect::<Vec<_>>();
120-
let right_samples = (0..1000).map(|i| (i as f32 * 0.01).sin() * 0.8).collect::<Vec<_>>();
121-
123+
let left_samples = (0..1000)
124+
.map(|i| (i as f32 * 0.01).sin() * 1.5)
125+
.collect::<Vec<_>>();
126+
let right_samples = (0..1000)
127+
.map(|i| (i as f32 * 0.01).sin() * 0.8)
128+
.collect::<Vec<_>>();
129+
122130
let mut stereo_samples = Vec::new();
123131
for i in 0..1000 {
124132
stereo_samples.push(left_samples[i]);
125133
stereo_samples.push(right_samples[i]);
126134
}
127-
135+
128136
let buffer = SamplesBuffer::new(2, 44100, stereo_samples);
129-
let settings = rodio::source::LimitSettings::default()
130-
.with_threshold(-3.0);
131-
137+
let settings = rodio::source::LimitSettings::default().with_threshold(-3.0);
138+
132139
let limiter = buffer.limit(settings);
133140
let limited_samples: Vec<f32> = limiter.collect();
134-
141+
135142
// Extract left and right channels after limiting
136143
let limited_left: Vec<f32> = limited_samples.iter().step_by(2).cloned().collect();
137144
let limited_right: Vec<f32> = limited_samples.iter().skip(1).step_by(2).cloned().collect();
138-
145+
139146
let left_peak = limited_left.iter().fold(0.0f32, |acc, &x| acc.max(x.abs()));
140-
let right_peak = limited_right.iter().fold(0.0f32, |acc, &x| acc.max(x.abs()));
141-
147+
let right_peak = limited_right
148+
.iter()
149+
.fold(0.0f32, |acc, &x| acc.max(x.abs()));
150+
142151
// Both channels should be limited to approximately the same level
143152
// (limiter should prevent the louder channel from exceeding threshold)
144-
assert!(left_peak <= 1.5, "Left channel should be limited: {:.3}", left_peak);
145-
assert!(right_peak <= 1.5, "Right channel should be limited: {:.3}", right_peak);
153+
assert!(
154+
left_peak <= 1.5,
155+
"Left channel should be limited: {:.3}",
156+
left_peak
157+
);
158+
assert!(
159+
right_peak <= 1.5,
160+
"Right channel should be limited: {:.3}",
161+
right_peak
162+
);
146163
}

0 commit comments

Comments
 (0)