Skip to content

Commit

Permalink
improved error message for channel index out of range #208
Browse files Browse the repository at this point in the history
  • Loading branch information
markheath committed Jul 22, 2017
1 parent 17c8ca2 commit 8b8ff19
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions NAudio/CoreAudioApi/AudioMeterInformationChannels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace NAudio.CoreAudioApi
/// </summary>
public class AudioMeterInformationChannels
{
readonly IAudioMeterInformation audioMeterInformation;
private readonly IAudioMeterInformation audioMeterInformation;

/// <summary>
/// Metering Channel Count
Expand All @@ -54,8 +54,14 @@ public float this[int index]
{
get
{
var channels = Count;
if (index >= channels)
{
throw new ArgumentOutOfRangeException(nameof(index),
$"Peak index cannot be greater than number of channels ({channels})");
}
var peakValues = new float[Count];
GCHandle Params = GCHandle.Alloc(peakValues, GCHandleType.Pinned);
var Params = GCHandle.Alloc(peakValues, GCHandleType.Pinned);
Marshal.ThrowExceptionForHR(audioMeterInformation.GetChannelsPeakValues(peakValues.Length, Params.AddrOfPinnedObject()));
Params.Free();
return peakValues[index];
Expand Down

0 comments on commit 8b8ff19

Please sign in to comment.