Пример #1
0
            private static Win7ComInterface.IAudioMeterInformation GetAudioMeterInformation()
            {
                Win7ComInterface.IAudioMeterInformation result = null;
                InvokeTryCatch("Win7VolumeOperate.GetAudioMeterInformation", () =>
                {
                    Win7ComInterface.IMMDevice device = Device;
                    if (device == null)
                    {
                        return;
                    }

                    const uint CLSCTX_ALL = 23u;

                    object comMeterInfo;
                    Guid IID_IAudioMeterInformation = typeof(Win7ComInterface.IAudioMeterInformation).GUID;
                    Marshal.ThrowExceptionForHR(device.Activate(ref IID_IAudioMeterInformation, CLSCTX_ALL, IntPtr.Zero, out comMeterInfo));
                    Win7ComInterface.IAudioMeterInformation meterInfo = comMeterInfo as Win7ComInterface.IAudioMeterInformation;

                    if (meterInfo == null)
                    {
                        throw new Exception("初始化 Win7以上操作系统的 音频Com IAudioMeterInformation 组件失败!");
                    }

                    int HardwareSupp;
                    Marshal.ThrowExceptionForHR(meterInfo.QueryHardwareSupport(out HardwareSupp));
                    result = meterInfo;
                });
                return(result);
            }
Пример #2
0
            private static float GetAudioMeterInfoPeakValue()
            {
                float result = 0;

                InvokeTryCatch("Win7VolumeOperate.GetAudioMeterInfoPeakValue", () =>
                {
                    Win7ComInterface.IAudioMeterInformation audioMeterInfo = AudioMeterInfo;
                    if (audioMeterInfo == null)
                    {
                        return;
                    }

                    float temp;
                    Marshal.ThrowExceptionForHR(audioMeterInfo.GetPeakValue(out temp));
                    result = temp;
                });
                return(result);
            }
Пример #3
0
            private static int GetAudioMeterInfoCount()
            {
                int result = 0;

                InvokeTryCatch("Win7VolumeOperate.GetAudioMeterInfoCount", () =>
                {
                    Win7ComInterface.IAudioMeterInformation audioMeterInfo = AudioMeterInfo;
                    if (audioMeterInfo == null)
                    {
                        return;
                    }

                    int temp;
                    Marshal.ThrowExceptionForHR(audioMeterInfo.GetMeteringChannelCount(out temp));
                    result = temp;
                });
                return(result);
            }
Пример #4
0
            private static float[] GetAudioMeterInfoChannelsPeakValues()
            {
                float[] result = new float[] { 0f, 0f };
                InvokeTryCatch("Win7VolumeOperate.GetAudioMeterInfoChannelsPeakValues", () =>
                {
                    Win7ComInterface.IAudioMeterInformation audioMeterInfo = AudioMeterInfo;
                    if (audioMeterInfo == null)
                    {
                        return;
                    }

                    int count;
                    Marshal.ThrowExceptionForHR(audioMeterInfo.GetMeteringChannelCount(out count));

                    float[] peakValues = new float[count];
                    GCHandle Params    = GCHandle.Alloc(peakValues, GCHandleType.Pinned);
                    Marshal.ThrowExceptionForHR(audioMeterInfo.GetChannelsPeakValues(peakValues.Length, Params.AddrOfPinnedObject()));
                    Params.Free();
                    result = peakValues;
                });
                return(result);
            }