CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2007
    Location
    California
    Posts
    136

    C# object to get PCM of a WAV file [.NET ver 3.0]

    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
    Last edited by kabilius; May 11th, 2009 at 02:44 PM.

  2. #2
    Join Date
    Jun 2007
    Location
    California
    Posts
    136

    Re: C# object to get PCM of a WAV file

    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.
    Code:
                    //
                    // 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured