流抓起音频采样(以字节),音频渲染器过滤器 [英] Streaming grabbed audio sample (in BYTE) to Audio renderer Filter

查看:221
本文介绍了流抓起音频采样(以字节),音频渲染器过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个程序来使用ISampleGrabber从话筒取样品音频continously到缓冲区中。

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");
}

我需要的每秒1000个样本的开始样品

I need a sample of 1000 samples per sec for start

我暂停getcurrentbuffer时间为1ms和循环吧。

I pause getcurrentbuffer for 1ms and loop it.

我不知道这些方法。

我可以肯定的唯一方法是将抓住样品流的音频渲染过滤器。

The only way for me to be sure is to stream the grabbed sample to an audio render filter.

我怎么做?

推荐答案

根据需要调用的文件 ISampleGrabber :: SetBufferSamples 之前调用 ISampleGrabber :: GetCurrentBuffer 。不过,我会建议使用一个回调函数使用 ISampleGrabber :: SetCallback 。然后,你不需要使用循环和睡眠。

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.

无论哪种方式,你得到的是字节。根据格式每个音频样品使用1个或多个字节。例如16位的立体声使用每样本的4个字节。如果你只是写字节的文件(例如,test.pcm),也有一些音频的编辑器可以打开并播放,例如cooledit95。打开文件时,必须输入您使用的PCM格式。
最好是将其写入到一个.wav文件,然后你可以打开与每一个媒体播放器的文件。但是,这需要你知道.wav文件格式。

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.

这篇关于流抓起音频采样(以字节),音频渲染器过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