File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ namespace NAudio.CoreAudioApi
3030 /// </summary>
3131 public class AudioMeterInformationChannels
3232 {
33- readonly IAudioMeterInformation audioMeterInformation ;
33+ private readonly IAudioMeterInformation audioMeterInformation ;
3434
3535 /// <summary>
3636 /// Metering Channel Count
@@ -54,8 +54,14 @@ public float this[int index]
5454 {
5555 get
5656 {
57+ var channels = Count ;
58+ if ( index >= channels )
59+ {
60+ throw new ArgumentOutOfRangeException ( nameof ( index ) ,
61+ $ "Peak index cannot be greater than number of channels ({ channels } )") ;
62+ }
5763 var peakValues = new float [ Count ] ;
58- GCHandle Params = GCHandle . Alloc ( peakValues , GCHandleType . Pinned ) ;
64+ var Params = GCHandle . Alloc ( peakValues , GCHandleType . Pinned ) ;
5965 Marshal . ThrowExceptionForHR ( audioMeterInformation . GetChannelsPeakValues ( peakValues . Length , Params . AddrOfPinnedObject ( ) ) ) ;
6066 Params . Free ( ) ;
6167 return peakValues [ index ] ;
You can’t perform that action at this time.
0 commit comments