I have written a program to take sample audio continously from microphone into a buffer using ISampleGrabber.
I am quite sure of all other part of the program. But the below part to grab sample into buffer is what i'm quite not sure of.
void MICDetect::Run_Graph(IMediaControl* m_pControl)
{
m_hr = m_pControl->Run();// Now run the graph, i.e. start listening!
if(SUCCEEDED(m_hr))
{
cout<<"Graph is Running"<<endl;
}
else HR_Failed(m_hr);
cout<<"Waiting for buffer";
for(int i=5;i>=1;--i)
{
Sleep(500);
cout<<".";
}
cout<<endl;
m_hr = m_pGrabber->GetCurrentBuffer(&m_Size, NULL);
if(FAILED(m_hr))
{
HR_Failed(m_hr);
}
pBuffer = (BYTE*)CoTaskMemAlloc(m_Size);
if (!pBuffer)
{
m_hr = E_OUTOFMEMORY;
HR_Failed(m_hr);
}
for(int i=1000000;i>1;i--)
{
Sleep(1);
m_hr = m_pGrabber->GetCurrentBuffer(&m_Size, (long*)pBuffer);
if (FAILED(m_hr))
{
HR_Failed(m_hr);
}
}
system("pause");
}
I need a sample of 1000 samples per sec for start
I pause getcurrentbuffer for 1ms and loop it.
I'm not sure of these method.
The only way for me to be sure is to stream the grabbed sample to an audio render filter.
How am I supposed to do that?