转换此代码以获得麦克风输入?包含类源代码

发布于 2024-10-24 03:54:03 字数 1493 浏览 1 评论 0原文

我正在使用此处找到的 WindowsMedia 库: http://www.ernzo.com/soundstudio.aspx

示例代码能够播放音频文件,但是我试图让流来自麦克风。

我相信我已经获得了使用带有麦克风的 PeakMeter 的所有代码,除了以下部分。这是初始化音乐文件播放的代码,但我需要它来初始化监听麦克风。

但不知道该怎么做。有人以前这样做过并且知道需要进行哪些更改吗?

IMediaStream pAudioStream = null;
_MediaStream = new MultimediaStream();
int mmr = _MediaStream.Initialize(STREAM_TYPE.STREAMTYPE_READ,    
                                 (int)AMMSF_INIT.AMMSF_NOGRAPHTHREAD, null);
mmr = _MediaStream.AddMediaStream(null, MSPurposeId.PrimaryAudio, 
                                  0, out pAudioStream);
MSStatus.ThrowExceptionForHR(mmr);

// open media file
mmr = _MediaStream.OpenFile(filePath, (int)AMMSF_OPEN.AMMSF_RUN);
MSStatus.ThrowExceptionForHR(mmr);

_AudioStream = new MMAudioStream();
mmr = _AudioStream.SetMediaStream(pAudioStream);
MSStatus.ThrowExceptionForHR(mmr);

_wfmt = new WaveFormat(_AudioStream.Format);
mmr = WaveDevice.Open(WaveConstants.WAVE_MAPPER, _wfmt);
WaveOutStatus.ThrowExceptionForHR(mmr);

WaveDevice 是 IWaveDevice,类型为 WaveOutDevice。显然,这将更改为 WaveInDevice 类型,并将 WaveOutStatus 更改为 WaveInStatus。

这是我创建的类的完整代码。 Listen() 方法是我正在修改的方法。

http://pastebin.com/TQTwRHTF

该类是使用 SoundStudio 项目中提供的代码创建的,使用WindowsMedia 和 PeakMeter 由 Ernzo 提供。

如果有人能够找出使 Listen() 工作的更改,那将为他们赢得赏金。 (目前我放入了代码试图弄清楚,但 Play() 工作得很好)。

I'm using the WindowsMedia library found here: http://www.ernzo.com/soundstudio.aspx

The sample code had the ability to play audio files, however I'm trying to get the stream to come from the microphone.

I believe I've gotten all the code working to use the PeakMeter with Microphone, except the following part. This is the code that initializes the playing of the music file, but instead I need it to initialize listening to the microphone.

Not sure how to do that though. Has anyone done this before and knows what changes are needed?

IMediaStream pAudioStream = null;
_MediaStream = new MultimediaStream();
int mmr = _MediaStream.Initialize(STREAM_TYPE.STREAMTYPE_READ,    
                                 (int)AMMSF_INIT.AMMSF_NOGRAPHTHREAD, null);
mmr = _MediaStream.AddMediaStream(null, MSPurposeId.PrimaryAudio, 
                                  0, out pAudioStream);
MSStatus.ThrowExceptionForHR(mmr);

// open media file
mmr = _MediaStream.OpenFile(filePath, (int)AMMSF_OPEN.AMMSF_RUN);
MSStatus.ThrowExceptionForHR(mmr);

_AudioStream = new MMAudioStream();
mmr = _AudioStream.SetMediaStream(pAudioStream);
MSStatus.ThrowExceptionForHR(mmr);

_wfmt = new WaveFormat(_AudioStream.Format);
mmr = WaveDevice.Open(WaveConstants.WAVE_MAPPER, _wfmt);
WaveOutStatus.ThrowExceptionForHR(mmr);

WaveDevice is IWaveDevice and of type WaveOutDevice. This will be changed to type WaveInDevice, and WaveOutStatus to WaveInStatus obviously.

Here is the code for the class I've created in full. The Listen() method is the one I'm modifying.

http://pastebin.com/TQTwRHTF

This class was created by using the code provided in the SoundStudio project, using the WindowsMedia and PeakMeter provided by Ernzo.

If someone can figure out the changes to make Listen() work, that will earn them the bounty. (It currently has code I put in trying to figure it out, but the Play() is working just fine).

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

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

发布评论

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

评论(1

予囚 2024-10-31 03:54:03

有一个演示展示了如何使用waveIn。
__waveInput_SoundStudioFrm.cs,只需将其重命名为 SoundStudioFrm.cs

There is a demo that shows how to use waveIn.
__waveInput_SoundStudioFrm.cs, simply rename it as SoundStudioFrm.cs

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