windowsaudioms-media-foundationdmo

How to get CResamplerMediaObject to work as it is supposed to?


I am trying to use CResamplerMediaObject to resample audio I capture from the DefaultAudioEndpoint in order to clone it to any other AudioEndpoint I choose.

But whatever the Input/OutputType is, it seems to just pass through what I input to it without modification.

If the Input/OutputType look like this:

inputType()
 WAVEFORMATEXTENSIBLE:
    wFormatTag = 65534
    cbSize = 22
    nAvgBytesPerSec = 384000
    nBlockAlign = 8
    nChannels = 2
    nSamplesPerSec = 48000
    wBitsPerSample = 32
    ext->dwChannelMask = 3
    ext->Samples.wValidBitsPerSample = 32
    ext->Samples.wSamplesPerBlock = 32
    ext->SubFormat = {00000003-0000-0010-8000-00AA00389B71}

 Properties of the media type: 
    MF_MT_AUDIO_NUM_CHANNELS = 2
    MF_MT_AUDIO_SAMPLES_PER_SECOND = 48000
    MF_MT_AUDIO_BLOCK_ALIGNMENT = 8
    MF_MT_AUDIO_AVG_BYTES_PER_SECOND = 384000
    MF_MT_AUDIO_BITS_PER_SAMPLE = 32
    MF_MT_ALL_SAMPLES_INDEPENDENT = 1
    MF_MT_AUDIO_CHANNEL_MASK = 3
    MF_MT_AUDIO_VALID_BITS_PER_SAMPLE = 0

outputType()
 WAVEFORMATEXTENSIBLE:
    wFormatTag = 65534
    cbSize = 22
    nAvgBytesPerSec = 1536000
    nBlockAlign = 32
    nChannels = 8
    nSamplesPerSec = 48000
    wBitsPerSample = 32
    ext->dwChannelMask = 1599
    ext->Samples.wValidBitsPerSample = 32
    ext->Samples.wSamplesPerBlock = 32
    ext->SubFormat = {00000003-0000-0010-8000-00AA00389B71}

 Properties of the media type:
    MF_MT_AUDIO_NUM_CHANNELS = 8
    MF_MT_AUDIO_SAMPLES_PER_SECOND = 48000
    MF_MT_AUDIO_BLOCK_ALIGNMENT = 32
    MF_MT_AUDIO_AVG_BYTES_PER_SECOND = 1536000
    MF_MT_AUDIO_BITS_PER_SAMPLE = 32
    MF_MT_ALL_SAMPLES_INDEPENDENT = 1
    MF_MT_AUDIO_CHANNEL_MASK = 1599
    MF_MT_AUDIO_VALID_BITS_PER_SAMPLE = 0

I would expect to get for every input frame with length of 8 Bytes ( ( wBitsPerSample / 8 ) * nChannels) an output frame with a length of 32 Bytes. Instead the outputframes are still 8 Bytes long.

If I insert the missing 6 bytes in the output data it works as expected, but would this not be the job of the resampler?

Also if I change the sampling rate for input or output I would expect to see changes in length between the inputed and outputed data. But it remains the same.

You can find the source code here.
If somebody needs an working example program it is available here.


Solution

  • Use of input media type twice is a likely cause and matches the behavior you are describing:

    Check( transform()->SetInputType( 0, inputType(), 0 ), "transform()->SetInputType" );
    Check( transform()->SetOutputType( 0, inputType(), 0 ), "transform()->SetOutputType" );