如何使用 SampleGrabber 构建音频频谱/可视化工具?

发布于 2024-10-10 00:04:56 字数 921 浏览 4 评论 0原文

我目前正在构建一个使用 DS sdk 的应用程序,我需要弄清楚如何从音频源不断获取幅度以绘制某种可视化工具或频谱。我一直在尝试研究如何在音频上实现样本采集器,但我发现的所有信息都已过时且无用。经过几十次尝试,这就是我目前所拥有的:

        ISampleGrabber pGrabber = (ISampleGrabber)pSampleGrabber;
        hr = pGraph.ConnectDirect(GetPin(pInfinitePinTeeFilterAudio, "Output3"), GetPin(pSampleGrabber, "Input"), null);
        checkHR(hr, "1040");
        if (hr < 0) return false;
        hr = pGraph.ConnectDirect(GetPin(pSampleGrabber, "Output"), GetPin(pNullRenderer, "In"), null);
        checkHR(hr, "1041");
        if (hr < 0) return false;

        AMMediaType media = new AMMediaType();
        media.formatType = FormatType.WaveEx;
        pGrabber.GetConnectedMediaType(media); //gets and sets media type into media

        pGrabber.SetBufferSamples(true);
        int cbbuffer = 0;
        hr = pGrabber.GetCurrentBuffer(ref cbbuffer, IntPtr.Zero);

如何读取当前缓冲区上的内容,并连续读取缓冲区上的内容?

I am currently building an application that uses the DS sdk, and I need to figure out how to obtain the amplitude constantly from the audio source to draw a visualizer or spectrum of some sort. I've been trying to look on how sample grabber is implemented on audio, but all of the information I've found have been outdated, and unhelpful. After a few dozen attempts, this is what I have currently:

        ISampleGrabber pGrabber = (ISampleGrabber)pSampleGrabber;
        hr = pGraph.ConnectDirect(GetPin(pInfinitePinTeeFilterAudio, "Output3"), GetPin(pSampleGrabber, "Input"), null);
        checkHR(hr, "1040");
        if (hr < 0) return false;
        hr = pGraph.ConnectDirect(GetPin(pSampleGrabber, "Output"), GetPin(pNullRenderer, "In"), null);
        checkHR(hr, "1041");
        if (hr < 0) return false;

        AMMediaType media = new AMMediaType();
        media.formatType = FormatType.WaveEx;
        pGrabber.GetConnectedMediaType(media); //gets and sets media type into media

        pGrabber.SetBufferSamples(true);
        int cbbuffer = 0;
        hr = pGrabber.GetCurrentBuffer(ref cbbuffer, IntPtr.Zero);

How do I read what is on the current buffer, and continuously read what is on the buffer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眸中客 2024-10-17 00:04:56

您走在正确的轨道上,您需要实现示例抓取器可以使用的回调函数,这就是SampleCB 是这样的,C# 等效项将是这样的:

int ISampleGrabberCB.SampleCB(double SampleTime, IMediaSample pSample )
{
    //work with audio sample here
    return 0;
}

还要确保您的图表中的样本采集器之前​​有一个音频解码器,否则您将收到压缩样本。

此处还有一篇相关文章可能对您有帮助。

You are on the right track, you need to implement a callback function that the sample grabber can use, that's what SampleCB is for, the C# equivalent would be something like this:

int ISampleGrabberCB.SampleCB(double SampleTime, IMediaSample pSample )
{
    //work with audio sample here
    return 0;
}

Also make sure that you have an audio decoder before your sample grabber in your graph, otherwise you will receive compressed samples.

There's also a relevant article here that might help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文