@@ -20,14 +20,15 @@ use self::alsa::poll::Descriptors;
2020pub use self :: enumerate:: Devices ;
2121
2222use crate :: {
23+ host:: fill_with_equilibrium,
2324 iter:: { SupportedInputConfigs , SupportedOutputConfigs } ,
2425 traits:: { DeviceTrait , HostTrait , StreamTrait } ,
2526 BackendSpecificError , BufferSize , BuildStreamError , ChannelCount , Data ,
2627 DefaultStreamConfigError , DeviceDescription , DeviceDescriptionBuilder , DeviceDirection ,
2728 DeviceId , DeviceIdError , DeviceNameError , DevicesError , FrameCount , InputCallbackInfo ,
28- OutputCallbackInfo , PauseStreamError , PlayStreamError , Sample , SampleFormat , SampleRate ,
29- StreamConfig , StreamError , SupportedBufferSize , SupportedStreamConfig ,
30- SupportedStreamConfigRange , SupportedStreamConfigsError , I24 , U24 ,
29+ OutputCallbackInfo , PauseStreamError , PlayStreamError , SampleFormat , SampleRate , StreamConfig ,
30+ StreamError , SupportedBufferSize , SupportedStreamConfig , SupportedStreamConfigRange ,
31+ SupportedStreamConfigsError ,
3132} ;
3233
3334mod enumerate;
@@ -1239,59 +1240,6 @@ fn hw_params_buffer_size_min_max(hw_params: &alsa::pcm::HwParams) -> (FrameCount
12391240 ( min_buf, max_buf)
12401241}
12411242
1242- // Fill a buffer with equilibrium values for any sample format.
1243- // Works with any buffer size, even if not perfectly aligned to sample boundaries.
1244- fn fill_with_equilibrium ( buffer : & mut [ u8 ] , sample_format : SampleFormat ) {
1245- macro_rules! fill_typed {
1246- ( $sample_type: ty) => { {
1247- let sample_size = std:: mem:: size_of:: <$sample_type>( ) ;
1248-
1249- assert_eq!(
1250- buffer. len( ) % sample_size,
1251- 0 ,
1252- "Buffer size must be aligned to sample size for format {:?}" ,
1253- sample_format
1254- ) ;
1255-
1256- let num_samples = buffer. len( ) / sample_size;
1257- let equilibrium = <$sample_type as Sample >:: EQUILIBRIUM ;
1258-
1259- // Safety: We verified the buffer size is correctly aligned for the sample type
1260- let samples = unsafe {
1261- std:: slice:: from_raw_parts_mut(
1262- buffer. as_mut_ptr( ) as * mut $sample_type,
1263- num_samples,
1264- )
1265- } ;
1266-
1267- for sample in samples {
1268- * sample = equilibrium;
1269- }
1270- } } ;
1271- }
1272- const DSD_SILENCE_BYTE : u8 = 0x69 ;
1273-
1274- match sample_format {
1275- SampleFormat :: I8 => fill_typed ! ( i8 ) ,
1276- SampleFormat :: I16 => fill_typed ! ( i16 ) ,
1277- SampleFormat :: I24 => fill_typed ! ( I24 ) ,
1278- SampleFormat :: I32 => fill_typed ! ( i32 ) ,
1279- // SampleFormat::I48 => fill_typed!(I48),
1280- SampleFormat :: I64 => fill_typed ! ( i64 ) ,
1281- SampleFormat :: U8 => fill_typed ! ( u8 ) ,
1282- SampleFormat :: U16 => fill_typed ! ( u16 ) ,
1283- SampleFormat :: U24 => fill_typed ! ( U24 ) ,
1284- SampleFormat :: U32 => fill_typed ! ( u32 ) ,
1285- // SampleFormat::U48 => fill_typed!(U48),
1286- SampleFormat :: U64 => fill_typed ! ( u64 ) ,
1287- SampleFormat :: F32 => fill_typed ! ( f32 ) ,
1288- SampleFormat :: F64 => fill_typed ! ( f64 ) ,
1289- SampleFormat :: DsdU8 | SampleFormat :: DsdU16 | SampleFormat :: DsdU32 => {
1290- buffer. fill ( DSD_SILENCE_BYTE )
1291- }
1292- }
1293- }
1294-
12951243fn init_hw_params < ' a > (
12961244 pcm_handle : & ' a alsa:: pcm:: PCM ,
12971245 config : & StreamConfig ,
0 commit comments