Ejemplo n.º 1
0
        internal AudioLine(AudioDevice audioDevice, MIXERLINE mxl)
        {
            _audioDevice = audioDevice;

            if (AudioDevice.RecordingSupport)
            {
                Direction = MixerType.Recording;
            }
            else if (AudioDevice.PlaybackSupport)
            {
                Direction = MixerType.Playback;
            }

            Channels      = mxl.cChannels;
            CControls     = mxl.cControls;
            Connections   = mxl.cConnections;
            Flag          = mxl.fdwLine;
            Destination   = mxl.dwDestination;
            Name          = mxl.szName;
            Id            = mxl.dwLineID;
            ComponentType = mxl.dwComponentType;
            Source        = mxl.dwSource;

            ReloadAudioLineControls();
            ReloadValues();
        }
Ejemplo n.º 2
0
        uint mixerGetLineInfo(IntPtr hmxobj,
                              ref MIXERLINE pmxl, MIXER_OBJECTF objF, MIXER_GETLINEINFOF lineF)
        {
            uint flag = (uint)objF | (uint)lineF;

            return(mixerGetLineInfo(hmxobj, ref pmxl, flag));
        }
Ejemplo n.º 3
0
        [DllImport("winmm.dll", CharSet = CharSet.Ansi)]                                                    // mixerGetLineInfoA

        private static extern int mixerGetLineInfoA(

            int hmxobj,

            ref MIXERLINE pmxl,

            int fdwInfo);
Ejemplo n.º 4
0
        internal static DestinationLine GetLine(Mixer mixer, int index)
        {
            MIXERLINE m = new MIXERLINE();

            m.cbStruct      = Marshal.SizeOf(m);
            m.dwDestination = index;
            mixerGetLineInfoA(mixer.Handle, ref m, MIXER_GETLINEINFOF_DESTINATION);
            return(new DestinationLine(mixer, m));
        }
Ejemplo n.º 5
0
        internal static SourceLine GetLine(Mixer mixer, int destIndex, int srcIndex)
        {
            MIXERLINE m = new MIXERLINE();

            m.cbStruct      = Marshal.SizeOf(m);
            m.dwDestination = destIndex;
            m.dwSource      = srcIndex;
            mixerGetLineInfoA(mixer.Handle, ref m, MIXER_GETLINEINFOF_SOURCE);
            return(new SourceLine(mixer, m));
        }
Ejemplo n.º 6
0
        private void ReloadLines()
        {
            MMErrors errorCode = 0;

            _audioLines.Clear();

            MIXERLINE mxl = new MIXERLINE();
            uint      dwDestination;

            unchecked
            {
                dwDestination = (uint)-1;
            }

            mxl.cbStruct        = (uint)Marshal.SizeOf(mxl);
            mxl.dwComponentType = _componentType;

            errorCode = (MMErrors)MixerNative.mixerGetLineInfo(_hMixer, ref mxl, MIXER_GETLINEINFOF.COMPONENTTYPE);
            if (errorCode != MMErrors.MMSYSERR_NOERROR)
            {
                throw new MixerException(errorCode, WMME.Audio.GetErrorDescription(FuncName.fnMixerGetLineInfo, errorCode));
            }

            dwDestination = mxl.dwDestination;

            var mixLine = new AudioLine(this, mxl);

            if (mixLine.CControls != 0 && !(mixLine.CControls == 1 && mixLine.Controls[0].ControlType == MIXERCONTROL_CONTROLTYPE.MUX))
            {
                _audioLines.Add(mixLine);
            }

            int cConnections = (int)mxl.cConnections;

            for (int i = 0; i < cConnections; i++)
            {
                mxl.cbStruct      = (uint)Marshal.SizeOf(mxl);
                mxl.dwDestination = dwDestination;
                mxl.dwSource      = (uint)i;

                errorCode = (MMErrors)MixerNative.mixerGetLineInfo(Handle, ref mxl, MIXER_GETLINEINFOF.SOURCE);
                if (errorCode != MMErrors.MMSYSERR_NOERROR)
                {
                    throw new MixerException(errorCode, WMME.Audio.GetErrorDescription(FuncName.fnMixerGetLineInfo, errorCode));
                }

                var mixLineNew = new AudioLine(this, mxl);

                if (mixLineNew.CControls != 0)
                {
                    _audioLines.Add(mixLineNew);
                }
            }
        }
Ejemplo n.º 7
0
        private MMSYSERR GetVolumeInfo(IntPtr hmixer, int ctrlType, ref MIXERCONTROL mxc)
        {
            MMSYSERR err = MMSYSERR.NOERROR;

            try
            {
                IntPtr            hmem = IntPtr.Zero;
                MIXERLINECONTROLS mxlc = new MIXERLINECONTROLS();
                mxlc.cbStruct = (uint)Marshal.SizeOf(mxlc);
                MIXERLINE mxl = new MIXERLINE();
                mxl.cbStruct        = (uint)Marshal.SizeOf(mxl);
                mxl.dwComponentType = (uint)MIXERLINE_COMPONENTTYPE.DST_SPEAKERS;
                err = mixerGetLineInfo(hmixer, ref mxl, MIXER_GETLINEINFOF.COMPONENTTYPE);

                if (err == MMSYSERR.NOERROR)
                {
                    mxlc.dwLineID    = (uint)mxl.dwLineID;
                    mxlc.dwControlID = (uint)ctrlType;
                    mxlc.cControls   = 1;
                    mxlc.cbmxctrl    = (uint)Marshal.SizeOf(mxc);
                    hmem             = malloc(Marshal.SizeOf(mxlc));
                    mxlc.pamxctrl    = hmem;
                    mxc.cbStruct     = (uint)Marshal.SizeOf(mxc);
                    err = mixerGetLineControls(hmixer, ref mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);

                    if (err == MMSYSERR.NOERROR)
                    {
                        mxc = (MIXERCONTROL)Marshal.PtrToStructure(mxlc.pamxctrl, typeof(MIXERCONTROL));
                        if (hmem != IntPtr.Zero)
                        {
                            free(hmem, Marshal.SizeOf(mxc));
                        }
                        return(err);
                    }
                    if (hmem != IntPtr.Zero)
                    {
                        free(hmem, Marshal.SizeOf(mxc));
                    }
                }
                return(err);
            }
            catch { return(err); }
        }
Ejemplo n.º 8
0
        public static MixerInfo GetMixerControls()
        {
            MIXERLINE         mxl = new MIXERLINE();
            MIXERLINECONTROLS mlc = new MIXERLINECONTROLS();

            mxl.cbStruct = (uint)Marshal.SizeOf(typeof(MIXERLINE));
            mlc.cbStruct = (uint)Marshal.SizeOf(typeof(MIXERLINECONTROLS));

            mixerGetLineInfo(IntPtr.Zero, ref mxl, MIXER.OBJECTF_MIXER | MIXER.GETLINEINFOF_DESTINATION);

            mlc.dwLineID  = mxl.dwLineID;
            mlc.cControls = mxl.cControls;
            mlc.cbmxctrl  = (uint)Marshal.SizeOf(typeof(MIXERCONTROL));
            mlc.pamxctrl  = Marshal.AllocHGlobal((int)(mlc.cbmxctrl * mlc.cControls));

            mixerGetLineControls(IntPtr.Zero, ref mlc, MIXER.OBJECTF_MIXER | MIXER.GETLINECONTROLSF_ALL);

            MixerInfo rtn = new MixerInfo();

            for (int i = 0; i < mlc.cControls; i++)
            {
                MIXERCONTROL mxc = (MIXERCONTROL)Marshal.PtrToStructure((IntPtr)((int)mlc.pamxctrl + (int)mlc.cbmxctrl * i), typeof(MIXERCONTROL));
                switch (mxc.dwControlType)
                {
                case MIXERCONTROL_CONTROLTYPE.VOLUME:
                    rtn.volumeCtl = mxc.dwControlID;
                    rtn.minVolume = mxc.Bounds.lMinimum;
                    rtn.maxVolume = mxc.Bounds.lMaximum;
                    break;

                case MIXERCONTROL_CONTROLTYPE.MUTE:
                    rtn.muteCtl = mxc.dwControlID;
                    break;
                }
            }

            Marshal.FreeHGlobal(mlc.pamxctrl);

            return(rtn);
        }
