| 4030 | { |
| 4031 | public: |
| 4032 | WasapiResampler( bool isFloat, unsigned int bitsPerSample, unsigned int channelCount, |
| 4033 | unsigned int inSampleRate, unsigned int outSampleRate ) |
| 4034 | : _bytesPerSample( bitsPerSample / 8 ) |
| 4035 | , _channelCount( channelCount ) |
| 4036 | , _sampleRatio( ( float ) outSampleRate / inSampleRate ) |
| 4037 | , _transformUnk( NULL ) |
| 4038 | , _transform( NULL ) |
| 4039 | , _mediaType( NULL ) |
| 4040 | , _inputMediaType( NULL ) |
| 4041 | , _outputMediaType( NULL ) |
| 4042 | |
| 4043 | #ifdef __IWMResamplerProps_FWD_DEFINED__ |
| 4044 | , _resamplerProps( NULL ) |
| 4045 | #endif |
| 4046 | { |
| 4047 | // 1. Initialization |
| 4048 | |
| 4049 | MFStartup( MF_VERSION, MFSTARTUP_NOSOCKET ); |
| 4050 | |
| 4051 | // 2. Create Resampler Transform Object |
| 4052 | |
| 4053 | CoCreateInstance( CLSID_CResamplerMediaObject, NULL, CLSCTX_INPROC_SERVER, |
| 4054 | IID_IUnknown, ( void** ) &_transformUnk ); |
| 4055 | |
| 4056 | _transformUnk->QueryInterface( IID_PPV_ARGS( &_transform ) ); |
| 4057 | |
| 4058 | #ifdef __IWMResamplerProps_FWD_DEFINED__ |
| 4059 | _transformUnk->QueryInterface( IID_PPV_ARGS( &_resamplerProps ) ); |
| 4060 | _resamplerProps->SetHalfFilterLength( 60 ); // best conversion quality |
| 4061 | #endif |
| 4062 | |
| 4063 | // 3. Specify input / output format |
| 4064 | |
| 4065 | MFCreateMediaType( &_mediaType ); |
| 4066 | _mediaType->SetGUID( MF_MT_MAJOR_TYPE, MFMediaType_Audio ); |
| 4067 | _mediaType->SetGUID( MF_MT_SUBTYPE, isFloat ? MFAudioFormat_Float : MFAudioFormat_PCM ); |
| 4068 | _mediaType->SetUINT32( MF_MT_AUDIO_NUM_CHANNELS, channelCount ); |
| 4069 | _mediaType->SetUINT32( MF_MT_AUDIO_SAMPLES_PER_SECOND, inSampleRate ); |
| 4070 | _mediaType->SetUINT32( MF_MT_AUDIO_BLOCK_ALIGNMENT, _bytesPerSample * channelCount ); |
| 4071 | _mediaType->SetUINT32( MF_MT_AUDIO_AVG_BYTES_PER_SECOND, _bytesPerSample * channelCount * inSampleRate ); |
| 4072 | _mediaType->SetUINT32( MF_MT_AUDIO_BITS_PER_SAMPLE, bitsPerSample ); |
| 4073 | _mediaType->SetUINT32( MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE ); |
| 4074 | |
| 4075 | MFCreateMediaType( &_inputMediaType ); |
| 4076 | _mediaType->CopyAllItems( _inputMediaType ); |
| 4077 | |
| 4078 | _transform->SetInputType( 0, _inputMediaType, 0 ); |
| 4079 | |
| 4080 | MFCreateMediaType( &_outputMediaType ); |
| 4081 | _mediaType->CopyAllItems( _outputMediaType ); |
| 4082 | |
| 4083 | _outputMediaType->SetUINT32( MF_MT_AUDIO_SAMPLES_PER_SECOND, outSampleRate ); |
| 4084 | _outputMediaType->SetUINT32( MF_MT_AUDIO_AVG_BYTES_PER_SECOND, _bytesPerSample * channelCount * outSampleRate ); |
| 4085 | |
| 4086 | _transform->SetOutputType( 0, _outputMediaType, 0 ); |
| 4087 | |
| 4088 | // 4. Send stream start messages to Resampler |
| 4089 |
nothing calls this directly
no outgoing calls
no test coverage detected