44//! to configure audio limiting parameters.
55
66use rodio:: source:: { LimitSettings , SineWave , Source } ;
7+ use rodio:: Sample ;
78use std:: time:: Duration ;
89
910fn main ( ) {
@@ -39,11 +40,11 @@ fn main() {
3940 let limited_wave = sine_wave. limit ( LimitSettings :: default ( ) ) ;
4041
4142 // Collect some samples to demonstrate
42- let samples: Vec < f32 > = limited_wave. take ( 100 ) . collect ( ) ;
43+ let samples: Vec < Sample > = limited_wave. take ( 100 ) . collect ( ) ;
4344 println ! ( " Generated {} limited samples" , samples. len( ) ) ;
4445
4546 // Show peak reduction
46- let max_sample = samples. iter ( ) . fold ( 0.0f32 , |acc, & x| acc. max ( x. abs ( ) ) ) ;
47+ let max_sample: Sample = samples. iter ( ) . fold ( 0.0 , |acc, & x| acc. max ( x. abs ( ) ) ) ;
4748 println ! ( " Peak amplitude after limiting: {max_sample:.3}" ) ;
4849 println ! ( ) ;
4950
@@ -56,7 +57,7 @@ fn main() {
5657
5758 // Apply the custom settings from Example 2
5859 let custom_limited = sine_wave2. limit ( custom_limiting) ;
59- let custom_samples: Vec < f32 > = custom_limited. take ( 50 ) . collect ( ) ;
60+ let custom_samples: Vec < Sample > = custom_limited. take ( 50 ) . collect ( ) ;
6061 println ! (
6162 " Generated {} samples with custom settings" ,
6263 custom_samples. len( )
@@ -101,7 +102,7 @@ fn main() {
101102 println ! ( "Example 6: Limiting with -6dB threshold" ) ;
102103
103104 // Create a sine wave that will definitely trigger limiting
104- const AMPLITUDE : f32 = 2.5 ; // High amplitude to ensure limiting occurs
105+ const AMPLITUDE : Sample = 2.5 ; // High amplitude to ensure limiting occurs
105106 let test_sine = SineWave :: new ( 440.0 )
106107 . amplify ( AMPLITUDE )
107108 . take_duration ( Duration :: from_millis ( 100 ) ) ; // 100ms = ~4410 samples
@@ -114,24 +115,24 @@ fn main() {
114115 . with_release ( Duration :: from_millis ( 12 ) ) ; // Moderate release
115116
116117 let limited_sine = test_sine. limit ( strict_limiting. clone ( ) ) ;
117- let test_samples: Vec < f32 > = limited_sine. take ( 4410 ) . collect ( ) ;
118+ let test_samples: Vec < Sample > = limited_sine. take ( 4410 ) . collect ( ) ;
118119
119120 // Analyze peaks at different time periods
120- let early_peak = test_samples[ 0 ..500 ]
121+ let early_peak: Sample = test_samples[ 0 ..500 ]
121122 . iter ( )
122- . fold ( 0.0f32 , |acc, & x| acc. max ( x. abs ( ) ) ) ;
123- let mid_peak = test_samples[ 1000 ..1500 ]
123+ . fold ( 0.0 , |acc, & x| acc. max ( x. abs ( ) ) ) ;
124+ let mid_peak: Sample = test_samples[ 1000 ..1500 ]
124125 . iter ( )
125- . fold ( 0.0f32 , |acc, & x| acc. max ( x. abs ( ) ) ) ;
126- let settled_peak = test_samples[ 2000 ..]
126+ . fold ( 0.0 , |acc, & x| acc. max ( x. abs ( ) ) ) ;
127+ let settled_peak: Sample = test_samples[ 2000 ..]
127128 . iter ( )
128- . fold ( 0.0f32 , |acc, & x| acc. max ( x. abs ( ) ) ) ;
129+ . fold ( 0.0 , |acc, & x| acc. max ( x. abs ( ) ) ) ;
129130
130131 // With -6dB threshold, ALL samples are well below 1.0!
131- let target_linear = 10.0_f32 . powf ( strict_limiting. threshold / 20.0 ) ;
132- let max_settled = test_samples[ 2000 ..]
132+ let target_linear = ( 10.0 as Sample ) . powf ( strict_limiting. threshold / 20.0 ) ;
133+ let max_settled: Sample = test_samples[ 2000 ..]
133134 . iter ( )
134- . fold ( 0.0f32 , |acc, & x| acc. max ( x. abs ( ) ) ) ;
135+ . fold ( 0.0 , |acc, & x| acc. max ( x. abs ( ) ) ) ;
135136
136137 println ! (
137138 " {}dB threshold limiting results:" ,
0 commit comments