1- use crate :: { Data , InputCallbackInfo , OutputCallbackInfo , Sample , SampleFormat } ;
1+ use crate :: { Data , FrameCount , InputCallbackInfo , OutputCallbackInfo , Sample , SampleFormat } ;
22
33/// When given an input data callback that expects samples in the specified sample format, return
44/// an input data callback that expects samples in the I16 sample format. The `buffer_size` is in
55/// samples.
66pub ( super ) fn input_adapter_callback < D > (
77 mut original_data_callback : D ,
8- buffer_size : usize ,
8+ buffer_size : FrameCount ,
99 sample_format : SampleFormat ,
1010) -> Box < dyn FnMut ( & Data , & InputCallbackInfo ) + Send + ' static >
1111where
1818 }
1919 SampleFormat :: F32 => {
2020 // Make the backing buffer for the Data used in the closure.
21- let mut adapted_buf = vec ! [ 0f32 ] . repeat ( buffer_size) ;
21+ let mut adapted_buf = vec ! [ 0f32 ] . repeat ( buffer_size as usize ) ;
2222 Box :: new ( move |data : & Data , info : & InputCallbackInfo | {
2323 let data_slice: & [ i16 ] = data. as_slice ( ) . unwrap ( ) ; // unwrap OK because data is always i16
2424 let adapted_slice = & mut adapted_buf;
@@ -32,15 +32,15 @@ where
3232 let adapted_data = unsafe {
3333 Data :: from_parts (
3434 adapted_buf. as_mut_ptr ( ) as * mut _ ,
35- buffer_size,
35+ buffer_size as usize , // TODO: this is converting a FrameCount to a number of samples; invalid for stereo!
3636 sample_format,
3737 )
3838 } ;
3939 original_data_callback ( & adapted_data, info) ;
4040 } )
4141 }
4242 SampleFormat :: U16 => {
43- let mut adapted_buf = vec ! [ 0u16 ] . repeat ( buffer_size) ;
43+ let mut adapted_buf = vec ! [ 0u16 ] . repeat ( buffer_size as usize ) ;
4444 Box :: new ( move |data : & Data , info : & InputCallbackInfo | {
4545 let data_slice: & [ i16 ] = data. as_slice ( ) . unwrap ( ) ; // unwrap OK because data is always i16
4646 let adapted_slice = & mut adapted_buf;
5454 let adapted_data = unsafe {
5555 Data :: from_parts (
5656 adapted_buf. as_mut_ptr ( ) as * mut _ ,
57- buffer_size,
57+ buffer_size as usize , // TODO: this is converting a FrameCount to a number of samples; invalid for stereo!
5858 sample_format,
5959 )
6060 } ;
6969/// sample format. The `buffer_size` is in samples.
7070pub ( super ) fn output_adapter_callback < D > (
7171 mut original_data_callback : D ,
72- buffer_size : usize ,
72+ buffer_size : FrameCount ,
7373 sample_format : SampleFormat ,
7474) -> Box < dyn FnMut ( & mut Data , & OutputCallbackInfo ) + Send + ' static >
7575where
@@ -82,15 +82,15 @@ where
8282 }
8383 SampleFormat :: F32 => {
8484 // Make the backing buffer for the Data used in the closure.
85- let mut adapted_buf = vec ! [ 0f32 ] . repeat ( buffer_size) ;
85+ let mut adapted_buf = vec ! [ 0f32 ] . repeat ( buffer_size as usize ) ;
8686
8787 Box :: new ( move |data : & mut Data , info : & OutputCallbackInfo | {
8888 // Note: we construct adapted_data here instead of in the parent function because
8989 // adapted_buf needs to be owned by the closure.
9090 let mut adapted_data = unsafe {
9191 Data :: from_parts (
9292 adapted_buf. as_mut_ptr ( ) as * mut _ ,
93- buffer_size,
93+ buffer_size as usize , // TODO: this is converting a FrameCount to a number of samples; invalid for stereo!
9494 sample_format,
9595 )
9696 } ;
@@ -108,15 +108,15 @@ where
108108 }
109109 SampleFormat :: U16 => {
110110 // Make the backing buffer for the Data used in the closure.
111- let mut adapted_buf = vec ! [ 0u16 ] . repeat ( buffer_size) ;
111+ let mut adapted_buf = vec ! [ 0u16 ] . repeat ( buffer_size as usize ) ;
112112
113113 Box :: new ( move |data : & mut Data , info : & OutputCallbackInfo | {
114114 // Note: we construct adapted_data here instead of in the parent function because
115115 // adapted_buf needs to be owned by the closure.
116116 let mut adapted_data = unsafe {
117117 Data :: from_parts (
118118 adapted_buf. as_mut_ptr ( ) as * mut _ ,
119- buffer_size,
119+ buffer_size as usize , // TODO: this is converting a FrameCount to a number of samples; invalid for stereo!
120120 sample_format,
121121 )
122122 } ;
0 commit comments