如何使用SampleGrabber搭建音频频谱/可视化工具? [英] How do I use SampleGrabber to build a spectrum/visualizer for audio?

查看:299
本文介绍了如何使用SampleGrabber搭建音频频谱/可视化工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在建设一个使用DS SDK的应用程序,我需要弄清楚如何从音频源不断取得幅度绘制某种类型的可视化工具或频谱。我一直在试图寻找样本采集卡是如何在音频实现的,但所有的我已经找到的信息已经过时,和无益的。几十尝试后,这是我目前有:

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?

推荐答案

您在正确的轨道上,需要实现样品采集卡可以使用一个回调函数,这就是的 SampleCB 是,在C#相当于会是这样像这样的:

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.

这篇关于如何使用SampleGrabber搭建音频频谱/可视化工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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