Ejemplo n.º 9
0
 private DestinationLine(Mixer mixer, MIXERLINE line) : base(mixer, line)
 {
 }
Ejemplo n.º 10
0
 static extern uint mixerGetLineInfo(IntPtr hmxobj, ref MIXERLINE pmxl, MIXER flags);
Ejemplo n.º 11
0
 uint mixerGetLineInfo(IntPtr hmxobj,
    ref MIXERLINE pmxl,MIXER_OBJECTF objF , MIXER_GETLINEINFOF lineF )
 {
     uint flag = (uint)objF | (uint)lineF;
     return mixerGetLineInfo(hmxobj, ref pmxl, flag);
 }
Ejemplo n.º 12
0
 internal MixerLine(Mixer mixer, MIXERLINE line)
 {
     this.mixer = mixer;
     this.line = line;
 }
Ejemplo n.º 13
0
 private SourceLine(Mixer m, MIXERLINE l)
     : base(m, l)
 {
 }
Ejemplo n.º 14
0
 public static extern int mixerGetLineInfoA(int hmxobj, ref MIXERLINE pmxl, uint fdwInfo);
Ejemplo n.º 15
0
 private DestinationLine(Mixer mixer, MIXERLINE line)
     : base(mixer, line)
 {
 }
Ejemplo n.º 16
0
		public static extern int mixerGetLineInfo(int hmxobj, ref MIXERLINE pmxl , int fdwInfo);
Ejemplo n.º 17
0
		private static bool GetControlByID(int mixer, int dst_id, int src_id, uint ctrl_type, out MIXERCONTROL outCtrl)
		{
			outCtrl = new MIXERCONTROL();
			MIXERLINE dst_line = new MIXERLINE();

			dst_line.cbStruct = Marshal.SizeOf(dst_line);
			dst_line.dwDestination = dst_id;
			int retval = mixerGetLineInfo(mixer, ref dst_line, MIXER_GETLINEINFOF_DESTINATION);
			if(retval != MMSYSERR_NOERROR)
				return false;

			if(src_id < 0)
			{
				MIXERLINECONTROLS dst_lc = new MIXERLINECONTROLS();
				int mcSize = 152;
				dst_lc.pamxctrl = Marshal.AllocCoTaskMem(mcSize);
				dst_lc.cbStruct = Marshal.SizeOf(dst_lc);
				dst_lc.dwLineID = dst_line.dwLineID;
				dst_lc.dwControl = ctrl_type;
				dst_lc.cControls = 1;
				dst_lc.cbmxctrl = mcSize;

				// Get the control 
				retval = mixerGetLineControls(mixer, ref dst_lc, MIXER_GETLINECONTROLSF_ONEBYTYPE); 
				if(retval != MMSYSERR_NOERROR) 
				{
					Marshal.FreeCoTaskMem(dst_lc.pamxctrl);
					return false;
				}
 
				MIXERCONTROL ctrl = new MIXERCONTROL();
				ctrl.cbStruct = mcSize; 
				// Copy the control into the destination structure 
				ctrl = (MIXERCONTROL)Marshal.PtrToStructure(dst_lc.pamxctrl, typeof(MIXERCONTROL)); 
				outCtrl = ctrl;
				Marshal.FreeCoTaskMem(dst_lc.pamxctrl);
				return true;
			}
			else
			{
				MIXERLINE src_line = new MIXERLINE();
				src_line.cbStruct = dst_line.cbStruct;
				src_line.dwDestination = dst_line.dwDestination;
				src_line.dwSource = src_id;
				retval = mixerGetLineInfo(mixer, ref src_line, MIXER_GETLINEINFOF_SOURCE);
				if(retval != MMSYSERR_NOERROR)
					return false;

				MIXERLINECONTROLS src_lc = new MIXERLINECONTROLS();
				int mcSize = 152;
				src_lc.pamxctrl = Marshal.AllocCoTaskMem(mcSize);
				src_lc.cbStruct = Marshal.SizeOf(src_lc); 
				src_lc.dwLineID = src_line.dwLineID; 
				src_lc.dwControl = ctrl_type; 
				src_lc.cControls = 1; 
				src_lc.cbmxctrl = mcSize;

				// Get the control 
				retval = mixerGetLineControls(mixer, ref src_lc, MIXER_GETLINECONTROLSF_ONEBYTYPE); 
				if(retval != MMSYSERR_NOERROR)
				{
					Marshal.FreeCoTaskMem(src_lc.pamxctrl);
					return false;
				}

				MIXERCONTROL ctrl = new MIXERCONTROL();
				ctrl.cbStruct = mcSize; 
				// Copy the control into the destination structure 
				ctrl = (MIXERCONTROL)Marshal.PtrToStructure(src_lc.pamxctrl, typeof(MIXERCONTROL)); 
				outCtrl = ctrl;
				Marshal.FreeCoTaskMem(src_lc.pamxctrl);
				return true;
			}
		}
Ejemplo n.º 18
0
        public static void Mute(bool mute)
        {
            // Check if this is vista or XP
            if (System.Environment.OSVersion.Version.Major >= 6)
            {
                EndpointVolume epVol = new EndpointVolume();
                epVol.Mute = mute;
                epVol.Dispose();
            }
            else
            {
                int mixerID = 0;

                if (mixerOpen(out mixerID, 0, 0, 0, 0) == MMSYSERR_NOERROR)
                {
                    MIXERLINE line = new MIXERLINE();
                    line.cbStruct        = Marshal.SizeOf(line);
                    line.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;

                    if (mixerGetLineInfoA(mixerID, ref line, MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR)
                    {
                        int          sizeofMIXERCONTROL = 152;
                        MIXERCONTROL mixerControl       = new MIXERCONTROL();

                        MIXERLINECONTROLS lineControl = new MIXERLINECONTROLS();

                        lineControl.pamxctrl  = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
                        lineControl.cbStruct  = Marshal.SizeOf(lineControl);
                        lineControl.dwLineID  = line.dwLineID;
                        lineControl.dwControl = MIXERCONTROL_CONTROLTYPE_MUTE;
                        lineControl.cControls = 1;
                        lineControl.cbmxctrl  = sizeofMIXERCONTROL;

                        mixerControl.cbStruct = sizeofMIXERCONTROL;

                        if (mixerGetLineControlsA(mixerID, ref lineControl, MIXER_GETLINECONTROLSF_ONEBYTYPE) == MMSYSERR_NOERROR)
                        {
                            mixerControl = (MIXERCONTROL)Marshal.PtrToStructure(lineControl.pamxctrl, typeof(MIXERCONTROL));

                            MIXERCONTROLDETAILS         controlDetails = new MIXERCONTROLDETAILS();
                            MIXERCONTROLDETAILS_BOOLEAN muteValue      = new MIXERCONTROLDETAILS_BOOLEAN();

                            controlDetails.item        = 0;
                            controlDetails.dwControlID = mixerControl.dwControlID;
                            controlDetails.cbStruct    = Marshal.SizeOf(controlDetails);
                            controlDetails.cbDetails   = Marshal.SizeOf(muteValue);
                            controlDetails.cChannels   = 1;

                            muteValue.dwValue = Convert.ToInt32(mute);

                            controlDetails.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(muteValue));

                            Marshal.StructureToPtr(muteValue, controlDetails.paDetails, false);

                            int rc = mixerSetControlDetails(mixerID, ref controlDetails, MIXER_SETCONTROLDETAILSF_VALUE);

                            Marshal.FreeCoTaskMem(controlDetails.paDetails);
                            Marshal.FreeCoTaskMem(lineControl.pamxctrl);
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
0
		public static bool InitSoundCard2(int mixerID)
		{
			int mixer;
			int retval = -1;
			retval = mixerOpen(out mixer, mixerID, 0, 0, 0);
			if(retval != MMSYSERR_NOERROR)
				return false;

			MIXERCAPS mc = new MIXERCAPS();
			retval = mixerGetDevCaps(mixer, ref mc, Marshal.SizeOf(mc));
			if(retval != MMSYSERR_NOERROR)
				goto failed;

			MIXERLINE dst_line = new MIXERLINE();
			dst_line.cbStruct = Marshal.SizeOf(dst_line);
			dst_line.dwDestination = 0;
			retval = mixerGetLineInfo(mixer, ref dst_line, MIXER_GETLINEINFOF_DESTINATION);
			if(retval != MMSYSERR_NOERROR)
				goto failed;

			for(int i=0; i<dst_line.cConnections; i++)
			{
				MIXERCONTROL ctrl = new MIXERCONTROL();
				GetControlByID(mixerID, 0, i, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
				SetBool(mixerID, ctrl, true);
			}

			mixerClose(mixer);

			SetMainVolume(mixerID, 100);
			SetWaveOutVolume(mixerID, 100);
			SetMainMute(mixerID, false);
			SetWaveOutMute(mixerID, false);

			return true;
			
		failed:
			mixerClose(mixer);
			return false;
		}
Ejemplo n.º 20
0
 private static extern MMSYSERR mixerGetLineInfo(IntPtr hmxobj, ref MIXERLINE pmxl, MIXER_GETLINEINFOF fdwInfo);
Ejemplo n.º 21
0
 public static extern int MixerGetLineInfo(IntPtr hmxobj, ref MIXERLINE pmxl, uint fdwInfo);
Ejemplo n.º 22
0
        public MixerAPI()
        {
            _hMixer = new IntPtr();
            uint mmresult = mixerOpen(ref _hMixer, 0, IntPtr.Zero, IntPtr.Zero, MIXER_OBJECTF.MIXER);
            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                throw new MixerException("mixerOpen:",mmresult);
            }

            MIXERLINE lineInfo = new MIXERLINE();
            lineInfo.StructSize = (uint)Marshal.SizeOf(new MIXERLINE());
            lineInfo.ComponentType =(uint)MIXERLINE_COMPONENTTYPE.SRC_WAVEOUT;
            //volInfo.ComponentType =(uint)MIXERLINE_COMPONENTTYPE.DST_SPEAKERS;
            mmresult = mixerGetLineInfo(_hMixer, ref lineInfo, MIXER_OBJECTF.HMIXER 
                ,MIXER_GETLINEINFOF.COMPONENTTYPE);

            IntPtr ctlPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROL()));

            MIXERLINECONTROLS ctlParam = new MIXERLINECONTROLS();
            ctlParam.StructSize = (uint)Marshal.SizeOf(new MIXERLINECONTROLS());
            ctlParam.LineID = lineInfo.dwLineID;
            ctlParam.ControlType = MIXERCONTROL_CONTROLTYPE.MUTE;
            ctlParam.Controls = 1;
            ctlParam.MixerControlItemSize=  (uint)Marshal.SizeOf(new MIXERCONTROL());
            ctlParam.MixerControlArray = ctlPtr;

            mmresult = mixerGetLineControls(_hMixer, ref ctlParam,MIXER_OBJECTF.HMIXER
                ,MIXER_GETLINECONTROLSF.ONEBYTYPE);
            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                Marshal.FreeCoTaskMem(ctlPtr);
                throw new MixerException("mixerGetLineControls", mmresult);
            }

            MIXERCONTROL muteCtrl = (MIXERCONTROL)Marshal.PtrToStructure(ctlPtr, typeof(MIXERCONTROL));

            _muteID = muteCtrl.ControlID;

            ctlParam.ControlType = MIXERCONTROL_CONTROLTYPE.VOLUME;
            //他の値は再利用。まだMarshal.FreeCoTaskMemを呼んではいけない

            mmresult = mixerGetLineControls(_hMixer, ref ctlParam,MIXER_OBJECTF.HMIXER
                ,MIXER_GETLINECONTROLSF.ONEBYTYPE);
            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                Marshal.FreeCoTaskMem(ctlPtr);
                throw new MixerException("mixerGetLineControls" , mmresult);
            }

            MIXERCONTROL volCtrl = (MIXERCONTROL)Marshal.PtrToStructure(ctlPtr, typeof(MIXERCONTROL));
            Marshal.FreeCoTaskMem(ctlPtr);

            _volumeID = volCtrl.ControlID;
            _volMax = volCtrl.Bounds.UnsignedMaximum;
            _volMin = volCtrl.Bounds.UnsignedMinimum;

            Debug.WriteLine(string.Format("MixerAPI constructor muteID:{0} volID:{1} volMan:{2} volMin:{3}",
                _muteID, _volumeID, _volMax, _volMin));


        }
Ejemplo n.º 23
0
 private SourceLine(Mixer m, MIXERLINE l) : base(m, l)
 {
 }
Ejemplo n.º 24
0
		private static bool GetControlByType(int mixer, uint dst_type, uint src_type, uint ctrl_type, out MIXERCONTROL outCtrl)
		{
			outCtrl = new MIXERCONTROL();
			MIXERCAPS mc = new MIXERCAPS();
			int retval = mixerGetDevCaps(mixer, ref mc, Marshal.SizeOf(mc));
			if(retval != MMSYSERR_NOERROR)
				return false;

			int num_dest = mc.cDestinations;
			for(int j=0; j<num_dest; j++)	// for each destination line
			{
				MIXERLINE dst_line = new MIXERLINE();
				dst_line.cbStruct = Marshal.SizeOf(dst_line);
				dst_line.dwDestination = j;
				retval = mixerGetLineInfo(mixer, ref dst_line, MIXER_GETLINEINFOF_DESTINATION);
				if(retval == MMSYSERR_NOERROR && dst_line.dwComponentType == dst_type)
				{
					if(src_type == 0)
					{
						MIXERLINECONTROLS dst_lc = new MIXERLINECONTROLS();
						int mcSize = 152;
						dst_lc.pamxctrl = Marshal.AllocCoTaskMem(mcSize);
						dst_lc.cbStruct = Marshal.SizeOf(dst_lc); 
						dst_lc.dwLineID = dst_line.dwLineID; 
						dst_lc.dwControl = ctrl_type; 
						dst_lc.cControls = 1; 
						dst_lc.cbmxctrl = mcSize;

						// Get the control 
						retval = mixerGetLineControls(mixer, ref dst_lc, MIXER_GETLINECONTROLSF_ONEBYTYPE); 
						if(retval == MMSYSERR_NOERROR) 
						{ 
							MIXERCONTROL ctrl = new MIXERCONTROL();
							ctrl.cbStruct = mcSize; 
							// Copy the control into the destination structure 
							ctrl = (MIXERCONTROL)Marshal.PtrToStructure(dst_lc.pamxctrl, typeof(MIXERCONTROL)); 
							outCtrl = ctrl;
							Marshal.FreeCoTaskMem(dst_lc.pamxctrl);
							return true;
						}
						Marshal.FreeCoTaskMem(dst_lc.pamxctrl);
						return false;
					}
					else
					{
						int num_src = dst_line.cConnections;
						for(int k=0; k<num_src; k++)	// for all source lines connected to this destination
						{
							MIXERLINE src_line = new MIXERLINE();
							src_line.cbStruct = dst_line.cbStruct;
							src_line.dwDestination = dst_line.dwDestination;
							src_line.dwSource = k;
							retval = mixerGetLineInfo(mixer, ref src_line, MIXER_GETLINEINFOF_SOURCE);
							if(retval == MMSYSERR_NOERROR && src_line.dwComponentType == src_type)
							{
								MIXERLINECONTROLS src_lc = new MIXERLINECONTROLS();
								int mcSize = 152;
								src_lc.pamxctrl = Marshal.AllocCoTaskMem(mcSize);
								src_lc.cbStruct = Marshal.SizeOf(src_lc); 
								src_lc.dwLineID = src_line.dwLineID; 
								src_lc.dwControl = ctrl_type; 
								src_lc.cControls = 1; 
								src_lc.cbmxctrl = mcSize;

								// Get the control 
								retval = mixerGetLineControls(mixer, ref src_lc, MIXER_GETLINECONTROLSF_ONEBYTYPE); 
								if(retval == MMSYSERR_NOERROR) 
								{ 
									MIXERCONTROL ctrl = new MIXERCONTROL();
									ctrl.cbStruct = mcSize; 
									// Copy the control into the destination structure 
									ctrl = (MIXERCONTROL)Marshal.PtrToStructure(src_lc.pamxctrl, typeof(MIXERCONTROL)); 
									outCtrl = ctrl;
									Marshal.FreeCoTaskMem(src_lc.pamxctrl);
									return true;
								}
								Marshal.FreeCoTaskMem(src_lc.pamxctrl);
								return false;
							}
						}
					}
				}
			}
			return false;
		}
Ejemplo n.º 25
0
        public static void Mute(bool mute)
        {
            // Check if this is vista or XP
            if (System.Environment.OSVersion.Version.Major >= 6)
            {
                EndpointVolume epVol = new EndpointVolume();
                epVol.Mute = mute;
                epVol.Dispose();
            }
            else
            {
                int mixerID = 0;

                if (mixerOpen(out mixerID, 0, 0, 0, 0) == MMSYSERR_NOERROR)
                {
                    MIXERLINE line = new MIXERLINE();
                    line.cbStruct = Marshal.SizeOf(line);
                    line.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;

                    if (mixerGetLineInfoA(mixerID, ref line, MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR)
                    {
                        int sizeofMIXERCONTROL = 152;
                        MIXERCONTROL mixerControl = new MIXERCONTROL();

                        MIXERLINECONTROLS lineControl = new MIXERLINECONTROLS();

                        lineControl.pamxctrl = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
                        lineControl.cbStruct = Marshal.SizeOf(lineControl);
                        lineControl.dwLineID = line.dwLineID;
                        lineControl.dwControl = MIXERCONTROL_CONTROLTYPE_MUTE;
                        lineControl.cControls = 1;
                        lineControl.cbmxctrl = sizeofMIXERCONTROL;

                        mixerControl.cbStruct = sizeofMIXERCONTROL;

                        if (mixerGetLineControlsA(mixerID, ref lineControl, MIXER_GETLINECONTROLSF_ONEBYTYPE) == MMSYSERR_NOERROR)
                        {
                            mixerControl = (MIXERCONTROL)Marshal.PtrToStructure(lineControl.pamxctrl, typeof(MIXERCONTROL));

                            MIXERCONTROLDETAILS controlDetails = new MIXERCONTROLDETAILS();
                            MIXERCONTROLDETAILS_BOOLEAN muteValue = new MIXERCONTROLDETAILS_BOOLEAN();

                            controlDetails.item = 0;
                            controlDetails.dwControlID = mixerControl.dwControlID;
                            controlDetails.cbStruct = Marshal.SizeOf(controlDetails);
                            controlDetails.cbDetails = Marshal.SizeOf(muteValue);
                            controlDetails.cChannels = 1;

                            muteValue.dwValue = Convert.ToInt32(mute);

                            controlDetails.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(muteValue));

                            Marshal.StructureToPtr(muteValue, controlDetails.paDetails, false);

                            int rc = mixerSetControlDetails(mixerID, ref controlDetails, MIXER_SETCONTROLDETAILSF_VALUE);

                            Marshal.FreeCoTaskMem(controlDetails.paDetails);
                            Marshal.FreeCoTaskMem(lineControl.pamxctrl);
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
		public static string GetLineName(int mixer, uint dst_type, uint src_type)
		{
			MIXERCAPS mc = new MIXERCAPS();
			int retval = mixerGetDevCaps(mixer, ref mc, Marshal.SizeOf(mc));
			if(retval != MMSYSERR_NOERROR)
				return "";

			int num_dest = mc.cDestinations;
			for(int j=0; j<num_dest; j++)	// for each destination line
			{
				MIXERLINE dst_line = new MIXERLINE();
				dst_line.cbStruct = Marshal.SizeOf(dst_line);
				dst_line.dwDestination = j;
				retval = mixerGetLineInfo(mixer, ref dst_line, MIXER_GETLINEINFOF_DESTINATION);
				if(retval == MMSYSERR_NOERROR && dst_line.dwComponentType == dst_type)
				{
					if(src_type == 0)
						return dst_line.szName;
					else
					{
						int num_src = dst_line.cConnections;
						for(int k=0; k<num_src; k++)	// for all source lines connected to this destination
						{
							MIXERLINE src_line = new MIXERLINE();
							src_line.cbStruct = dst_line.cbStruct;
							src_line.dwDestination = dst_line.dwDestination;
							src_line.dwSource = k;
							retval = mixerGetLineInfo(mixer, ref src_line, MIXER_GETLINEINFOF_SOURCE);
							if(retval == MMSYSERR_NOERROR && src_line.dwComponentType == src_type)
								return src_line.szName;
						}
					}
				}
			}
			return "";
		}
Ejemplo n.º 27
0
 public static extern uint mixerGetLineInfo(int hmxobj, ref MIXERLINE pmxl, uint flags);
Ejemplo n.º 28
0
		public static void RestoreState()
		{
			int index = 0;
			uint[] ctrl_list =
			{
				MIXERCONTROL_CONTROLTYPE_CUSTOM,
				MIXERCONTROL_CONTROLTYPE_BOOLEANMETER,
				MIXERCONTROL_CONTROLTYPE_SIGNEDMETER,
				MIXERCONTROL_CONTROLTYPE_PEAKMETER,
				MIXERCONTROL_CONTROLTYPE_BOOLEAN,
				MIXERCONTROL_CONTROLTYPE_ONOFF,
				MIXERCONTROL_CONTROLTYPE_MUTE,
				MIXERCONTROL_CONTROLTYPE_MONO,
				MIXERCONTROL_CONTROLTYPE_LOUDNESS,
				MIXERCONTROL_CONTROLTYPE_STEREOENH,
				MIXERCONTROL_CONTROLTYPE_BUTTON,
				MIXERCONTROL_CONTROLTYPE_DECIBELS,
				MIXERCONTROL_CONTROLTYPE_SIGNED,
				MIXERCONTROL_CONTROLTYPE_SLIDER,
				MIXERCONTROL_CONTROLTYPE_PAN,
				MIXERCONTROL_CONTROLTYPE_QSOUNDPAN,
				MIXERCONTROL_CONTROLTYPE_SINGLESELECT,
				MIXERCONTROL_CONTROLTYPE_MUX,
				MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT,
				MIXERCONTROL_CONTROLTYPE_MIXER,
				MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER,
				MIXERCONTROL_CONTROLTYPE_UNSIGNED,
				MIXERCONTROL_CONTROLTYPE_BASS,
				MIXERCONTROL_CONTROLTYPE_EQUALIZER,
				MIXERCONTROL_CONTROLTYPE_FADER,
				MIXERCONTROL_CONTROLTYPE_TREBLE,
				MIXERCONTROL_CONTROLTYPE_VOLUME,
				MIXERCONTROL_CONTROLTYPE_MICROTIME,
				MIXERCONTROL_CONTROLTYPE_MILLITIME,
				MIXERCONTROL_CONTROLTYPE_PERCENT,
			};
            
			int num_mixers = mixerGetNumDevs();
			int mixer = -1;
			int retval = -1;

			for(int i=0; i<num_mixers; i++)	// for each mixer
			{
				mixerOpen(out mixer, i, 0, 0, 0);
				MIXERCAPS mc = new MIXERCAPS();

				retval = mixerGetDevCaps(mixer, ref mc, Marshal.SizeOf(mc));
				if(retval == MMSYSERR_NOERROR)
				{
					int num_dest = mc.cDestinations;
					for(int j=0; j<num_dest; j++)		// for each destination line in this mixer
					{
						MIXERLINE dst_line = new MIXERLINE();
						dst_line.cbStruct = Marshal.SizeOf(dst_line);
						dst_line.dwDestination = j;

						retval = mixerGetLineInfo(mixer, ref dst_line, MIXER_GETLINEINFOF_DESTINATION);
						if(retval == MMSYSERR_NOERROR)
						{
							for(int k=0; k<30; k++)		// for each control in this destination line
							{
								MIXERLINECONTROLS dst_lc = new MIXERLINECONTROLS();
								int mcSize = 152;
								dst_lc.pamxctrl = Marshal.AllocCoTaskMem(mcSize);
								dst_lc.cbStruct = Marshal.SizeOf(dst_lc); 
								dst_lc.dwLineID = dst_line.dwLineID; 
								dst_lc.dwControl = ctrl_list[k]; 
								dst_lc.cControls = 1; 
								dst_lc.cbmxctrl = mcSize;

								// Get the control 
								retval = mixerGetLineControls(mixer, ref dst_lc, MIXER_GETLINECONTROLSF_ONEBYTYPE); 
								if(retval == MMSYSERR_NOERROR) 
								{ 
									MIXERCONTROL ctrl = new MIXERCONTROL();
									ctrl.cbStruct = mcSize; 
									// Copy the control into the destination structure 
									ctrl = (MIXERCONTROL)Marshal.PtrToStructure(dst_lc.pamxctrl, typeof(MIXERCONTROL)); 
									MIXERCONTROLDETAILS details = new MIXERCONTROLDETAILS();
									int size = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_SIGNED));
									details.dwControlID = ctrl.dwControlID; 
									details.cbDetails = size; 
									details.item = ctrl.cMultipleItems;
									if(details.item > 0) size *= details.item;
									details.paDetails = Marshal.AllocCoTaskMem(size); 
									details.cbStruct = Marshal.SizeOf(details); 
									details.cChannels = 1; 
									
									if(details.item > 0)
									{
										if(index != save.Count)
										{
											int rec_index = (int)save[index];
											int[] val = new int[details.item];
											for(int m=0; m<details.item; m++)
											{
												if(m == rec_index) val[m] = 1;
												else val[m] = 0;
											}
											Marshal.Copy(val, 0, details.paDetails, details.item);

											retval = mixerSetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE); 
											if(retval == MMSYSERR_NOERROR)
												index++;
										}
									}
									else
									{
										MIXERCONTROLDETAILS_UNSIGNED val = new MIXERCONTROLDETAILS_UNSIGNED();
										val.dwValue = (int)save[index];
										Marshal.StructureToPtr(val, details.paDetails, false);

										retval = mixerSetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE); 
										if(retval == MMSYSERR_NOERROR)
											index++;
									}
									Marshal.FreeCoTaskMem(details.paDetails);
								}
								Marshal.FreeCoTaskMem(dst_lc.pamxctrl);
							}

							int num_src = dst_line.cConnections;
							for(int k=0; k<num_src; k++)	// for each source line connected to this destination
							{
								MIXERLINE src_line = new MIXERLINE();
								src_line.cbStruct = dst_line.cbStruct;
								src_line.dwDestination = dst_line.dwDestination;
								src_line.dwSource = k;

								retval = mixerGetLineInfo(mixer, ref src_line, MIXER_GETLINEINFOF_SOURCE);
								if(retval == MMSYSERR_NOERROR)
								{
									for(int l=0; l<30; l++)	// for each control in this source line
									{
										MIXERLINECONTROLS src_lc = new MIXERLINECONTROLS();
										int mcSize = 152;
										src_lc.pamxctrl = Marshal.AllocCoTaskMem(mcSize);
										src_lc.cbStruct = Marshal.SizeOf(src_lc); 
										src_lc.dwLineID = src_line.dwLineID; 
										src_lc.dwControl = ctrl_list[l]; 
										src_lc.cControls = 1; 
										src_lc.cbmxctrl = mcSize;

										// Get the control 
										retval = mixerGetLineControls(mixer, ref src_lc, MIXER_GETLINECONTROLSF_ONEBYTYPE); 
										if(retval == MMSYSERR_NOERROR) 
										{ 
											MIXERCONTROL ctrl = new MIXERCONTROL();
											ctrl.cbStruct = mcSize; 
											// Copy the control into the destination structure 
											ctrl = (MIXERCONTROL)Marshal.PtrToStructure(src_lc.pamxctrl, typeof(MIXERCONTROL)); 
											MIXERCONTROLDETAILS details = new MIXERCONTROLDETAILS();
											int size;
											if(l<20) size = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_SIGNED));
											else size = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED));
											details.dwControlID = ctrl.dwControlID; 
											details.paDetails = Marshal.AllocCoTaskMem(size); 
											details.cbStruct = Marshal.SizeOf(details); 
											details.cChannels = 1; 
											details.item = ctrl.cMultipleItems; 
											details.cbDetails = size; 
									
											if(details.item > 0)
											{
												int rec_index = (int)save[index];
												MIXERCONTROLDETAILS_UNSIGNED[] val = new MIXERCONTROLDETAILS_UNSIGNED[details.item];
												for(int m=0; m<details.item; m++)
													val[m] = new MIXERCONTROLDETAILS_UNSIGNED();
												val[rec_index].dwValue = 1;
												Marshal.StructureToPtr(val[0], details.paDetails, false);
											}
											else
											{
												MIXERCONTROLDETAILS_UNSIGNED val = new MIXERCONTROLDETAILS_UNSIGNED();
												val.dwValue = (int)save[index];
												Marshal.StructureToPtr(val, details.paDetails, false);
											}

											retval = mixerSetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE); 
											if(retval == MMSYSERR_NOERROR)
												index++;

											Marshal.FreeCoTaskMem(details.paDetails);
										}
										Marshal.FreeCoTaskMem(src_lc.pamxctrl);
									}
								}
							}							
						}
					}
				}
			}
			mixerClose(mixer);
		}
Ejemplo n.º 29
0
 internal static DestinationLine GetLine(Mixer mixer, int index)
 {
     MIXERLINE m = new MIXERLINE();
     m.cbStruct = Marshal.SizeOf(m);
     m.dwDestination = index;
     mixerGetLineInfoA(mixer.Handle, ref m, MIXER_GETLINEINFOF_DESTINATION);
     return new DestinationLine(mixer, m);
 }
Ejemplo n.º 30
0
        // This function attempts to obtain a specified mixer control/component pair -
        // returns true if successful.
        private static bool GetMixerControl(                                                                        // GetMixerControl
            int hmixer,
            int component,
            int control,
            out MIXERCONTROL mxc,
            out int vCurrentVol)
        {
            bool retValue = false;

            mxc = new MIXERCONTROL();

            MIXERLINECONTROLS            mxlc  = new MIXERLINECONTROLS();
            MIXERLINE                    mxl   = new MIXERLINE();
            MIXERCONTROLDETAILS          pmxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED du    = new MIXERCONTROLDETAILS_UNSIGNED();

            vCurrentVol = -1;                   // A dummy value

            mxl.cbStruct        = Marshal.SizeOf(mxl);
            mxl.dwComponentType = component;

            int rc = mixerGetLineInfoA(
                hmixer,
                ref mxl,
                MIXER_GETLINEINFOF_COMPONENTTYPE);

            if (MMSYSERR_NOERROR == rc)
            {
                int sizeofMIXERCONTROL = 152;
                int ctrl = Marshal.SizeOf(typeof(MIXERCONTROL));
                mxlc.pamxctrl  = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
                mxlc.cbStruct  = Marshal.SizeOf(mxlc);
                mxlc.dwLineID  = mxl.dwLineID;
                mxlc.dwControl = control;
                mxlc.cControls = 1;
                mxlc.cbmxctrl  = sizeofMIXERCONTROL;

                // Allocate a buffer for the control
                mxc.cbStruct = sizeofMIXERCONTROL;

                // Get the control
                rc = mixerGetLineControlsA(
                    hmixer,
                    ref mxlc,
                    MIXER_GETLINECONTROLSF_ONEBYTYPE);

                if (MMSYSERR_NOERROR == rc)
                {
                    retValue = true;
                    // Copy the control into the destination structure
                    mxc = (MIXERCONTROL)Marshal.PtrToStructure(
                        mxlc.pamxctrl,
                        typeof(MIXERCONTROL));
                }

                int sizeofMIXERCONTROLDETAILS =
                    Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));

                int sizeofMIXERCONTROLDETAILS_UNSIGNED =
                    Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED));

                pmxcd.cbStruct    = sizeofMIXERCONTROLDETAILS;
                pmxcd.dwControlID = mxc.dwControlID;
                pmxcd.paDetails   = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED);
                pmxcd.cChannels   = 1;
                pmxcd.item        = 0;
                pmxcd.cbDetails   = sizeofMIXERCONTROLDETAILS_UNSIGNED;

                rc = mixerGetControlDetailsA(
                    hmixer,
                    ref pmxcd,
                    MIXER_GETCONTROLDETAILSF_VALUE);

                du = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(
                    pmxcd.paDetails,
                    typeof(MIXERCONTROLDETAILS_UNSIGNED));

                vCurrentVol = du.dwValue;

                return(retValue);                   // true
            }

            return(retValue);                   // false
        }
