Discussion:
How to encode a mono WMA using WM ASF Writer?
(too old to reply)
diandaolly
2010-06-13 17:10:56 UTC
Permalink
I used directshow filter "wm asf writer" to encode wma for my mp3
files (which are all mono music).

Yes I did made it work. However, all generated wma files are stereo (I
used system profile WMProfile_V80_64StereoAudio).

Is it possible to configure the asf writer so that I can generate mono
wma?

The following code did generate MONO wma, but apparently problematic
since I only got strange sound. Any hint on what the problem is?
Thanks.

---------------------------------------------

// Change profile to keep mono:

CComQIPtr<IConfigAsfWriter> spiConfigAsfWriter(spiAsfWriter);

CComPtr<IWMProfile> spiProfile = NULL;
hr = spiConfigAsfWriter->GetCurrentProfile(&spiProfile); // a system
profile being used

DWORD dwCount = 0;
hr = spiProfile->GetStreamCount(&dwCount);

for (DWORD i = 0; i < dwCount; i++)
{
CComPtr<IWMStreamConfig> spiStreamConfig = NULL;
hr = spiProfile->GetStream(i, &spiStreamConfig);

GUID guidST;
hr = spiStreamConfig->GetStreamType(&guidST);

if (WMMEDIATYPE_Audio == guidST)
{
CComQIPtr<IWMMediaProps> pAudioPro(spiStreamConfig);

DWORD dwSize = 0;
pAudioPro->GetMediaType(NULL, &dwSize);

ByteArray baMT(dwSize);
WM_MEDIA_TYPE * pmt = (WM_MEDIA_TYPE *)baMT.GetData();
::ZeroMemory(pmt, dwSize);
pAudioPro->GetMediaType(pmt, &dwSize);

if (pmt->majortype == MEDIATYPE_Audio)
{
if (pmt->formattype == FORMAT_WaveFormatEx)
{
WAVEFORMATEX * pwfx = (WAVEFORMATEX *)pmt->pbFormat;

pwfx->nChannels = 1; // ensure mono

//
// what else fields should I change? and how?
//
}
}

hr = pAudioPro->SetMediaType(pmt);

hr = spiProfile->ReconfigStream(spiStreamConfig);

hr = spiConfigAsfWriter-
ConfigureFilterUsingProfile(spiProfile);
}
Alessandro Angeli
2010-06-13 23:26:19 UTC
Permalink
From: "diandaolly"
Post by diandaolly
WAVEFORMATEX * pwfx = (WAVEFORMATEX *)pmt->pbFormat;
pwfx->nChannels = 1; // ensure mono
// what else fields should I change? and how?
With LPCM uncompressed audio:

nBlockAlign = nChannels * wBitsPerSample / 8

nAvgBitesPerSex = nBlockAlign * nSamplesPerSec

However, with WMA compressed audio it is not a good idea to modify the
WAVEFORMATEX structure manually, since there may be codec-specific bytes
(cbSize > 0) that also need changing, so you need to list the codec's
supported formats and use one of those. See IWMCodecInfo3 and:

http://msdn.microsoft.com/en-us/Library/dd743137.aspx
Post by diandaolly
used system profile WMProfile_V80_64StereoAudio).
If I were you I'd create a profile from scratch so I could use the WMA
v9.x encoder, which is quite better.
--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm
diandaolly
2010-06-15 16:27:26 UTC
Permalink
Thank you for the message. Now I use a customized profile and the
problem has been solved!

Loading...