FireNotification() 개인적인 메소드

private FireNotification ( NAudio.CoreAudioApi.AudioVolumeNotificationData notificationData ) : void
notificationData NAudio.CoreAudioApi.AudioVolumeNotificationData
리턴 void
예제 #1
0
        public void OnNotify(IntPtr notifyData)
        {
            //Since AUDIO_VOLUME_NOTIFICATION_DATA is dynamic in length based on the
            //number of audio channels available we cannot just call PtrToStructure
            //to get all data, thats why it is split up into two steps, first the static
            //data is marshalled into the data structure, then with some IntPtr math the
            //remaining floats are read from memory.
            //
            var data = MarshalHelpers.PtrToStructure <AudioVolumeNotificationDataStruct>(notifyData);

            //Determine offset in structure of the first float
            var offset = MarshalHelpers.OffsetOf <AudioVolumeNotificationDataStruct>("ChannelVolume");
            //Determine offset in memory of the first float
            var firstFloatPtr = (IntPtr)((long)notifyData + (long)offset);

            var voldata = new float[data.nChannels];

            //Read all floats from memory.
            for (int i = 0; i < data.nChannels; i++)
            {
                voldata[i] = MarshalHelpers.PtrToStructure <float>(firstFloatPtr);
            }

            //Create combined structure and Fire Event in parent class.
            var notificationData = new AudioVolumeNotificationData(data.guidEventContext, data.bMuted, data.fMasterVolume, voldata, data.guidEventContext);

            parent.FireNotification(notificationData);
        }
        public void OnNotify(ref AudioVolumeNotificationDataStruct data)
        //public int OnNotify(IntPtr NotifyData)
        {
            //Since AUDIO_VOLUME_NOTIFICATION_DATA is dynamic in length based on the
            //number of audio channels available we cannot just call PtrToStructure
            //to get all data, thats why it is split up into two steps, first the static
            //data is marshalled into the data structure, then with some IntPtr math the
            //remaining floats are read from memory.
            //
            //AudioVolumeNotificationDataStruct data = (AudioVolumeNotificationDataStruct)Marshal.PtrToStructure(NotifyData, typeof(AudioVolumeNotificationDataStruct));

            //Determine offset in structure of the first float
            //IntPtr Offset = Marshal.OffsetOf(typeof(AudioVolumeNotificationDataStruct), "ChannelVolume");
            //Determine offset in memory of the first float
            //IntPtr FirstFloatPtr = (IntPtr)((long)NotifyData + (long)Offset);

            //float[] voldata = new float[data.nChannels];

            //Read all floats from memory.
            //for (int i = 0; i < data.nChannels; i++)
            //{
            //    voldata[i] = data.fMasterVolume;
            //}

            //Create combined structure and Fire Event in parent class.
            AudioVolumeNotificationData NotificationData = new AudioVolumeNotificationData(data.guidEventContext, data.bMuted, data.fMasterVolume);

            _Parent.FireNotification(NotificationData);
        }