Sample grabber

Hi, i have written down some code to set up and run a DirectShow graph.
I'm using the Sample Grabber to get audio samples decoded by the graph.
The sample grabber is then connected to the NullRenderer.

It works fine on stereo files, but on 6channels-files it downmixes them, and i need all the channels for my application.

Then I tried to set theWAVEFORMATEXTENSIBLEstructure, as i found on the Microsoft website.

WAVEFORMATPCMEX waveFormatPCMEx;
waveFormatPCMEx.Format.cbSize = 22;

waveFormatPCMEx.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
waveFormatPCMEx.Format.nChannels = 6;
waveFormatPCMEx.Format.nSamplesPerSec = 48000L;
waveFormatPCMEx.Format.nAvgBytesPerSec = 864000L; // Compute using nBlkAlign * nSamp/Sec
waveFormatPCMEx.Format.nBlockAlign = 18;
waveFormatPCMEx.Format.wBitsPerSample = 24; //Container has 3 bytes
waveFormatPCMEx.Format.cbSize = 22;
waveFormatPCMEx.Samples.wValidBitsPerSample = 20; // Top 20 bits have
data
waveFormatPCMEx.dwChannelMask = KSAUDIO_SPEAKER_5POINT1;
waveFormatPCMEx.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; // Specify PCM

HRESULT hr = CreateAudioMediaType((LPWAVEFORMATEX)&waveFormatPCMEx,&mt, TRUE);

But the graph fails to (intelligent) connect the sample grabber to the
File Source, withVFW_E_CANNOT_CONNECT.

Should i set the sample grabber in some different way? Any idea?

Thanks in advance!
[1927 byte] By [OnofrioPanzarino] at [2008-1-10]
# 1
You probably shouldn't set the format block at all. Just set the major type and let it give you the format.
ChrisP. at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 2
Hi Chris, thanks for the reply.

I've already tried setting the major type = MEDIATYPE_Audio and the rest to zero, but i still get 2 channels.

OnofrioPanzarino at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 3

Do you have a small sample audio file you can send me? My email address in on my web site http://www.chrisnet.net

Also you can try my Legacy HD Audio Filter on my site and see if that will work as an intermediate conversion.

ChrisP. at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 4

Ok, I got the sample and now I can immediately see the problem.

The sample is AC3, which means it goes through a decoder. The decoder has to be configured as to the number of output channels, otherwise it will probably default to stereo. I tested it with the Moonlight Decoder and the AC3Filter decoder. Both defaulted to stereo output until they were configured (they remember their preferences). Once configured they gave 6 channels to the sampleGrabber and Renderer.

ChrisP. at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 5
You're right,
i had not configured the filters properly (the GraphBuilder automatically loaded Intervideo Audio Decoder, that i can not configure).
With AC3Filter all works fine: i get all the channels now.

Thank you very much, Chris!
OP

OnofrioPanzarino at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...

Software Development for Windows Vista

Site Classified