Ejemplo n.º 31
0
 internal static extern int mixerGetLineInfoA(IntPtr hmxobj, ref 
     MIXERLINE pmxl, int fdwInfo);
Ejemplo n.º 32
0
    private static bool GetVolumeControl(int hmixer, int componentType, int ctrlType, out MIXERCONTROL mxc,
                                         out int vCurrentVol)
    {
      // This function attempts to obtain a mixer control. 
      // Returns True if successful. 
      MIXERLINECONTROLS mxlc = new MIXERLINECONTROLS();
      MIXERLINE mxl = new MIXERLINE();
      MIXERCONTROLDETAILS pmxcd = new MIXERCONTROLDETAILS();
      MIXERCONTROLDETAILS_UNSIGNED du = new MIXERCONTROLDETAILS_UNSIGNED();
      mxc = new MIXERCONTROL();
      int rc;
      bool retValue;
      vCurrentVol = -1;

      mxl.cbStruct = Marshal.SizeOf(mxl);
      mxl.dwComponentType = componentType;

      rc = mixerGetLineInfoA(hmixer, ref mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);

      if (MMSYSERR_NOERROR == rc)
      {
        int sizeofMIXERCONTROL = 152;
        int ctrl = Marshal.SizeOf(typeof (MIXERCONTROL));
        mxlc.pamxctrl = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
        mxlc.cbStruct = Marshal.SizeOf(mxlc);
        mxlc.dwLineID = mxl.dwLineID;
        mxlc.dwControl = ctrlType;
        mxlc.cControls = 1;
        mxlc.cbmxctrl = sizeofMIXERCONTROL;

        // Allocate a buffer for the control 
        mxc.cbStruct = sizeofMIXERCONTROL;

        // Get the control 
        rc = mixerGetLineControlsA(hmixer, ref mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);

        if (MMSYSERR_NOERROR == rc)
        {
          retValue = true;

          // Copy the control into the destination structure 
          mxc = (MIXERCONTROL)Marshal.PtrToStructure(mxlc.pamxctrl, typeof (MIXERCONTROL));
        }
        else
        {
          retValue = false;
        }
        int sizeofMIXERCONTROLDETAILS = Marshal.SizeOf(typeof (MIXERCONTROLDETAILS));
        int sizeofMIXERCONTROLDETAILS_UNSIGNED = Marshal.SizeOf(typeof (MIXERCONTROLDETAILS_UNSIGNED));
        pmxcd.cbStruct = sizeofMIXERCONTROLDETAILS;
        pmxcd.dwControlID = mxc.dwControlID;
        pmxcd.paDetails =
          Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED);
        pmxcd.cChannels = 1;
        pmxcd.item = 0;
        pmxcd.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED;

        rc = mixerGetControlDetailsA(hmixer, ref pmxcd, MIXER_GETCONTROLDETAILSF_VALUE);

        du =
          (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(pmxcd.paDetails, typeof (MIXERCONTROLDETAILS_UNSIGNED));

        vCurrentVol = du.dwValue;

        return retValue;
      }

      retValue = false;
      return retValue;
    }
