title: How to Display AudioMeterInformation?
body: <p><strong>How to Display AudioMeterInformation?</strong></p>
  
  <p>I need to display metering for default capture device and output devices, similar to when you open windows Playback and Recording devices dialog in windows 7.</p>
  
  <p>There is an open source API available which is wrapper over windows core audio named naudio. The example provided is using WaveIn device to collect sound samples and then produce metering information</p>
  
  <pre><code>WaveIn = new WaveIn { DeviceNumber = 0 };
  WaveIn.DataAvailable += OnDataAvailable;
  WaveIn.RecordingStopped += OnRecordingStopped;
  WaveIn.WaveFormat = new WaveFormat(44100, 1);
  
  public virtual void OnDataAvailable(object sender, WaveInEventArgs e)
  {
      byte[] buffer = e.Buffer;
      for (int index = 0; index &lt; e.BytesRecorded; index += 2)
      {
          short sample = (short)((buffer[index + 1] &lt;&lt; 8) | buffer[index + 0]);
          float sample32 = sample / 32768f;
          SampleAggregator.Add(sample32);
      }
  }
  
  public class SampleAggregator
  {
      // volume
      private int Count { get; set; }
  
      public float MaxValue { get; set; }
      public float MinValue { get; set; }
      public int NotificationCount { get; set; }
      public event EventHandler&lt;MaxSampleEventArgs&gt; MaximumCalculated;
      public event EventHandler Restart = delegate { };
  
      public void RaiseRestart()
      {
          Restart(this, EventArgs.Empty);
      }
  
      private void Reset()
      {
          Count = 0;
          MaxValue = MinValue = 0;
      }
  
      public void Add(float value)
      {
          MaxValue = Math.Max(MaxValue, value);
          MinValue = Math.Min(MinValue, value);
  
          Count++;
  
          if (Count &gt;= NotificationCount &amp;&amp; NotificationCount &gt; 0)
          {
              if (MaximumCalculated != null)
              {
                  MaximumCalculated(this, new MaxSampleEventArgs(MinValue, MaxValue));
              }
  
              Reset();
          }
      }
  }
  </code></pre>
  
  <p>Taking samples would make sense in windows XP where AudioMeterInformation is not available.
  Can someone help to display AudioMeterInformation without having to take samples from the device.</p>