fn config_to_waveformatextensible(
    config: &StreamConfig,
    sample_format: SampleFormat,
) -> Option<mmreg::WAVEFORMATEXTENSIBLE> {
    let format_tag = match sample_format {
        SampleFormat::I16 => mmreg::WAVE_FORMAT_PCM,
        SampleFormat::F32 => mmreg::WAVE_FORMAT_EXTENSIBLE,
        SampleFormat::U16 => return None,
    };
    let channels = config.channels as WORD;
    let sample_rate = config.sample_rate.0 as DWORD;
    let sample_bytes = sample_format.sample_size() as WORD;
    let avg_bytes_per_sec = u32::from(channels) * sample_rate * u32::from(sample_bytes);
    let block_align = channels * sample_bytes;
    let bits_per_sample = 8 * sample_bytes;
    let cb_size = match sample_format {
        SampleFormat::I16 => 0,
        SampleFormat::F32 => {
            let extensible_size = mem::size_of::<mmreg::WAVEFORMATEXTENSIBLE>();
            let ex_size = mem::size_of::<mmreg::WAVEFORMATEX>();
            (extensible_size - ex_size) as WORD
        }
        SampleFormat::U16 => return None,
    };
    let waveformatex = mmreg::WAVEFORMATEX {
        wFormatTag: format_tag,
        nChannels: channels,
        nSamplesPerSec: sample_rate,
        nAvgBytesPerSec: avg_bytes_per_sec,
        nBlockAlign: block_align,
        wBitsPerSample: bits_per_sample,
        cbSize: cb_size,
    };

    // CPAL does not care about speaker positions, so pass audio straight through.
    // TODO: This constant should be defined in winapi but is missing.
    const KSAUDIO_SPEAKER_DIRECTOUT: DWORD = 0;
    let channel_mask = KSAUDIO_SPEAKER_DIRECTOUT;

    let sub_format = match sample_format {
        SampleFormat::I16 => ksmedia::KSDATAFORMAT_SUBTYPE_PCM,
        SampleFormat::F32 => ksmedia::KSDATAFORMAT_SUBTYPE_IEEE_FLOAT,
        SampleFormat::U16 => return None,
    };
    let waveformatextensible = mmreg::WAVEFORMATEXTENSIBLE {
        Format: waveformatex,
        Samples: bits_per_sample as WORD,
        dwChannelMask: channel_mask,
        SubFormat: sub_format,
    };

    Some(waveformatextensible)
}
// Turns a `Format` into a `WAVEFORMATEXTENSIBLE`.
//
// Returns `None` if the WAVEFORMATEXTENSIBLE does not support the given format.
Turns a `Format` into a `WAVEFORMATEXTENSIBLE`.
Returns `None` if the WAVEFORMATEXTENSIBLE does not support the given format.
Turns a ` Format ` into a ` WAVEFORMATEXTENSIBLE ` . Returns ` None ` if the WAVEFORMATEXTENSIBLE does not support the given format .
fn config_to_waveformatextensible(
    config: &StreamConfig,
    sample_format: SampleFormat,
) -> Option<mmreg::WAVEFORMATEXTENSIBLE> {
    let format_tag = match sample_format {
        SampleFormat::I16 => mmreg::WAVE_FORMAT_PCM,
        SampleFormat::F32 => mmreg::WAVE_FORMAT_EXTENSIBLE,
        SampleFormat::U16 => return None,
    };
    let channels = config.channels as WORD;
    let sample_rate = config.sample_rate.0 as DWORD;
    let sample_bytes = sample_format.sample_size() as WORD;
    let avg_bytes_per_sec = u32::from(channels) * sample_rate * u32::from(sample_bytes);
    let block_align = channels * sample_bytes;
    let bits_per_sample = 8 * sample_bytes;
    let cb_size = match sample_format {
        SampleFormat::I16 => 0,
        SampleFormat::F32 => {
            let extensible_size = mem::size_of::<mmreg::WAVEFORMATEXTENSIBLE>();
            let ex_size = mem::size_of::<mmreg::WAVEFORMATEX>();
            (extensible_size - ex_size) as WORD
        }
        SampleFormat::U16 => return None,
    };
    let waveformatex = mmreg::WAVEFORMATEX {
        wFormatTag: format_tag,
        nChannels: channels,
        nSamplesPerSec: sample_rate,
        nAvgBytesPerSec: avg_bytes_per_sec,
        nBlockAlign: block_align,
        wBitsPerSample: bits_per_sample,
        cbSize: cb_size,
    };
    // CPAL does not care about speaker positions, so pass audio straight through.
    // TODO: This constant should be defined in winapi but is missing.
    const KSAUDIO_SPEAKER_DIRECTOUT: DWORD = 0;
    let channel_mask = KSAUDIO_SPEAKER_DIRECTOUT;
    let sub_format = match sample_format {
        SampleFormat::I16 => ksmedia::KSDATAFORMAT_SUBTYPE_PCM,
        SampleFormat::F32 => ksmedia::KSDATAFORMAT_SUBTYPE_IEEE_FLOAT,
        SampleFormat::U16 => return None,
    };
    let waveformatextensible = mmreg::WAVEFORMATEXTENSIBLE {
        Format: waveformatex,
        Samples: bits_per_sample as WORD,
        dwChannelMask: channel_mask,
        SubFormat: sub_format,
    };
    Some(waveformatextensible)
}
fn config_to_waveformatextensible ( config : & StreamConfig , sample_format : SampleFormat , ) -> Option < mmreg :: WAVEFORMATEXTENSIBLE > { let format_tag = match sample_format { SampleFormat :: I16 => mmreg :: WAVE_FORMAT_PCM , SampleFormat :: F32 => mmreg :: WAVE_FORMAT_EXTENSIBLE , SampleFormat :: U16 => return None , } ; let channels = config . channels as WORD ; let sample_rate = config . sample_rate . 0 as DWORD ; let sample_bytes = sample_format . sample_size ( ) as WORD ; let avg_bytes_per_sec = u32 :: from ( channels ) * sample_rate * u32 :: from ( sample_bytes ) ; let block_align = channels * sample_bytes ; let bits_per_sample = 8 * sample_bytes ; let cb_size = match sample_format { SampleFormat :: I16 => 0 , SampleFormat :: F32 => { let extensible_size = mem :: size_of :: < mmreg :: WAVEFORMATEXTENSIBLE > ( ) ; let ex_size = mem :: size_of :: < mmreg :: WAVEFORMATEX > ( ) ; ( extensible_size - ex_size ) as WORD } SampleFormat :: U16 => return None , } ; let waveformatex = mmreg :: WAVEFORMATEX { wFormatTag : format_tag , nChannels : channels , nSamplesPerSec : sample_rate , nAvgBytesPerSec : avg_bytes_per_sec , nBlockAlign : block_align , wBitsPerSample : bits_per_sample , cbSize : cb_size , } ; // CPAL does not care about speaker positions, so pass audio straight through. // TODO: This constant should be defined in winapi but is missing. const KSAUDIO_SPEAKER_DIRECTOUT : DWORD = 0 ; let channel_mask = KSAUDIO_SPEAKER_DIRECTOUT ; let sub_format = match sample_format { SampleFormat :: I16 => ksmedia :: KSDATAFORMAT_SUBTYPE_PCM , SampleFormat :: F32 => ksmedia :: KSDATAFORMAT_SUBTYPE_IEEE_FLOAT , SampleFormat :: U16 => return None , } ; let waveformatextensible = mmreg :: WAVEFORMATEXTENSIBLE { Format : waveformatex , Samples : bits_per_sample as WORD , dwChannelMask : channel_mask , SubFormat : sub_format , } ; Some ( waveformatextensible ) }
Turns a `Format` into a `WAVEFORMATEXTENSIBLE`.
Turns a ` Format ` into a ` WAVEFORMATEXTENSIBLE ` .
config
&StreamConfig
sample_format
SampleFormat
config
&StreamConfig
sample_format
SampleFormat