简体   繁体   English

将抓取的音频样本(以字节为单位)流式传输到音频渲染器过滤器

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

I have written a program to take sample audio continously from microphone into a buffer using ISampleGrabber. 我编写了一个程序,使用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 我需要每秒1000个样本的样本才能开始

I pause getcurrentbuffer for 1ms and loop it. 我将getcurrentbuffer暂停1ms并将其循环。

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? 我应该怎么做?

according to the documentation you need to call ISampleGrabber::SetBufferSamples before calling ISampleGrabber::GetCurrentBuffer . 根据文档,在调用ISampleGrabber::GetCurrentBuffer之前,需要先调用ISampleGrabber::SetBufferSamples But I would recommend using a callback function using ISampleGrabber::SetCallback . 但是我建议使用使用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. 根据格式,每个音频样本使用1个或多个字节。 For example 16-bit stereo uses 4 bytes per sample. 例如,16位立体声每个样本使用4个字节。 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. 如果仅将字节写入文件(例如test.pcm),则可以使用某些音频编辑器来打开和播放该文件,例如coolit95。 When opening the file you have to enter which pcm format you use. 打开文件时,您必须输入使用的pcm格式。 It is better to write it to a .wav file, then you can open the file with every media player. 最好将其写入.wav文件,然后可以使用每个媒体播放器打开该文件。 But that requires you to know the .wav file format. 但这需要您知道.wav文件格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM