You can use Microsoft Media Foundation and MF_MT_AUDIO_AVG_BYTES_PER_SECOND
or with WinRT, interfaces like AudioEncodingProperties
I did this test with MMF and help from ChatGPT to convert a .wav to 256 kbps :
int TranscodeWav(const wchar_t* pwsInputPath, const wchar_t* pwsOutputPath)
{
MFStartup(MF_VERSION);
IMFSourceReader* pReader = nullptr;
MFCreateSourceReaderFromURL(pwsInputPath, NULL, &pReader);
IMFMediaType* pMediaTypeOut = nullptr;
MFCreateMediaType(&pMediaTypeOut);
pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
// From ChatGPT
pMediaTypeOut->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, 16000); // 16 kHz
pMediaTypeOut->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, 16); // 16‑bit depth
pMediaTypeOut->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, 1); // Mono
// Average bytes per second = samplerate × channels × bits/sample ÷ 8
// Byte rate = 16000 * 1 * 16 / 8 = 32,000 bytes/s
// 256 kbps = 256000 bps (divide by 8 for bytes/sec)
pMediaTypeOut->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, 16000 * 1 * 16 / 8);
// Set the media type on the source reader's output
pReader->SetCurrentMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM, NULL, pMediaTypeOut);
IMFSinkWriter* pWriter = nullptr;
DWORD nStreamIndex = 0;
MFCreateSinkWriterFromURL(pwsOutputPath, NULL, NULL, &pWriter);
pWriter->AddStream(pMediaTypeOut, &nStreamIndex);
pWriter->BeginWriting();
// Transcode loop: read samples, optionally convert timestamps, write to output
DWORD nFlags = 0;
LONGLONG timestamp = 0;
while (true)
{
IMFSample* pSample = nullptr;
pReader->ReadSample(MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, nullptr, &nFlags, ×tamp, &pSample);
if (nFlags & MF_SOURCE_READERF_ENDOFSTREAM) break;
if (pSample)
{
pWriter->WriteSample(nStreamIndex, pSample);
pSample->Release();
}
}
pWriter->Finalize();
pWriter->Release();
pMediaTypeOut->Release();
pReader->Release();
MFShutdown();
return 0;
}
with :
#include <mfapi.h>
#include <mfidl.h>
#include <mferror.h>
#include <mfreadwrite.h>
#pragma comment(lib, "Mfplat")
#pragma comment(lib, "mfreadwrite")
#pragma comment(lib, "mfuuid")