Ejemplo n.º 33
0
 internal static SourceLine GetLine(Mixer mixer, int destIndex, int srcIndex)
 {
     MIXERLINE m = new MIXERLINE();
     m.cbStruct = Marshal.SizeOf(m);
     m.dwDestination = destIndex;
     m.dwSource = srcIndex;
     mixerGetLineInfoA(mixer.Handle, ref m, MIXER_GETLINEINFOF_SOURCE);
     return new SourceLine(mixer, m);
 }
Ejemplo n.º 34
0
 internal MixerLine(Mixer mixer, MIXERLINE line)
 {
     this.mixer = mixer;
     this.line  = line;
 }
Ejemplo n.º 35
0
        public static MixerInfo GetMixerControls()
        {
            MIXERLINE mxl = new MIXERLINE();
            MIXERLINECONTROLS mlc = new MIXERLINECONTROLS();
            mxl.cbStruct = (uint)Marshal.SizeOf(typeof(MIXERLINE));
            mlc.cbStruct = (uint)Marshal.SizeOf(typeof(MIXERLINECONTROLS));

            mixerGetLineInfo(IntPtr.Zero, ref mxl, MIXER.OBJECTF_MIXER | MIXER.GETLINEINFOF_DESTINATION);

            mlc.dwLineID = mxl.dwLineID;
            mlc.cControls = mxl.cControls;
            mlc.cbmxctrl = (uint)Marshal.SizeOf(typeof(MIXERCONTROL));
            mlc.pamxctrl = Marshal.AllocHGlobal((int)(mlc.cbmxctrl * mlc.cControls));

            mixerGetLineControls(IntPtr.Zero, ref mlc, MIXER.OBJECTF_MIXER | MIXER.GETLINECONTROLSF_ALL);

            MixerInfo rtn = new MixerInfo();

            for (int i = 0; i < mlc.cControls; i++)
            {
                MIXERCONTROL mxc = (MIXERCONTROL)Marshal.PtrToStructure((IntPtr)((int)mlc.pamxctrl + (int)mlc.cbmxctrl * i), typeof(MIXERCONTROL));
                switch (mxc.dwControlType)
                {
                    case MIXERCONTROL_CONTROLTYPE.VOLUME:
                        rtn.volumeCtl = mxc.dwControlID;
                        rtn.minVolume = mxc.Bounds.lMinimum;
                        rtn.maxVolume = mxc.Bounds.lMaximum;
                        break;
                    case MIXERCONTROL_CONTROLTYPE.MUTE:
                        rtn.muteCtl = mxc.dwControlID;
                        break;
                }
            }

            Marshal.FreeHGlobal(mlc.pamxctrl);

            return rtn;
        }
Ejemplo n.º 36
0
 static extern uint mixerGetLineInfo(IntPtr hmxobj,
    ref MIXERLINE pmxl, uint fdwInfo);
