简体   繁体   English

读取系统音频 Output Stream

[英]Reading The System Audio Output Stream

I am currently Making an Oscilloscope Component For XNA and need a bit of help.我目前正在为 XNA 制作示波器组件,需要一些帮助。 I would Like to get the Audio Information form The Systems Audio Output Stream, However i am finding it extremely hard to do so.我想获得系统音频 Output Stream 的音频信息表格,但是我发现这样做非常困难。 i have found Some Resources but nothing that helps me all the way, or it helps in a way i am not able to grasp.我找到了一些资源,但没有任何帮助我一路走来,或者它以我无法掌握的方式提供帮助。 Here are the Following Resources i have found so far.以下是我迄今为止发现的以下资源。

How to programmatically get the current audio level? 如何以编程方式获取当前音频电平?

http://msdn.microsoft.com/en-us/library/ms712636 http://msdn.microsoft.com/en-us/library/ms712636

http://social.msdn.microsoft.com/Forums/en/xnagamestudioexpress/thread/6a3ea3da-849b-475d-a2a4-7cf7c27347d5 http://social.msdn.microsoft.com/Forums/en/xnagamestudioexpress/thread/6a3ea3da-849b-475d-a2a4-7cf7c27347d5

As i am not Able to completely get a handle on what to do i have humbly come to you for your help Thank you Vary much.由于我无法完全掌握要做什么,我谦卑地向您寻求帮助,非常感谢您。

DirectSound has a lot of nuance to it that can make it difficult to work with. DirectSound 有很多细微差别,使其难以使用。 If you're open to using some third-party options, there are a few free ones available that abstract the technical details of DirectSound and make this problem much more approachable.如果您愿意使用一些第三方选项,可以使用一些免费的选项来抽象 DirectSound 的技术细节并使这个问题更容易解决。 I personally recommend BASS.NET - and NAudio is good if you're more interested in an entirely managed solution.我个人推荐 BASS.NET - 如果您对完全托管的解决方案更感兴趣,NAudio 会很好。

In BASS.NET, your code would look something like this:在 BASS.NET 中,您的代码将如下所示:

private RECORDPROC _myRecProc; // make it global, so that the Garbage Collector can not remove it
...
Bass.BASS_RecordInit(-1);
_myRecProc = new RECORDPROC(MyRecording);
// start recording paused
int settings = 0;
int inputSource = 0;
while (settings != -1)
{
  // get the settings of that input
  settings = Bass.BASS_RecordGetInput(inputSource, ref vol);
  if ( Bass.BASS_RecordGetInputName(inputSource) == "What U Hear" ||
       Bass.BASS_RecordGetInputName(inputSource) == "Stereo Mix")
  { 
    break;
  }
  inputSource++;
}    

Bass.BASS_RecordSetInput(inputSource, BASSInput.BASS_INPUT_ON, 0.5F)

int recChannel = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, 50, _myRecProc, IntPtr.Zero);
...
// really start recording
Bass.BASS_ChannelPlay(recChannel, false);
...
// the recording callback
private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
{
  return true;
}

Basically, you're initializing BASS.基本上,您正在初始化 BASS。 Then you loop through all the possible input sources searching for "What U Hear" or "Stereo Mix."然后循环搜索“你听到什么”或“立体声混音”的所有可能输入源。 The name of the channel that is a combination of all your speaker output varies from soundcard to soundcard, so you'll have to get a list of the common names.由所有扬声器 output 组合而成的通道名称因声卡而异,因此您必须获取常用名称列表。 After you've found an appropriate channel, you'll start recording.找到合适的频道后,您将开始录制。 The MyRecording method will have a buffer for you to analyze. MyRecording 方法将有一个缓冲区供您分析。

This is just one way to do it, with one library.这只是使用一个库的一种方法。 Take a look around and see which library provides you with data in a format you want it in.环顾四周,看看哪个库以您想要的格式为您提供数据。

XNA includes a MediaPlayer class that gives you access to some "visualization data" (a sampling of frequencies and their volumes). XNA 包含一个 MediaPlayer class,可让您访问一些“可视化数据”(频率及其音量的采样)。 Take a look at this for a tutorial.看一下这个教程。

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

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