Ejemplo n.º 1
0
        public Mixers(bool ignoreExceptions)
        {
            if (ignoreExceptions)
            {
                try
                {
                    mRecording = new Mixer(MixerType.Recording);
                }
                catch (Exception)
                {
                    mRecording = null;
                }
            }
            else
                mRecording = new Mixer(MixerType.Recording);

            if (ignoreExceptions)
            {
                try
                {
                    mPlayback = new Mixer(MixerType.Playback);
                }
                catch (Exception)
                {
                    mPlayback = null;
                }
            }
            else
                mPlayback	= new Mixer(MixerType.Playback);
        }
        public XPAudioDeviceControl()
        {
            //audioDevices = new Microsoft.DirectX.DirectSound.CaptureDevicesCollection();

            mixers = new Mixers(true);
            captureMixer = mixers.Recording;
            renderMixer = mixers.Playback;

            if (captureMixer != null)
            {
                // Set the current default values:
                // For the Device interface
                CaptureDeviceInterface = captureMixer.DeviceDetail.MixerName;

                // For the Device line
                if (captureMixer.UserLines.Count > 0)
                {
                    _UnselectableMixerLineName = captureMixer.UserLines[0].Name;
                    MixerLine selectedCaptureMixerLine = getSelectedMixerLine(captureMixer);
                    CaptureDeviceLine = selectedCaptureMixerLine.Name;
                }
                else
                {
                    throw new DeviceInterfaceException(CaptureDeviceInterface, "No capture line detected for the " + CaptureDeviceInterface + " device interface.");
                }

            }

            // Not supported for now.
            // RenderDeviceInterface = renderMixer.DeviceDetail.MixerName;
            // MixerLine selectedRenderMixerLine = getSelectedMixerLine(renderMixer);
            // RenderDeviceLine = selectedRenderMixerLine.Name;
        }
Ejemplo n.º 3
0
        private void RunCallback(Mixer mixer, MixerLine line)
        {
            int VolumeMin = Mixers.Playback.Lines[0].VolumeMin;
            int VolumeMax = Mixers.Playback.Lines[0].VolumeMax;
            int VolumeCurrent = Mixers.Playback.Lines[0].Volume;

            // Volume Min and Max are probably 0, and 100, but since I can't say that for sure adjust the values to be zero based
            VolumeMax = VolumeMax - VolumeMin;
            VolumeCurrent = VolumeCurrent - VolumeMin;
            VolumeMin = 0;

            double volume = ((double)VolumeCurrent)/((double) VolumeMax);
            bool muted = Mixers.Playback.Lines[0].Mute;

            if(_callback != null)
                _callback.Invoke(new DeviceInfo(volume, muted));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Callback from Windows Volume Control
        /// </summary>
        /// <param name="mixer"></param>
        /// <param name="line"></param>
        private void mMixer_MixerLineChanged(Mixer mixer, MixerLine line)
        {
            mAvoidEvents = true;

            try
            {
                float balance = -1;
                MixerLine frontEndLine = (MixerLine)volumeTrackBar.Tag;
                if (frontEndLine == line)
                {
                    int volume = 0;
                    if (line.Channels != 2)
                        volume = line.Volume;
                    else
                    {
                        line.Channel = Channel.Left;
                        int left = line.Volume;
                        line.Channel = Channel.Right;
                        int right = line.Volume;
                        if (left > right)
                        {
                            volume = left;
                            // TIP: Do not reset the balance if both left and right channel have 0 value
                            if (left != 0 && right != 0)
                                balance = (volume > 0) ? -(1 - (right / (float)left)) : 0;
                        }
                        else
                        {
                            volume = right;
                            // TIP: Do not reset the balance if both left and right channel have 0 value
                            if (left != 0 && right != 0)
                                balance = (volume > 0) ? 1 - (left / (float)right) : 0;
                        }
                    }

                    if (volume >= 0)
                        volumeTrackBar.Value = volume;

                }

                // adjust toolstrip checkboxes
                if ((MixerLine)micMuteButton.Tag == line)
                {
                    micMuteButton.ButtonToggled = line.Volume == 0 ? true : false;
                }
                else if ((MixerLine)muteButton.Tag == line)
                {
                    muteButton.ButtonToggled = line.Mute;
                }
            }
            finally
            {
                mAvoidEvents = false;
            }
        }
Ejemplo n.º 5
0
 private void mMixer_MixerLineChanged(Mixer mixer, MixerLine line)
 {
     //mAvoidEvents = true;
 }
        /// <summary>
        /// Set the device interface to be used
        /// </summary>
        /// <param name="mixer"></param>
        /// <param name="deviceInterface">The name of the device interface (e.g. "XYZ Audio Adapter")</param>
        private void setDeviceInterface(Mixer mixer, string deviceInterface)
        {
            bool deviceFound = false;

            MixerDetails mixerDetails = mixer.Devices;

            foreach (MixerDetail mixerDetail in mixerDetails)
            {
                if (mixerDetail.MixerName == deviceInterface)
                {

                    if (mixer.MixerType == MixerType.Recording)
                    {
                        mixers.Recording.DeviceId = mixerDetail.DeviceId;
                    }
                    else if (mixer.MixerType == MixerType.Playback)
                    {
                        mixers.Playback.DeviceId = mixerDetail.DeviceId;
                    }

                    mixer.DeviceId = mixerDetail.DeviceId;
                    deviceFound = true;
                    break;
                }
            }

            if (!deviceFound)
            {
                throw new DeviceInterfaceException(deviceInterface, "The " + deviceInterface + " device interface was not found.");
            }
        }
        /// <summary>
        /// Get the device Mixer Line that has been set to operate on.
        /// </summary>
        /// <param name="mixer"></param>
        /// <returns></returns>
        private MixerLine getSelectedMixerLine(Mixer mixer)
        {
            IEnumerator recordinLineEnum = mixer.UserLines.GetEnumerator();
            MixerLine mixerLine = null;

            while (recordinLineEnum.MoveNext())
            {
                mixerLine = (MixerLine)recordinLineEnum.Current;
                if (mixerLine.ContainsSelected)
                {
                    if (mixerLine.Selected)
                    {
                        return mixerLine;
                    }

                }
                else if (mixerLine.Name == _UnselectableMixerLineName)
                {
                    return mixerLine;
                }
            }

            string deviceLineName = null;
            if (mixer.MixerType == MixerType.Playback)
            {
                deviceLineName = RenderDeviceLine;
            }
            else
            {
                deviceLineName = CaptureDeviceLine;
            }

            throw new UnselectableDeviceLineException(mixer.DeviceDetail.MixerName, deviceLineName, "The target device line was unselectable.");
        }
        public Dictionary<string, List<AudioLineInfo>> getDeviceNames(Mixer mixer, Dictionary<string, List<AudioLineInfo>> deviceDictionary)
        {
            // Clear dictionary of previously added data (in case some devices have been unplugged or new ones have been plugged in)
            deviceDictionary.Clear();

            foreach (MixerDetail mixerDetail in mixer.Devices)
            {
                // Get the device's interface name
                string deviceInterfaceFriendlyName = mixerDetail.MixerName;

                // Which is set as a dictionary key if a different line already exists for it...
                if (!deviceDictionary.ContainsKey(deviceInterfaceFriendlyName))
                {
                    // If this device interface name hasn't already set as a dictionary key, then create a new entry for it.
                    deviceDictionary[deviceInterfaceFriendlyName] = new List<AudioLineInfo>();
                }

                // Create a mixer object based on the current deviceId so that we can retrieve the lines.
                mixers = new Mixers(true);
                Mixer mixer2 = null;

                // Get proper mixer type
                if (mixer.MixerType == MixerType.Playback){
                    mixer2 = mixers.Playback;
                }

                else if(mixer.MixerType == MixerType.Recording){
                    mixer2 = mixers.Recording;
                }

                // Set the device id
                mixer2.DeviceId = mixerDetail.DeviceId;

                // Retrieve the mixer lines and set them in the dictionar
                foreach (MixerLine mixerLine in mixer2.UserLines)
                {
                    /**
                     * Create the line name and interface friendly name (mixer name) pair to associate with the mixer name.
                     *
                     * But what? We are associating the mixer name with the mixer name? Isn't this unecessary redundancy?
                     * We have too because these two values are only identical under XP. In Vista and Windows7 The will be different so this
                     * is why we structure the response this way.
                     * Check out the Vista implementation for further details.
                     */
                    //KeyValuePair<string, string> lineNameAndFriendlyNamePair = new KeyValuePair<string, string>(mixerLine.Name, mixerDetail.MixerName);

                    // Gather device line properties to associate with the device's interface name.
                    AudioLineInfo audioLineInfo = new AudioLineInfo();

                    // Line name is confusingly known as the device friendly name.
                    audioLineInfo.LineName = mixerLine.Name;

                    // The device's friendly name (the REAL friendly name).
                    audioLineInfo.FriendlyName = mixerDetail.MixerName;

                    // Is the device line mutable
                    audioLineInfo.Mutable = mixerLine.ContainsMute;

                    deviceDictionary[mixerDetail.MixerName].Add(audioLineInfo);

                }

            }

            return deviceDictionary;
        }
Ejemplo n.º 9
0
    private void mMixer_MixerLineChanged(Mixer mixer, MixerLine line)
    {
      mAvoidEvents = true;

      try
      {
        if (line.Direction == MixerType.Playback)
        {
          float balance = adjustValues(line, trackBarPlaybackVolume);

          //Set the balance
          if (balance != -1)
          {
            if ((MixerLine)trackBarPlaybackBalance.Tag == line)
            {
              trackBarPlaybackBalance.Value = (int)(trackBarPlaybackBalance.Maximum * balance);
            }
          }

          // adjust checkboxes
          checkBoxPlaybackMute.Checked = line.Mute;
        }
        else if (line.Direction == MixerType.Recording)
        {
          line.Channel = Channel.Uniform;
          // adjust recording 
          float balance = adjustValues(line, trackBarRecordingVolume);
          //Set the balance
          //if (balance != -1)
          //{
          //  if ((MixerLine)trackBarRecordingBalance.Tag == line)
          //  {
          //    trackBarRecordingBalance.Value = (int)(trackBarRecordingBalance.Maximum * balance);
          //  }
          //}
          // adjust checkboxes
          checkBoxRecordingMute.Checked = (line.Volume == 0 ? true : false);

        }
      }
      finally
      {
        mAvoidEvents = false;
      }
    }
Ejemplo n.º 10
0
		private void mMixer_MixerLineChanged(Mixer mixer, MixerLine line)
		{
			mAvoidEvents = true;

			try
			{
				float balance = -1;
				foreach(TrackBar tBar in tBarArray[(int) mixer.MixerType])
				{
					MixerLine frontEndLine = (MixerLine) tBar.Tag;
					if (frontEndLine == line)
					{
						int volume = 0;
						if (line.Channels != 2)
							volume = line.Volume;
						else
						{
							line.Channel = Channel.Left;
							int left	= line.Volume;
							line.Channel = Channel.Right;
							int right	= line.Volume;
							if (left > right)
							{
								volume = left;
								// TIP: Do not reset the balance if both left and right channel have 0 value
								if (left != 0 && right != 0)
									balance = (volume > 0) ? -(1 - (right / (float) left)) : 0;
							}
							else
							{
								volume = right;
								// TIP: Do not reset the balance if both left and right channel have 0 value
								if (left != 0 && right != 0)
									balance = (volume > 0) ? 1 - (left / (float) right) : 0;
							}
						}

						if (volume >= 0)
							tBar.Value = volume;
						break;
					}
				}
				//Set the balance
				if (balance != -1)
				{
					foreach(TrackBar tBar in tBarBalanceArray[(int) mixer.MixerType])
					{
						MixerLine frontEndLine = (MixerLine) tBar.Tag;
						if (frontEndLine == line)
						{
							tBar.Value = (int) (tBar.Maximum * balance);
							break;
						}
					}
				}

				foreach(CheckBox checkBox in chkBoxArray[(int) mixer.MixerType])
				{
					MixerLine frontEndLine = (MixerLine) checkBox.Tag;
					if (frontEndLine == line)
					{
						if (line.Direction == MixerType.Recording)
							checkBox.Checked = line.Selected;
						else
							checkBox.Checked = line.Mute;
						break;
					}
				}
			}
			finally
			{
				mAvoidEvents = false;
			}
		}
Ejemplo n.º 11
0
        private void mMixer_MixerLineChanged(Mixer mixer, MixerLine line)
        {
            //mAvoidEvents = true;

            try
            {
                float balance = -1;
                TrackBar tBar =trackBarVolume;

                    MixerLine frontEndLine = (MixerLine)tBar.Tag;
                    if (frontEndLine == line)
                    {
                        int volume = 0;
                        if (line.Channels != 2)
                            volume = line.Volume;
                        else
                        {
                            line.Channel = Channel.Left;
                            int left = line.Volume;
                            line.Channel = Channel.Right;
                            int right = line.Volume;
                            if (left > right)
                            {
                                volume = left;
                                // TIP: Do not reset the balance if both left and right channel have 0 value
                                if (left != 0 && right != 0)
                                    balance = (volume > 0) ? -(1 - (right / (float)left)) : 0;
                            }
                            else
                            {
                                volume = right;
                                // TIP: Do not reset the balance if both left and right channel have 0 value
                                if (left != 0 && right != 0)
                                    balance = (volume > 0) ? 1 - (left / (float)right) : 0;
                            }
                        }

                        if (volume >= 0)
                            tBar.Value = volume;

                    }

                //Set the balance
                if (balance != -1)
                {

                        MixerLine frontEndLine2 = (MixerLine)tBar.Tag;
                        if (frontEndLine2 == line)
                        {
                            tBar.Value = (int)(tBar.Maximum * balance);

                        }

                }

            }
            finally
            {
                //mAvoidEvents = false;
            }
        }
Ejemplo n.º 12
0
 private void mMixer_MixerLineChanged(Mixer mixer, MixerLine line)
 {
     try
     {
             int volume = 0;
                 volume = line.Volume;
         if ((MixerLine)chkMutein.Tag == line)
         {
             chkMutein.Checked = line.Volume == 0 ? true : false;
         }
         else if ((MixerLine)chkMuteOut.Tag == line)
         {
             chkMuteOut.Checked = line.Mute;
         }
     }
     finally
     {
     }
 }
Ejemplo n.º 13
0
 public Mixers()
 {
     mRecording = new Mixer(MixerType.Recording);
     mPlayback  = new Mixer(MixerType.Playback);
 }
Ejemplo n.º 14
0
 public Mixers()
 {
     mRecording	= new Mixer(MixerType.Recording);
     mPlayback	= new Mixer(MixerType.Playback);
 }