如何使用 SampleGrabber 构建音频频谱/可视化工具?
我目前正在构建一个使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您走在正确的轨道上,您需要实现示例抓取器可以使用的回调函数,这就是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:
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.