Ejemplo n.º 37
0
        private void ReloadAudioDevices()
        {
            if (_reloadDevicesInProgress)
            {
                return;
            }

            MMErrors errorCode = 0;
            IntPtr   hMixer    = IntPtr.Zero;

            try
            {
                _reloadDevicesInProgress = true;

                var       newAudioDevices = new List <AudioDeviceDescriptor>();
                MIXERCAPS wic             = new MIXERCAPS();

                int iNumDevs = MixerNative.mixerGetNumDevs();

                for (int i = 0; i < iNumDevs; i++)
                {
                    // Get info about the next device
                    errorCode = (MMErrors)MixerNative.mixerGetDevCaps(i, ref wic, Marshal.SizeOf(wic));
                    if (errorCode != MMErrors.MMSYSERR_NOERROR)
                    {
                        throw new MixerException(errorCode, GetErrorDescription(FuncName.fnMixerGetDevCaps, errorCode));
                    }

                    errorCode = (MMErrors)MixerNative.mixerOpen(out hMixer, i, IntPtr.Zero, IntPtr.Zero, 0);
                    if (errorCode != MMErrors.MMSYSERR_NOERROR)
                    {
                        throw new MixerException(errorCode, GetErrorDescription(FuncName.fnMixerOpen, errorCode));
                    }

                    MIXERLINE mxl = new MIXERLINE();
                    mxl.cbStruct = (uint)Marshal.SizeOf(mxl);

                    var deviceDescriptor = new AudioDeviceDescriptor()
                    {
                        DeviceId = i,
                        Name     = wic.szPname
                    };

                    foreach (var mixerlineComponenttype in AudioDevice.RecordingLineTypes)
                    {
                        mxl.dwComponentType = mixerlineComponenttype;
                        if (MixerNative.mixerGetLineInfo(hMixer, ref mxl, MIXER_GETLINEINFOF.COMPONENTTYPE) == 0)
                        {
                            deviceDescriptor.RecordingSupport       = true;
                            deviceDescriptor.RecordingComponentType = mixerlineComponenttype;

                            break;
                        }
                    }

                    foreach (var mixerlineComponenttype in AudioDevice.PlaybackLineTypes)
                    {
                        mxl.dwComponentType = mixerlineComponenttype;
                        if (MixerNative.mixerGetLineInfo(hMixer, ref mxl, MIXER_GETLINEINFOF.COMPONENTTYPE) == 0)
                        {
                            deviceDescriptor.PlaybackSupport       = true;
                            deviceDescriptor.PlaybackComponentType = mixerlineComponenttype;

                            break;
                        }
                    }

                    if (deviceDescriptor.PlaybackSupport || deviceDescriptor.RecordingSupport)
                    {
                        if (deviceDescriptor.PlaybackSupport && deviceDescriptor.RecordingSupport)
                        {
                            var playbackDeviceDescriptor = new AudioDeviceDescriptor()
                            {
                                DeviceId              = deviceDescriptor.DeviceId,
                                Name                  = deviceDescriptor.Name,
                                PlaybackSupport       = true,
                                RecordingSupport      = false,
                                PlaybackComponentType = deviceDescriptor.PlaybackComponentType
                            };

                            var recordingDeviceDescriptor = new AudioDeviceDescriptor()
                            {
                                DeviceId               = deviceDescriptor.DeviceId,
                                Name                   = deviceDescriptor.Name,
                                PlaybackSupport        = false,
                                RecordingSupport       = true,
                                RecordingComponentType = deviceDescriptor.RecordingComponentType
                            };

                            newAudioDevices.Add(playbackDeviceDescriptor);
                            newAudioDevices.Add(recordingDeviceDescriptor);
                        }
                        else
                        {
                            newAudioDevices.Add(deviceDescriptor);
                        }
                    }
                }

                if (newAudioDevices.Count > 0 || (_audioDevices.Count > 0 && iNumDevs == 0))
                {
                    UpdateAudioDevicesLists(newAudioDevices);
                }
            }
            finally
            {
                if (hMixer != IntPtr.Zero)
                {
                    MixerNative.mixerClose(hMixer);
                }

                _reloadDevicesInProgress = false;
            }
        }
Ejemplo n.º 38
0
 static extern uint mixerGetLineInfo(IntPtr hmxobj, ref MIXERLINE pmxl, MIXER flags);
Ejemplo n.º 39
0
 private static extern int mixerGetLineInfoA(int hmxobj, ref MIXERLINE pmxl, int fdwInfo);
Ejemplo n.º 40
0
 internal static extern int mixerGetLineInfo(IntPtr hmxobj, ref MIXERLINE pmxl, MIXER_GETLINEINFOF fdwInfo);
Ejemplo n.º 41
0
 internal static extern int mixerGetLineInfoA(IntPtr hmxobj, ref
                                              MIXERLINE pmxl, int fdwInfo);
Ejemplo n.º 42
0
 public static extern MmResult mixerGetLineInfo(IntPtr hMixer, ref MIXERLINE mixerLine, MixerFlags dwInfoFlags);
Ejemplo n.º 43
0
        public MixerAPI()
        {
            _hMixer = new IntPtr();
            uint mmresult = mixerOpen(ref _hMixer, 0, IntPtr.Zero, IntPtr.Zero, MIXER_OBJECTF.MIXER);

            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                throw new MixerException("mixerOpen:", mmresult);
            }

            MIXERLINE lineInfo = new MIXERLINE();

            lineInfo.StructSize    = (uint)Marshal.SizeOf(new MIXERLINE());
            lineInfo.ComponentType = (uint)MIXERLINE_COMPONENTTYPE.SRC_WAVEOUT;
            //volInfo.ComponentType =(uint)MIXERLINE_COMPONENTTYPE.DST_SPEAKERS;
            mmresult = mixerGetLineInfo(_hMixer, ref lineInfo, MIXER_OBJECTF.HMIXER
                                        , MIXER_GETLINEINFOF.COMPONENTTYPE);

            IntPtr ctlPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROL()));

            MIXERLINECONTROLS ctlParam = new MIXERLINECONTROLS();

            ctlParam.StructSize           = (uint)Marshal.SizeOf(new MIXERLINECONTROLS());
            ctlParam.LineID               = lineInfo.dwLineID;
            ctlParam.ControlType          = MIXERCONTROL_CONTROLTYPE.MUTE;
            ctlParam.Controls             = 1;
            ctlParam.MixerControlItemSize = (uint)Marshal.SizeOf(new MIXERCONTROL());
            ctlParam.MixerControlArray    = ctlPtr;

            mmresult = mixerGetLineControls(_hMixer, ref ctlParam, MIXER_OBJECTF.HMIXER
                                            , MIXER_GETLINECONTROLSF.ONEBYTYPE);
            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                Marshal.FreeCoTaskMem(ctlPtr);
                throw new MixerException("mixerGetLineControls", mmresult);
            }

            MIXERCONTROL muteCtrl = (MIXERCONTROL)Marshal.PtrToStructure(ctlPtr, typeof(MIXERCONTROL));

            _muteID = muteCtrl.ControlID;

            ctlParam.ControlType = MIXERCONTROL_CONTROLTYPE.VOLUME;
            //他の値は再利用。まだMarshal.FreeCoTaskMemを呼んではいけない

            mmresult = mixerGetLineControls(_hMixer, ref ctlParam, MIXER_OBJECTF.HMIXER
                                            , MIXER_GETLINECONTROLSF.ONEBYTYPE);
            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                Marshal.FreeCoTaskMem(ctlPtr);
                throw new MixerException("mixerGetLineControls", mmresult);
            }

            MIXERCONTROL volCtrl = (MIXERCONTROL)Marshal.PtrToStructure(ctlPtr, typeof(MIXERCONTROL));

            Marshal.FreeCoTaskMem(ctlPtr);

            _volumeID = volCtrl.ControlID;
            _volMax   = volCtrl.Bounds.UnsignedMaximum;
            _volMin   = volCtrl.Bounds.UnsignedMinimum;

            Debug.WriteLine(string.Format("MixerAPI constructor muteID:{0} volID:{1} volMan:{2} volMin:{3}",
                                          _muteID, _volumeID, _volMax, _volMin));
        }
