开发者

Convert this code to get Microphone Input? Class Source code included

开发者 https://www.devze.com 2023-02-18 05:52 出处:网络
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 micro

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 pAu开发者_C百科dioStream);
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).


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号