@@ -143,6 +143,12 @@ fn main() {
143143 . action ( ArgAction :: SetTrue )
144144 . help ( "Enables Variable Bit Rate (VBR)" ) ,
145145 )
146+ . arg (
147+ Arg :: new ( "resample" )
148+ . long ( "resample" )
149+ . short ( 'r' )
150+ . help ( "Sets the target sample rate for resampling" ) ,
151+ )
146152 . get_matches ( ) ;
147153
148154 let settings = get_encoder_settings ( & matches) ;
@@ -165,12 +171,38 @@ fn main() {
165171 std:: process:: exit ( 1 ) ;
166172 } ) ;
167173
174+ let mut samples = input_wave. samples ;
175+ let mut sample_rate = input_wave. sample_rate ;
176+
177+ if let Some ( target_rate_str) = matches. get_one :: < String > ( "resample" ) {
178+ let target_rate = target_rate_str. parse :: < u32 > ( ) . unwrap_or_else ( |_| {
179+ eprintln ! ( "Error: Failed to parse resample rate" ) ;
180+ std:: process:: exit ( 1 ) ;
181+ } ) ;
182+
183+ #[ cfg( feature = "resample" ) ]
184+ {
185+ samples = sea_codec:: resample:: resample (
186+ & samples,
187+ sample_rate,
188+ target_rate,
189+ input_wave. channels as u32 ,
190+ ) ;
191+ sample_rate = target_rate;
192+ }
193+ #[ cfg( not( feature = "resample" ) ) ]
194+ {
195+ eprintln ! ( "Error: Resampling feature is not enabled. Recompile with --features resample" ) ;
196+ std:: process:: exit ( 1 ) ;
197+ }
198+ }
199+
168200 let mut sea_encoder = SeaEncoder :: from_slice (
169201 input_wave. channels as u8 ,
170- input_wave . sample_rate ,
171- Some ( input_wave . samples . len ( ) as u32 / input_wave. channels ) ,
202+ sample_rate,
203+ Some ( samples. len ( ) as u32 / input_wave. channels as u32 ) ,
172204 settings,
173- & input_wave . samples ,
205+ & samples,
174206 )
175207 . unwrap_or_else ( |_| {
176208 eprintln ! ( "Error: Failed to create encoder" ) ;
@@ -215,11 +247,36 @@ fn main() {
215247 { }
216248
217249 let info = sea_decoder. get_header ( ) ;
250+ let mut samples = sea_decoded;
251+ let mut sample_rate = info. sample_rate ;
252+
253+ if let Some ( target_rate_str) = matches. get_one :: < String > ( "resample" ) {
254+ let target_rate = target_rate_str. parse :: < u32 > ( ) . unwrap_or_else ( |_| {
255+ eprintln ! ( "Error: Failed to parse resample rate" ) ;
256+ std:: process:: exit ( 1 ) ;
257+ } ) ;
258+
259+ #[ cfg( feature = "resample" ) ]
260+ {
261+ samples = sea_codec:: resample:: resample (
262+ & samples,
263+ sample_rate,
264+ target_rate,
265+ info. channels as u32 ,
266+ ) ;
267+ sample_rate = target_rate;
268+ }
269+ #[ cfg( not( feature = "resample" ) ) ]
270+ {
271+ eprintln ! ( "Error: Resampling feature is not enabled. Recompile with --features resample" ) ;
272+ std:: process:: exit ( 1 ) ;
273+ }
274+ }
218275
219276 write_wav (
220- sea_decoded . as_slice ( ) ,
277+ samples . as_slice ( ) ,
221278 info. channels as u16 ,
222- info . sample_rate ,
279+ sample_rate,
223280 output,
224281 )
225282 . unwrap_or_else ( |_| {
0 commit comments