File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -110,6 +110,22 @@ impl SoxResampler {
110110 }
111111
112112 pub fn flush ( & mut self ) -> Result < & [ i16 ] , String > {
113+ let delay = unsafe { soxr_sys:: soxr_delay ( self . soxr_ptr ) } ;
114+ let delay_samples = delay. ceil ( ) as usize ;
115+ if delay_samples == 0 {
116+ let error = unsafe { soxr_sys:: soxr_clear ( self . soxr_ptr ) } ;
117+ if !error. is_null ( ) {
118+ let msg = unsafe { std:: ffi:: CStr :: from_ptr ( error) } ;
119+ return Err ( msg. to_string_lossy ( ) . to_string ( ) ) ;
120+ }
121+ return Ok ( & [ ] ) ;
122+ }
123+
124+ let required_output_size = delay_samples * self . num_channels as usize ;
125+ if self . out_buf . len ( ) < required_output_size {
126+ self . out_buf . resize ( required_output_size, 0 ) ;
127+ }
128+
113129 let mut odone: usize = 0 ;
114130 let error = unsafe {
115131 soxr_sys:: soxr_process (
@@ -118,7 +134,7 @@ impl SoxResampler {
118134 0 ,
119135 std:: ptr:: null_mut ( ) ,
120136 self . out_buf . as_mut_ptr ( ) as * mut c_void ,
121- self . out_buf . len ( ) ,
137+ delay_samples ,
122138 & mut odone,
123139 )
124140 } ;
@@ -134,7 +150,8 @@ impl SoxResampler {
134150 return Err ( error_msg. to_string_lossy ( ) . to_string ( ) ) ;
135151 }
136152
137- Ok ( & self . out_buf [ ..odone] )
153+ let output_samples = odone * self . num_channels as usize ;
154+ Ok ( & self . out_buf [ ..output_samples] )
138155 }
139156}
140157
You can’t perform that action at this time.
0 commit comments