44//! producer/consumer doesn't have to convert to planar on every call.
55//! Currently sample-rate only; channel up/downmix is rejected upstream.
66
7+ use rubato:: audioadapter_buffers:: direct:: SequentialSliceOfVecs ;
78use rubato:: {
8- Resampler as RubatoTrait , SincFixedIn , SincInterpolationParameters , SincInterpolationType , WindowFunction ,
9+ Async , FixedAsync , Resampler as RubatoTrait , SincInterpolationParameters , SincInterpolationType , WindowFunction ,
910} ;
1011
1112use crate :: AudioError ;
1213
1314/// Sample-rate converter over interleaved `f32` PCM.
1415pub struct Resampler {
15- resampler : SincFixedIn < f32 > ,
16+ resampler : Async < f32 > ,
1617 chunk_frames : usize ,
1718 channels : usize ,
1819 input_planar : Vec < Vec < f32 > > ,
1920 output_planar : Vec < Vec < f32 > > ,
21+ output_frames_max : usize ,
2022 pending : Vec < f32 > ,
2123}
2224
@@ -39,23 +41,26 @@ impl Resampler {
3941 oversampling_factor : 128 ,
4042 window : WindowFunction :: BlackmanHarris2 ,
4143 } ;
42- let resampler = SincFixedIn :: < f32 > :: new (
44+ let resampler = Async :: < f32 > :: new_sinc (
4345 output_rate as f64 / input_rate as f64 ,
4446 1.0 ,
45- params,
47+ & params,
4648 chunk_frames,
4749 channels as usize ,
50+ FixedAsync :: Input ,
4851 ) ?;
4952
5053 let input_planar = ( 0 ..channels as usize ) . map ( |_| vec ! [ 0.0f32 ; chunk_frames] ) . collect ( ) ;
51- let output_planar = resampler. output_buffer_allocate ( true ) ;
54+ let output_frames_max = resampler. output_frames_max ( ) ;
55+ let output_planar = vec ! [ vec![ 0.0f32 ; output_frames_max] ; channels as usize ] ;
5256
5357 Ok ( Self {
5458 resampler,
5559 chunk_frames,
5660 channels : channels as usize ,
5761 input_planar,
5862 output_planar,
63+ output_frames_max,
5964 pending : Vec :: new ( ) ,
6065 } )
6166 }
@@ -83,9 +88,12 @@ impl Resampler {
8388 }
8489 }
8590
86- let ( _, produced) =
87- self . resampler
88- . process_into_buffer ( & self . input_planar , & mut self . output_planar , None ) ?;
91+ let input = SequentialSliceOfVecs :: new ( & self . input_planar , self . channels , self . chunk_frames )
92+ . expect ( "resampler input buffer dimensions" ) ;
93+ let mut output =
94+ SequentialSliceOfVecs :: new_mut ( & mut self . output_planar , self . channels , self . output_frames_max )
95+ . expect ( "resampler output buffer dimensions" ) ;
96+ let ( _, produced) = self . resampler . process_into_buffer ( & input, & mut output, None ) ?;
8997
9098 let prev_len = out. len ( ) ;
9199 out. resize ( prev_len + produced * self . channels , 0.0 ) ;
0 commit comments