private void checkBoxPlaybackMute_CheckedChanged(object sender, EventArgs e) { CheckBox chkBox = (CheckBox)sender; MixerLine line = (MixerLine)chkBox.Tag; if (line.Direction == MixerType.Recording) { line.Channel = Channel.Uniform; //line.Selected = chkBox.Checked; if (checkBoxRecordingMute.Checked == true) { _lastMicVolume = line.Volume; line.Volume = 0; } else { line.Volume = _lastMicVolume; } } // set mute if possible if (line.ContainsMute) { line.Mute = chkBox.Checked; } }
static public void setVol() { try { int waveInDeviceNumber = Values.micpicked; var mixerLine = new MixerLine((IntPtr)waveInDeviceNumber, 0, MixerFlags.WaveIn); foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { UnsignedMixerControl volumeControl = control as UnsignedMixerControl; volumeControl.Percent = Values.prefvol; break; } } } catch (Exception) { if (Values.error == 0) { Values.error = 1; MessageBox.Show("==========PLEASE READ========== \n" + "This message only shows up ONCE per run, \n" + "it means the selected mic does not work. \n" + "Set the mic to 'Default' in your settings. \n" + "Afterwards restart the program. \n" + "==============================="); } } }
public Form1() { this.WindowState = FormWindowState.Minimized; InitializeComponent(); int waveInDeviceNumber = 0; MixerLine mixerLine = new MixerLine((IntPtr)waveInDeviceNumber, 0, MixerFlags.WaveIn); MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); device = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications); device.AudioEndpointVolume.OnVolumeNotification += audioModifyEvent; foreach (MixerControl control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { volumeControl = control as UnsignedMixerControl; break; } } trackBar1.Value = (int)Math.Round(volumeControl.Percent); volume = trackBar1.Value; }
/// <summary>Return the info for a mixer line component</summary> public MixerLine LineInfo(EMixerLineComponentType line_component_type) { MixerLine line = MixerLine.New; line.dwComponentType = (uint)line_component_type; Check(mixerGetLineInfoA(Handle, ref line, (uint)EMixerGetLineInfoFlag.COMPONENTTYPE)); return(line); }
private void RunMicroCallback(Mixer mixer, MixerLine line) { MixerLine defaultLine = null; foreach (MixerLine itemLine in Mixers.Recording.UserLines) { if (itemLine.ComponentType == MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE) { defaultLine = itemLine; break; } } if (defaultLine != null) { int VolumeMin = defaultLine.VolumeMin; int VolumeMax = defaultLine.VolumeMax; int VolumeCurrent = defaultLine.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 = defaultLine.Mute; if (_callback != null) { _callback.Invoke(new DeviceInfo(volume, muted)); } } }
private void toolStripTrackBar_ValueChanged(object sender, EventArgs e) { if (mAvoidEvents) return; TrackBar tBar = (TrackBar)sender; MixerLine line = (MixerLine)tBar.Tag; if (line.Direction == MixerType.Recording) { line.Volume = toolStripTrackBar2.Value; line.Mute = line.Volume == 0; toolStripMicMuteButton.Image = line.Mute ? Sipek.Properties.Resources.ico_mutedin : Sipek.Properties.Resources.ico_mutein; toolStripMicMuteButton.Checked = line.Mute; } else { if (line.Channels != 2) { // One channel or more than two let set the volume uniform line.Channel = Channel.Uniform; line.Volume = tBar.Value; } else { //Set independent volume line.Channel = Channel.Uniform; line.Volume = toolStripTrackBar1.Value; } line.Mute = line.Volume == 0; toolStripMuteButton.Image = line.Mute ? Sipek.Properties.Resources.ico_mutedout : Sipek.Properties.Resources.ico_muteout; toolStripMuteButton.Checked = line.Mute; } }
/// <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)toolStripTrackBar1.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) toolStripTrackBar1.Value = volume; } // adjust toolstrip checkboxes if ((MixerLine)toolStripMicMuteButton.Tag == line) { toolStripMicMuteButton.Checked = line.Volume == 0 ? true : false; toolStripMicMuteButton.Image = line.Volume == 0 ? Sipek.Properties.Resources.ico_mutedin : Sipek.Properties.Resources.ico_mutein; } else if ((MixerLine)toolStripMuteButton.Tag == line) { toolStripMuteButton.Checked = line.Mute; toolStripMuteButton.Image = line.Mute ? Sipek.Properties.Resources.ico_mutedout : Sipek.Properties.Resources.ico_muteout; } } finally { mAvoidEvents = false; } }
private void toolStripMuteButton_Click(object sender, EventArgs e) { ToolStripButton chkBox = (ToolStripButton)sender; MixerLine line = (MixerLine)chkBox.Tag; if (line.Direction == MixerType.Recording) { if (chkBox.Checked == true) { _lastMicVol = line.Volume; line.Volume = 0; } else { line.Volume = _lastMicVol; } toolStripTrackBar2.Value = line.Volume; toolStripMicMuteButton.Image = line.Volume == 0 ? Sipek.Properties.Resources.ico_mutedin : Sipek.Properties.Resources.ico_mutein; } else { if (chkBox.Checked == true) { _lastVol = line.Volume; line.Volume = 0; } else { line.Volume = _lastVol; } line.Mute = chkBox.Checked; toolStripMuteButton.Image = line.Mute ? Sipek.Properties.Resources.ico_mutedout : Sipek.Properties.Resources.ico_muteout; } }
public void CanGetWaveInMixerLine() { using (WaveIn waveIn = new WaveIn()) { MixerLine line = waveIn.GetMixerLine(); //Debug.WriteLine(String.Format("Mic Level {0}", level)); } }
private void LoadAudioValues() { try { mMixers = new Mixers(); } catch (Exception e) { ///report error (new ErrorDialog("Initialize Error ", "Audio Mixer cannot initialize! \r\nCheck audio configuration and start again!\r\n" + e.Message)).ShowDialog(); return; } // set callback mMixers.Playback.MixerLineChanged += new WaveLib.AudioMixer.Mixer.MixerLineChangeHandler(mMixer_MixerLineChanged); mMixers.Recording.MixerLineChanged += new WaveLib.AudioMixer.Mixer.MixerLineChangeHandler(mMixer_MixerLineChanged); MixerLine pbline = mMixers.Playback.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.SRC_WAVEOUT); toolStripTrackBar1.Tag = pbline; toolStripMuteButton.Tag = pbline; MixerLine recline = mMixers.Recording.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE); toolStripTrackBar2.Tag = recline; toolStripMicMuteButton.Tag = recline; //If it is 2 channels then ask both and set the volume to the bigger but keep relation between them (Balance) int volume = 0; float balance = 0; if (pbline.Channels != 2) volume = pbline.Volume; else { pbline.Channel = Channel.Left; int left = pbline.Volume; pbline.Channel = Channel.Right; int right = pbline.Volume; if (left > right) { volume = left; balance = (volume > 0) ? -(1 - (right / (float)left)) : 0; } else { volume = right; balance = (volume > 0) ? (1 - (left / (float)right)) : 0; } } if (volume >= 0) this.toolStripTrackBar1.Value = volume; else this.toolStripTrackBar1.Enabled = false; // toolstrip checkboxes this.toolStripMuteButton.Checked = pbline.Mute; this.toolStripMicMuteButton.Checked = recline.Volume == 0 ? true : false; _lastMicVol = recline.Volume; }
private static void ExploreMixerSource(MixerLine destinationLine, int sourceIndex) { var sourceLine = destinationLine.GetSource(sourceIndex); Debug.WriteLine(String.Format("Source {0}: {1}", sourceIndex, sourceLine)); foreach (MixerControl control in sourceLine.Controls) { Debug.WriteLine(String.Format("CONTROL: {0}", control)); } }
private static void SetVolumeControlById(int id) { var mixerLine = new MixerLine(( IntPtr )id, 0, MixerFlags.WaveIn); foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { VolumeControl = control as UnsignedMixerControl; break; } } }
private void trackBarPlaybackVolume_ValueChanged(object sender, EventArgs e) { if (mAvoidEvents) { return; } TrackBar tBar = (TrackBar)sender; MixerLine line = (MixerLine)tBar.Tag; if (line.Channels != 2) { // One channel or more than two let set the volume uniform line.Channel = Channel.Uniform; line.Volume = tBar.Value; } else { TrackBar tBarBalance = trackBarPlaybackBalance; //Set independent volume //foreach (TrackBar tBarBalance in tBarBalanceArray[(int)line.Mixer.MixerType]) { MixerLine frontEndLine = (MixerLine)tBarBalance.Tag; if (frontEndLine == line) { if (tBarBalance.Value == 0) { line.Channel = Channel.Uniform; line.Volume = tBar.Value; } if (tBarBalance.Value <= 0) { // Left channel is bigger line.Channel = Channel.Left; line.Volume = tBar.Value; line.Channel = Channel.Right; line.Volume = (int)(tBar.Value * (1 + (tBarBalance.Value / (float)tBarBalance.Maximum))); } else { // Right channel is bigger line.Channel = Channel.Right; line.Volume = tBar.Value; line.Channel = Channel.Left; line.Volume = (int)(tBar.Value * (1 - (tBarBalance.Value / (float)tBarBalance.Maximum))); } //break; } } } }
void SetMicInputVolume(int input_vol) { int waveInDeviceNumber = 0; var mixerLine = new MixerLine((IntPtr)waveInDeviceNumber, 0, MixerFlags.WaveIn); foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { Mic_Input_Volume_Control = control as UnsignedMixerControl; Mic_Input_Volume_Control.Percent = input_vol; } } }
public MixerLine GetMixerLine() { MixerLine result; if (this.waveInHandle != IntPtr.Zero) { result = new MixerLine(this.waveInHandle, 0, MixerFlags.WaveInHandle); } else { result = new MixerLine((IntPtr)this.DeviceNumber, 0, MixerFlags.WaveIn); } return(result); }
/// <summary> /// Microphone Level /// </summary> public MixerLine GetMixerLine() { MixerLine mixerLine; if (waveInHandle != IntPtr.Zero) { mixerLine = new MixerLine(this.waveInHandle, 0, MixerFlags.WaveInHandle); } else { mixerLine = new MixerLine((IntPtr)DeviceNumber, 0, MixerFlags.WaveIn); } return(mixerLine); }
private void TryGetVolumeControl() { int waveInDeviceNumber = 0; var mixerLine = new MixerLine((IntPtr)waveInDeviceNumber, 0, MixerFlags.WaveIn); foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { volumeControlList.Add(control as UnsignedMixerControl); break; } } }
/// <summary> /// Microphone Level /// </summary> public MixerLine GetMixerLine() { // TODO use mixerGetID instead to see if this helps with XP MixerLine mixerLine; if (waveInHandle != IntPtr.Zero) { mixerLine = new MixerLine(this.waveInHandle, 0, MixerFlags.WaveInHandle); } else { mixerLine = new MixerLine((IntPtr)DeviceNumber, 0, MixerFlags.WaveIn); } return(mixerLine); }
public int GetMicInputVolume() { int waveInDeviceNumber = 0; var mixerLine = new MixerLine((IntPtr)waveInDeviceNumber, 0, MixerFlags.WaveIn); foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { Mic_Input_Volume_Control = control as UnsignedMixerControl; return(Convert.ToInt16(Mic_Input_Volume_Control.Percent)); } } return(50); }
/// <summary>Retrieve mixer data</summary> public MixerControl LineControl(EMixerLineComponentType line_component_type, EMixerCtrlType ctrl_type) { uint mixer_data_size = (uint)Marshal.SizeOf(typeof(MixerControl)); MixerLine line = LineInfo(line_component_type); MixerLineControls line_ctrls = MixerLineControls.New; line_ctrls.pamxctrl = Marshal.AllocCoTaskMem((int)mixer_data_size); line_ctrls.dwLineID = line.dwLineID; line_ctrls.dwControlType = (uint)ctrl_type; line_ctrls.cControls = 1; line_ctrls.cbmxctrl = mixer_data_size; Check(mixerGetLineControlsA(Handle, ref line_ctrls, (uint)EMixerGetLineControlsFlag.ONEBYTYPE)); return((MixerControl?)Marshal.PtrToStructure(line_ctrls.pamxctrl, typeof(MixerControl)) ?? throw new NullReferenceException($"Null returned for WinMM MixerControl")); }
private void btnSetVolume_Click(object sender, EventArgs e) { int waveInDeviceNumber = waveIn.DeviceNumber; var mixerLine = new MixerLine((IntPtr)waveInDeviceNumber, 0, MixerFlags.WaveIn); foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { volumeControl = control as UnsignedMixerControl; MicrophoneLevel = desiredVolume; break; } } }
private void SetRecordingVolume() { int waveInDeviceNumber = 0; var mixerLine = new MixerLine((IntPtr)waveInDeviceNumber, 0, MixerFlags.WaveIn); foreach (var control in mixerLine.Controls) { if (control.ControlType == MixerControlType.Volume) { var volumeControl = control as UnsignedMixerControl; volumeControl.Percent = RecordingVolume; break; } } }
private void trackBarPlaybackBalance_ValueChanged(object sender, EventArgs e) { if (mAvoidEvents) { return; } TrackBar tBarBalance = (TrackBar)sender; MixerLine line = (MixerLine)tBarBalance.Tag; //This demo just set balance when they are just 2 channels if (line.Channels == 2) { //Set independent volume TrackBar tBarVolume = trackBarPlaybackVolume; //foreach (TrackBar tBarVolume in tBarArray[(int)line.Mixer.MixerType]) { MixerLine frontEndLine = (MixerLine)tBarVolume.Tag; if (frontEndLine == line) { if (tBarBalance.Value == 0) { line.Channel = Channel.Uniform; line.Volume = tBarVolume.Value; } if (tBarBalance.Value <= 0) { // Left channel is bigger line.Channel = Channel.Left; line.Volume = tBarVolume.Value; line.Channel = Channel.Right; line.Volume = (int)(tBarVolume.Value * (1 + (tBarBalance.Value / (float)tBarBalance.Maximum))); } else { // Rigth channel is bigger line.Channel = Channel.Right; line.Volume = tBarVolume.Value; line.Channel = Channel.Left; line.Volume = (int)(tBarVolume.Value * (1 - (tBarBalance.Value / (float)tBarBalance.Maximum))); } //break; } } } }
private float adjustValues(MixerLine line, TrackBar tBar) { float balance = -1; 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; } } return(balance); }
private void trackBarRecordingVolume_ValueChanged(object sender, EventArgs e) { if (mAvoidEvents) { return; } TrackBar tBar = (TrackBar)sender; MixerLine line = (MixerLine)tBar.Tag; // One channel or more than two let set the volume uniform line.Channel = Channel.Uniform; line.Volume = tBar.Value; _lastMicVolume = line.Volume; this.checkBoxRecordingMute.Checked = line.Volume == 0 ? true : false; }
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; } }
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 { } }
private void RunCallback(Mixer mixer, MixerLine line) { int VolumeMin = Mixers.Playback.UserLines[0].VolumeMin; int VolumeMax = Mixers.Playback.UserLines[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.UserLines[0].Mute; if (_callback != null) { _callback.Invoke(new DeviceInfo(volume, muted)); } }
protected static UnsignedMixerControl GetVolumeMixerControlForInputLine(MixerLine destination) { if (destination.ComponentType == MixerLineComponentType.DestinationWaveIn) { foreach (MixerLine source in destination.Sources) { if (source.ComponentType == MixerLineComponentType.SourceMicrophone) { foreach (MixerControl control in source.Controls) { if (control.ControlType == MixerControlType.Volume) { return((UnsignedMixerControl)control); } } } } } return(null); }
public void CanFindDefaultWaveIn() { int defaultWaveInMixerId = MixerLine.GetMixerIdForWaveIn(0); Mixer mixer = new Mixer(defaultWaveInMixerId); foreach (MixerLine destination in mixer.Destinations) { Debug.WriteLine(String.Format("DESTINATION: {0} {1} (Type: {2}, Target: {3})", destination.Name, destination.TypeDescription, destination.ComponentType, destination.TargetName)); if (destination.ComponentType == MixerLineComponentType.DestinationWaveIn) { foreach (MixerLine source in destination.Sources) { Debug.WriteLine(String.Format("{0} {1} (Source: {2}, Target: {3})", source.Name, source.TypeDescription, source.IsSource, source.TargetName)); if (source.ComponentType == MixerLineComponentType.SourceMicrophone) { Debug.WriteLine(String.Format("Found the microphone: {0}", source.Name)); foreach (MixerControl control in source.Controls) { if (control.ControlType == MixerControlType.Volume) { Debug.WriteLine(String.Format("Volume Found: {0}", control)); UnsignedMixerControl umc = (UnsignedMixerControl)control; uint originalValue = umc.Value; umc.Value = umc.MinValue; Assert.AreEqual(umc.MinValue, umc.Value, "Set Minimum Correctly"); umc.Value = umc.MaxValue; Assert.AreEqual(umc.MaxValue, umc.Value, "Set Maximum Correctly"); umc.Value = umc.MaxValue / 2; Assert.AreEqual(umc.MaxValue / 2, umc.Value, "Set MidPoint Correctly"); umc.Value = originalValue; Assert.AreEqual(originalValue, umc.Value, "Set Original Correctly"); } } } } } } }
public static extern MixerError mixerGetLineInfoA(IntPtr handle, ref MixerLine mixerLine, MixerLineFlags flags);