Click to See Complete Forum and Search --> : C# object to get PCM of a WAV file
kabilius
May 11th, 2009, 11:22 AM
Hi all,
.NET version 3.0
I am trying to get the PCM of a .WAV file, so that I can calculate the waveform.
Is there a .NET or COM object that returns the PCM of a WAV file? or do I have to parse the .WAV file manually and decode the data of the WAV file to get the PCM?
P.S. I heard about using Direct Show, is this the correct direction?
Please advise,
Thank you,
kab
kabilius
May 12th, 2009, 09:34 AM
Hi all,
After studying DirectShow for a night, I was able create a source filter to read the content of an audio file; however, I am still abit unclear about how exactly direct show works.
I have two questions:
1. I remember reading an article that says DirectShow will decode and uncompress of the media data automatically. Is this true? or do I have to find the codec of the WAV file myself and decode it?
2. What exactly is an IPin?
3. What does PCM look like? is it an array of numbers? (I'd assume it's array of numbers, so I can calculate the waveform from it... right?)
Anyway, here is the code I have at the moment. I have it setup so that a pin is ready to read a WAV file and send to another pin.
//
// dShowGraphBuilder
//
this.dShowGraphBuilder = (DirectShowLib.IGraphBuilder)new FilterGraph();
// create a file source filter
//
// dShowBaseFilter
//
this.dShowBaseFilter = null;
this.dShowGraphBuilder.AddSourceFilter(@"\\server\\audioFile.wav", "Parser", out this.dShowBaseFilter);
IEnumPins enumPins;
int nRet;
nRet = this.dShowBaseFilter.EnumPins(out enumPins);
enumPins.Reset();
if (nRet == 0 && enumPins != null)
{
// loop through each pin
IPin[] iPins = new IPin[1];
IntPtr nptrFetched = new IntPtr();
do
{
nRet = enumPins.Next(1, iPins, nptrFetched);
if (nRet == 0 && iPins[0] != null)
{
// look for output pins
PinDirection pinDirection = PinDirection.Input;
nRet = iPins[0].QueryDirection(out pinDirection);
if (nRet == 0 && pinDirection == (PinDirection.Output))
{
// add the input pin to the source list
}
iPins[0] = null;
}
} while (nRet == 0);
}
Marshal.ReleaseComObject(enumPins);
enumPins = null;
Please give me some guidance,
Thank you,
kab
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.