Ejemplo n.º 1
0
        public static float[] ReadPeakValues(IAudioMeterInformation meter)
        {
            var ret = new float[2];

            try
            {
                uint chanCount = meter.GetMeteringChannelCount();
                if (chanCount > 0)
                {
                    var arrayPtr = Marshal.AllocHGlobal((int)chanCount * 4); // 4 bytes in float
                    if (meter.GetChannelsPeakValues(chanCount, arrayPtr) == HRESULT.S_OK)
                    {
                        var values = new float[chanCount];
                        Marshal.Copy(arrayPtr, values, 0, (int)chanCount);

                        if (chanCount == 1)
                        {
                            ret[0] = values[0];
                            ret[1] = values[0];
                        }
                        else
                        {
                            ret[0] = values[0];
                            ret[1] = values[1];
                        }
                    }
                }
            }
            catch (Exception ex) when(ex.Is(HRESULT.AUDCLNT_E_DEVICE_INVALIDATED))
            {
                // Expected in some cases.
            }
            return(ret);
        }
        public float[] GetChannelsPeakValues()
        {
            var result = new float[MeteringChannelCount];
            var Params = GCHandle.Alloc(result, GCHandleType.Pinned);

            Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetChannelsPeakValues(result.Length, Params.AddrOfPinnedObject()));
            Params.Free();
            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Get Peak value
 /// </summary>
 /// <param name="index">Channel index</param>
 /// <returns>Peak value</returns>
 unsafe public float this[int index] {
     get {
         var peakValues = new float[Count];
         fixed(float *peaks = peakValues)
         {
             audioMeterInformation.GetChannelsPeakValues(peakValues.Length, (IntPtr)peaks);
             return(peakValues[index]);
         }
     }
 }
Ejemplo n.º 4
0
 public float this[int index]
 {
     get
     {
         float[]  peakValues = new float[Count];
         GCHandle Params     = GCHandle.Alloc(peakValues, GCHandleType.Pinned);
         Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetChannelsPeakValues(peakValues.Length, Params.AddrOfPinnedObject()));
         Params.Free();
         return(peakValues[index]);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     Get Peak value
 /// </summary>
 /// <param name="index">Channel index</param>
 /// <returns>Peak value</returns>
 public float this[int index]
 {
     get
     {
         return(ComThread.Invoke(() =>
         {
             var peakValues = new float[Count];
             Marshal.ThrowExceptionForHR(
                 _audioMeterInformation.GetChannelsPeakValues(Convert.ToUInt32(peakValues.Length), peakValues));
             return peakValues[index];
         }));
     }
 }
        internal float[] GetPeaks()
        {
            if (_count == 0)
            {
                _count = GetCount();
            }

            var peakValues = new float[_count];
            var Params     = GCHandle.Alloc(peakValues, GCHandleType.Pinned);

            Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetChannelsPeakValues(peakValues.Length, Params.AddrOfPinnedObject()));
            Params.Free();
            return(peakValues);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Get Peak value
 /// </summary>
 /// <param name="index">Channel index</param>
 /// <returns>Peak value</returns>
 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];
         var Params     = GCHandle.Alloc(peakValues, GCHandleType.Pinned);
         Marshal.ThrowExceptionForHR(audioMeterInformation.GetChannelsPeakValues(peakValues.Length, Params.AddrOfPinnedObject()));
         Params.Free();
         return(peakValues[index]);
     }
 }
Ejemplo n.º 8
0
 // TODO - write directly to _peakLevelArgs?
 private void PeakMeter_GetValues()
 {
     if (pm_HasPeakMeter)
     {
         GCHandle values = GCHandle.Alloc(pm_PeakMeterValues, GCHandleType.Pinned);
         //pm_PeakMeterInfo.GetMeteringChannelCount(out pm_PeakMeterChannelCount);
         pm_PeakMeterInfo.GetChannelsPeakValues(pm_PeakMeterChannelCount, values.AddrOfPinnedObject());
         pm_PeakMeterInfo.GetPeakValue(out pm_PeakMeterMasterValue);
         values.Free();
     }
     else
     {
         for (int i = 0; i < MAX_AUDIO_CHANNELS; i++)
         {
             pm_PeakMeterValues[i] = STOP_VALUE;
         }
     }
 }