Ejemplo n.º 44
0
    private static void GetVolumeControl(int hmixer, int componentType,
                                         int ctrlType, out MIXERCONTROL mxc, out int vCurrentVol)
    {
      // This function attempts to obtain a mixer control. 
      // Returns True if successful. 
      MIXERLINECONTROLS mxlc = new MIXERLINECONTROLS();
      MIXERLINE mxl = new MIXERLINE();
      MIXERCONTROLDETAILS pmxcd = new MIXERCONTROLDETAILS();
      MIXERCONTROLDETAILS_UNSIGNED du = new
        MIXERCONTROLDETAILS_UNSIGNED();
      mxc = new MIXERCONTROL();

      vCurrentVol = -1;

      //mxl.szShortName = new string(' ', MIXER_SHORT_NAME_CHARS); 
      //mxl.szName = new string(' ', MIXER_LONG_NAME_CHARS); 
      mxl.cbStruct = Marshal.SizeOf(mxl);
      mxl.dwComponentType = componentType;

      // Obtain a line corresponding to the component public enum 
      CheckErr(mixerGetLineInfoA(hmixer, ref mxl,
                                 MIXER_GETLINEINFOF_COMPONENTTYPE));

      int sizeofMIXERCONTROL = 152;
      //Marshal.SizeOf(typeof(MIXERCONTROL)) 
      int ctrl = Marshal.SizeOf(typeof (MIXERCONTROL));
      mxlc.pamxctrl = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL); //new MIXERCONTROL(); 
      mxlc.cbStruct = Marshal.SizeOf(mxlc);
      mxlc.dwLineID = mxl.dwLineID;
      mxlc.dwControl = ctrlType;
      mxlc.cControls = 1;
      mxlc.cbmxctrl = sizeofMIXERCONTROL;

      // Allocate a buffer for the control 
      mxc.cbStruct = sizeofMIXERCONTROL;

      // Get the control 
      try
      {
        CheckErr(mixerGetLineControlsA(hmixer, ref mxlc,
                                       MIXER_GETLINECONTROLSF_ONEBYTYPE));
        // Copy the control into the destination structure 
        mxc = (MIXERCONTROL)Marshal.PtrToStructure(mxlc.pamxctrl, typeof (MIXERCONTROL));
      }
      catch (Exception e)
      {
        throw e;
      }
      finally
      {
        Marshal.FreeCoTaskMem(mxlc.pamxctrl);
      }
      int sizeofMIXERCONTROLDETAILS =
        Marshal.SizeOf(typeof (MIXERCONTROLDETAILS));
      int sizeofMIXERCONTROLDETAILS_UNSIGNED =
        Marshal.SizeOf(typeof (MIXERCONTROLDETAILS_UNSIGNED));
      pmxcd.cbStruct = sizeofMIXERCONTROLDETAILS;
      pmxcd.dwControlID = mxc.dwControlID;
      pmxcd.paDetails =
        Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED);
      pmxcd.cChannels = 1;
      pmxcd.item = 0;
      pmxcd.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED;

      try
      {
        CheckErr(mixerGetControlDetailsA(hmixer, ref pmxcd,
                                         MIXER_GETCONTROLDETAILSF_VALUE));
        du =
          (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(pmxcd.paDetails, typeof (MIXERCONTROLDETAILS_UNSIGNED));
      }
      catch (Exception e)
      {
        throw e;
      }
      finally
      {
        Marshal.FreeCoTaskMem(pmxcd.paDetails);
      }
      vCurrentVol = du.dwValue;
    }
        private static void GetVolumeControl(int hmixer, int componentType,
                                             int ctrlType, out MIXERCONTROL mxc, out int vCurrentVol)
        {
            // This function attempts to obtain a mixer control.
            // Returns True if successful.
            MIXERLINECONTROLS            mxlc  = new MIXERLINECONTROLS();
            MIXERLINE                    mxl   = new MIXERLINE();
            MIXERCONTROLDETAILS          pmxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED du    = new
                                                 MIXERCONTROLDETAILS_UNSIGNED();

            mxc = new MIXERCONTROL();

            vCurrentVol = -1;

            //mxl.szShortName = new string(' ', MIXER_SHORT_NAME_CHARS);
            //mxl.szName = new string(' ', MIXER_LONG_NAME_CHARS);
            mxl.cbStruct        = Marshal.SizeOf(mxl);
            mxl.dwComponentType = componentType;

            // Obtain a line corresponding to the component public enum
            CheckErr(mixerGetLineInfoA(hmixer, ref mxl,
                                       MIXER_GETLINEINFOF_COMPONENTTYPE));

            int sizeofMIXERCONTROL = 152;
            //Marshal.SizeOf(typeof(MIXERCONTROL))
            int ctrl = Marshal.SizeOf(typeof(MIXERCONTROL));

            mxlc.pamxctrl  = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL); //new MIXERCONTROL();
            mxlc.cbStruct  = Marshal.SizeOf(mxlc);
            mxlc.dwLineID  = mxl.dwLineID;
            mxlc.dwControl = ctrlType;
            mxlc.cControls = 1;
            mxlc.cbmxctrl  = sizeofMIXERCONTROL;

            // Allocate a buffer for the control
            mxc.cbStruct = sizeofMIXERCONTROL;

            // Get the control
            try
            {
                CheckErr(mixerGetLineControlsA(hmixer, ref mxlc,
                                               MIXER_GETLINECONTROLSF_ONEBYTYPE));
                // Copy the control into the destination structure
                mxc = (MIXERCONTROL)Marshal.PtrToStructure(mxlc.pamxctrl, typeof(MIXERCONTROL));
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                Marshal.FreeCoTaskMem(mxlc.pamxctrl);
            }
            int sizeofMIXERCONTROLDETAILS =
                Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
            int sizeofMIXERCONTROLDETAILS_UNSIGNED =
                Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED));

            pmxcd.cbStruct    = sizeofMIXERCONTROLDETAILS;
            pmxcd.dwControlID = mxc.dwControlID;
            pmxcd.paDetails   =
                Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED);
            pmxcd.cChannels = 1;
            pmxcd.item      = 0;
            pmxcd.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED;

            try
            {
                CheckErr(mixerGetControlDetailsA(hmixer, ref pmxcd,
                                                 MIXER_GETCONTROLDETAILSF_VALUE));
                du =
                    (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(pmxcd.paDetails, typeof(MIXERCONTROLDETAILS_UNSIGNED));
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                Marshal.FreeCoTaskMem(pmxcd.paDetails);
            }
            vCurrentVol = du.dwValue;
        }
Ejemplo n.º 46
0
        protected static bool GetMuteControl(int hmixer, int componentType, int ctrlType, out MIXERCONTROL mxc, out bool vCurrentMute)
        {
            // This function attempts to obtain a mixer control.
            // Returns True if successful.
            MIXERLINECONTROLS           mxlc  = new MIXERLINECONTROLS();
            MIXERLINE                   mxl   = new MIXERLINE();
            MIXERCONTROLDETAILS         pmxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_BOOLEAN du    = new MIXERCONTROLDETAILS_BOOLEAN();

            mxc = new MIXERCONTROL();
            int  rc;
            bool retValue;

            vCurrentMute = false;

            mxl.cbStruct        = Marshal.SizeOf(mxl);
            mxl.dwComponentType = componentType;

            rc = mixerGetLineInfoA(hmixer, ref mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);

            if (MMSYSERR_NOERROR == rc)
            {
                int sizeofMIXERCONTROL = 152;
                int ctrl = Marshal.SizeOf(typeof(MIXERCONTROL));
                mxlc.pamxctrl  = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
                mxlc.cbStruct  = Marshal.SizeOf(mxlc);
                mxlc.dwLineID  = mxl.dwLineID;
                mxlc.dwControl = ctrlType;
                mxlc.cControls = 1;
                mxlc.cbmxctrl  = sizeofMIXERCONTROL;

                // Allocate a buffer for the control
                mxc.cbStruct = sizeofMIXERCONTROL;

                // Get the control
                rc = mixerGetLineControlsA(hmixer, ref mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
                if (MMSYSERR_NOERROR == rc)
                {
                    retValue = true;

                    // Copy the control into the destination structure
                    mxc = (MIXERCONTROL)Marshal.PtrToStructure(
                        mxlc.pamxctrl, typeof(MIXERCONTROL));
                }
                else
                {
                    retValue = false;
                }

                int sizeofMIXERCONTROLDETAILS         = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
                int sizeofMIXERCONTROLDETAILS_BOOLEAN = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_BOOLEAN));
                pmxcd.cbStruct    = sizeofMIXERCONTROLDETAILS;
                pmxcd.dwControlID = mxc.dwControlID;
                pmxcd.paDetails   = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_BOOLEAN);
                pmxcd.cChannels   = 1;
                pmxcd.item        = 0;
                pmxcd.cbDetails   = sizeofMIXERCONTROLDETAILS_BOOLEAN;

                rc = mixerGetControlDetailsA(hmixer, ref pmxcd, MIXER_GETCONTROLDETAILSF_VALUE);

                du = (MIXERCONTROLDETAILS_BOOLEAN)Marshal.PtrToStructure(pmxcd.paDetails, typeof(MIXERCONTROLDETAILS_BOOLEAN));

                vCurrentMute = (du.fValue != 0);

                return(retValue);
            }

            retValue = false;
            return(retValue);
        }
Ejemplo n.º 47
0
		public extern static uint mixerGetLineInfo(uint hmxobj, ref MIXERLINE pmxl, uint fdwInfo);
Ejemplo n.º 48
0
 public static extern MmResult mixerGetLineInfo(IntPtr hMixer, ref MIXERLINE mixerLine, MixerFlags dwInfoFlags);