Streaming grabbed audio sample (in BYTE) to Audio renderer Filter

六眼飞鱼酱① 提交于 2019-12-10 11:59:43

问题


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?


回答1:


according to the documentation you need to call ISampleGrabber::SetBufferSamples before calling ISampleGrabber::GetCurrentBuffer. But I would recommend using a callback function using ISampleGrabber::SetCallback. Then you do not need to use a loop and sleep.

Either way, what you get is bytes. Depending on the format each audio sample uses 1 or more bytes. For example 16-bit stereo uses 4 bytes per sample. If you just write the bytes to a file (eg. test.pcm), there are some audio editors which are able to open and play it, for example cooledit95. When opening the file you have to enter which pcm format you use. It is better to write it to a .wav file, then you can open the file with every media player. But that requires you to know the .wav file format.



来源:https://stackoverflow.com/questions/5138476/streaming-grabbed-audio-sample-in-byte-to-audio-renderer-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!