title: Convert this code to get Microphone Input? Class Source code included
body: <p>I'm using the WindowsMedia library found here: <a href="http://www.ernzo.com/soundstudio.aspx" rel="nofollow">http://www.ernzo.com/soundstudio.aspx</a></p>
  
  <p>The sample code had the ability to play audio files, however I'm trying to get the stream to come from the microphone.</p>
  
  <p>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.</p>
  
  <p>Not sure how to do that though. Has anyone done this before and knows what changes are needed?</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>WaveDevice is IWaveDevice and of type WaveOutDevice. This will be changed to type WaveInDevice, and WaveOutStatus to WaveInStatus obviously.</p>
  
  <p>Here is the code for the class I've created in full. The Listen() method is the one I'm modifying.</p>
  
  <p><a href="http://pastebin.com/TQTwRHTF" rel="nofollow">http://pastebin.com/TQTwRHTF</a></p>
  
  <p>This class was created by using the code provided in the SoundStudio project, using the WindowsMedia and PeakMeter provided by Ernzo.</p>
  
  <p>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).</p>