title: How to properly Capture Audio with DirectShow
body: <p>Basiclly I just want to capture audio and save it to a file on disk. I came to the conlusion using the AVI format would be best and least annoying. After wading through the DirectShow API, this is what I came up with.</p>
  
  <pre><code>//I find the mic in previous code
  hr = pMoniker-&gt;BindToObject(0, 0, IID_IBaseFilter, (void**)&amp;pSrc);
  
  hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&amp;pGraph);
  //Initialize the Capture Graph Builder
  hr = pBuild-&gt;SetFiltergraph(pGraph);
  
  IBaseFilter *pMux;
  //IFileSinkFilter *pSink;
  hr = pBuild-&gt;SetOutputFileName(
      &amp;MEDIASUBTYPE_Avi,  // Specifies AVI for the target file.
      L"C:\\Example.avi", // File name.
      &amp;pMux,              // Receives a pointer to the mux.
      NULL);              // (Optional) Receives a pointer to the file sink.
  
  
  hr = pBuild-&gt;RenderStream(
      &amp;PIN_CATEGORY_CAPTURE, // Pin category.
      &amp;MEDIATYPE_Audio,      // Media type.
      pSrc,                  // Capture filter.
      NULL,                  // Intermediate filter (optional).
      pMux);                 // Mux or file sink filter.
  </code></pre>
  
  <p>Now, I figured this would be enough to do what I wanted but no file is created on disk and RenderStream gives me E_INVALDARGS. If I change the function call to:</p>
  
  <pre><code>hr = pBuild-&gt;RenderStream(
      NULL, // Pin category.
  NULL,      // Media type.
      pSrc,                  // Capture filter.
      NULL,                  // Intermediate filter (optional).
      pMux);                 // Mux or file sink filter.
  </code></pre>
  
  <p>I get the VFW_E_NOT_IN_GRAPH error instead.</p>
  
  <p>What am I doing wrong here? I'd be outmost grateful for any help, thanks in advance!</p>