Accessing raw wav data from a directshow filter graph

241 views Asked by At

The following code will quite happily load in an mp3 and play it, but I need to retrieve the raw wav data, as float if possible. How can I do that? I kind of know how to do it using IAMMultiMediaStream but Microsoft suggests using a filter on the graph is the preferred way, I just can't find any documentation or examples. I would have thought playing the sound file is the hardest part and that accessing the raw data would be easy.

    IGraphBuilder* pGraph;

// Use its member function CoCreateInstance to 
//create the COM object and obtain the IGraphBuilder pointer.
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);

if(FAILED(hr)){ /*... handle hr error*/ }

// Use the overloaded -> operator to call the interface methods.
std::wstring ws;
ws.assign(rInFilename.begin(), rInFilename.end());
hr = pGraph->RenderFile(ws.c_str(), NULL);
if(FAILED(hr)){ /*... handle hr error*/ }

// Declare a second smart pointer and use it to  
// obtain another interface from the object.
IMediaControl* pControl;
IMediaEvent* pEvent;

hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

// Use the second interface.
hr = pControl->Run();
if(FAILED(hr)){ /*... handle hr error*/ }

// Use the third interface. 
long evCode = 0;
pEvent->WaitForCompletion(INFINITE, &evCode);

edit: I should link to microsoft documentation showing how to do this using streams

https://msdn.microsoft.com/en-us/library/windows/desktop/dd317593%28v=vs.85%29.aspx

0

There are 0 answers