unsafe fn format_from_waveformatex_ptr(
    waveformatex_ptr: *const mmreg::WAVEFORMATEX,
) -> Option<SupportedStreamConfig> {
    fn cmp_guid(a: &GUID, b: &GUID) -> bool {
        a.Data1 == b.Data1 && a.Data2 == b.Data2 && a.Data3 == b.Data3 && a.Data4 == b.Data4
    }
    let sample_format = match (
        (*waveformatex_ptr).wBitsPerSample,
        (*waveformatex_ptr).wFormatTag,
    ) {
        (16, mmreg::WAVE_FORMAT_PCM) => SampleFormat::I16,
        (32, mmreg::WAVE_FORMAT_IEEE_FLOAT) => SampleFormat::F32,
        (n_bits, mmreg::WAVE_FORMAT_EXTENSIBLE) => {
            let waveformatextensible_ptr = waveformatex_ptr as *const mmreg::WAVEFORMATEXTENSIBLE;
            let sub = (*waveformatextensible_ptr).SubFormat;
            if n_bits == 16 && cmp_guid(&sub, &ksmedia::KSDATAFORMAT_SUBTYPE_PCM) {
                SampleFormat::I16
            } else if n_bits == 32 && cmp_guid(&sub, &ksmedia::KSDATAFORMAT_SUBTYPE_IEEE_FLOAT) {
                SampleFormat::F32
            } else {
                return None;
            }
        }
        // Unknown data format returned by GetMixFormat.
        _ => return None,
    };

    let format = SupportedStreamConfig {
        channels: (*waveformatex_ptr).nChannels as _,
        sample_rate: SampleRate((*waveformatex_ptr).nSamplesPerSec),
        buffer_size: SupportedBufferSize::Unknown,
        sample_format,
    };
    Some(format)
}
// Get a cpal Format from a WAVEFORMATEX.
Get a cpal Format from a WAVEFORMATEX.
Get a cpal Format from a WAVEFORMATEX .
unsafe fn format_from_waveformatex_ptr(
    waveformatex_ptr: *const mmreg::WAVEFORMATEX,
) -> Option<SupportedStreamConfig> {
    fn cmp_guid(a: &GUID, b: &GUID) -> bool {
        a.Data1 == b.Data1 && a.Data2 == b.Data2 && a.Data3 == b.Data3 && a.Data4 == b.Data4
    }
    let sample_format = match (
        (*waveformatex_ptr).wBitsPerSample,
        (*waveformatex_ptr).wFormatTag,
    ) {
        (16, mmreg::WAVE_FORMAT_PCM) => SampleFormat::I16,
        (32, mmreg::WAVE_FORMAT_IEEE_FLOAT) => SampleFormat::F32,
        (n_bits, mmreg::WAVE_FORMAT_EXTENSIBLE) => {
            let waveformatextensible_ptr = waveformatex_ptr as *const mmreg::WAVEFORMATEXTENSIBLE;
            let sub = (*waveformatextensible_ptr).SubFormat;
            if n_bits == 16 && cmp_guid(&sub, &ksmedia::KSDATAFORMAT_SUBTYPE_PCM) {
                SampleFormat::I16
            } else if n_bits == 32 && cmp_guid(&sub, &ksmedia::KSDATAFORMAT_SUBTYPE_IEEE_FLOAT) {
                SampleFormat::F32
            } else {
                return None;
            }
        }
        // Unknown data format returned by GetMixFormat.
        _ => return None,
    };
    let format = SupportedStreamConfig {
        channels: (*waveformatex_ptr).nChannels as _,
        sample_rate: SampleRate((*waveformatex_ptr).nSamplesPerSec),
        buffer_size: SupportedBufferSize::Unknown,
        sample_format,
    };
    Some(format)
}
unsafe fn format_from_waveformatex_ptr ( waveformatex_ptr : * const mmreg :: WAVEFORMATEX , ) -> Option < SupportedStreamConfig > { fn cmp_guid ( a : & GUID , b : & GUID ) -> bool { a . Data1 == b . Data1 && a . Data2 == b . Data2 && a . Data3 == b . Data3 && a . Data4 == b . Data4 } let sample_format = match ( ( * waveformatex_ptr ) . wBitsPerSample , ( * waveformatex_ptr ) . wFormatTag , ) { ( 16 , mmreg :: WAVE_FORMAT_PCM ) => SampleFormat :: I16 , ( 32 , mmreg :: WAVE_FORMAT_IEEE_FLOAT ) => SampleFormat :: F32 , ( n_bits , mmreg :: WAVE_FORMAT_EXTENSIBLE ) => { let waveformatextensible_ptr = waveformatex_ptr as * const mmreg :: WAVEFORMATEXTENSIBLE ; let sub = ( * waveformatextensible_ptr ) . SubFormat ; if n_bits == 16 && cmp_guid ( & sub , & ksmedia :: KSDATAFORMAT_SUBTYPE_PCM ) { SampleFormat :: I16 } else if n_bits == 32 && cmp_guid ( & sub , & ksmedia :: KSDATAFORMAT_SUBTYPE_IEEE_FLOAT ) { SampleFormat :: F32 } else { return None ; } } // Unknown data format returned by GetMixFormat. _ => return None , } ; let format = SupportedStreamConfig { channels : ( * waveformatex_ptr ) . nChannels as _ , sample_rate : SampleRate ( ( * waveformatex_ptr ) . nSamplesPerSec ) , buffer_size : SupportedBufferSize :: Unknown , sample_format , } ; Some ( format ) }
Get a cpal Format from a WAVEFORMATEX.
Get a cpal Format from a WAVEFORMATEX .
waveformatex_ptr
*const mmreg::WAVEFORMATEX
waveformatex_ptr
*const mmreg::WAVEFORMATEX