11use std:: sync:: Arc ;
22
33use cpal:: traits:: { DeviceTrait , StreamTrait } ;
4- use cpal:: { SampleFormat , Stream } ;
4+ use cpal:: { Sample , SampleFormat , Stream } ;
55use rubato:: {
66 Resampler , SincFixedOut , SincInterpolationParameters , SincInterpolationType , WindowFunction ,
77 calculate_cutoff,
@@ -519,7 +519,7 @@ fn build_output_stream(
519519 selected_sr,
520520 & shared,
521521 & mut render_state,
522- |x| ( x * i16:: MAX as f32 ) as i16 ,
522+ |x| < i16 as Sample > :: from_sample ( x ) ,
523523 ) ;
524524 } ,
525525 err_fn,
@@ -538,7 +538,45 @@ fn build_output_stream(
538538 selected_sr,
539539 & shared,
540540 & mut render_state,
541- |x| ( ( x * 0.5 + 0.5 ) * u16:: MAX as f32 ) as u16 ,
541+ |x| <u16 as Sample >:: from_sample ( x) ,
542+ ) ;
543+ } ,
544+ err_fn,
545+ None ,
546+ )
547+ }
548+ SampleFormat :: I24 => {
549+ let shared = Arc :: clone ( shared) ;
550+ let mut render_state = RenderState :: default ( ) ;
551+ device. build_output_stream (
552+ & config,
553+ move |data : & mut [ cpal:: I24 ] , _| {
554+ fill_output (
555+ data,
556+ output_channels,
557+ selected_sr,
558+ & shared,
559+ & mut render_state,
560+ |x| <cpal:: I24 as Sample >:: from_sample ( x) ,
561+ ) ;
562+ } ,
563+ err_fn,
564+ None ,
565+ )
566+ }
567+ SampleFormat :: U24 => {
568+ let shared = Arc :: clone ( shared) ;
569+ let mut render_state = RenderState :: default ( ) ;
570+ device. build_output_stream (
571+ & config,
572+ move |data : & mut [ cpal:: U24 ] , _| {
573+ fill_output (
574+ data,
575+ output_channels,
576+ selected_sr,
577+ & shared,
578+ & mut render_state,
579+ |x| <cpal:: U24 as Sample >:: from_sample ( x) ,
542580 ) ;
543581 } ,
544582 err_fn,
0 commit comments