Esempio n. 1
0
        internal static MixerControl[] GetControls(Mixer mx, MixerLine line, int controlCount)
        {
            if (controlCount == 0)
            {
                return(new MixerControl[0]);
            }
            MIXERCONTROL[] mc     = new MIXERCONTROL[controlCount];
            int            mxsize = Marshal.SizeOf(mc[0]);

            if (mxsize != 148)
            {
                throw new Exception("" + mxsize);
            }
            //mxsize = 148;

            MIXERLINECONTROLS mlc = new MIXERLINECONTROLS();

            mlc.cbStruct  = Marshal.SizeOf(mlc);
            mlc.cControls = controlCount;
            mlc.dwLineID  = line.Id;

            mlc.pamxctrl = Marshal.AllocCoTaskMem(mxsize * controlCount);
            mlc.cbmxctrl = mxsize;

            int err;

            if ((err = mixerGetLineControlsA(mx.Handle, ref mlc, MIXER_GETLINECONTROLSF_ALL)) != 0)
            {
                throw new Win32Exception("Error #" + err + " calling mixerGetLineControls()\n");
            }

            for (int i = 0; i < controlCount; i++)
            {
                mc[i] = (MIXERCONTROL)Marshal.PtrToStructure(new IntPtr(mlc.pamxctrl.ToInt64() + mxsize * i),
                                                             typeof(MIXERCONTROL));
            }

            Marshal.FreeCoTaskMem(mlc.pamxctrl);
            MixerControl[] result = new MixerControl[controlCount];
            for (int i = 0; i < controlCount; i++)
            {
                result[i] = GetControl(mx, line, mc[i]);
            }

            return(result);
        }
Esempio n. 2
0
        public static int GetControlID( int component, int control )                                        // GetControlID
        {
            MIXERCONTROL mxc = new MIXERCONTROL();
            int _i;         // Though we won't need _i, it still must be declared                                    

            bool b = false;
            int retValue = 0;

            b = GetMixerControl(
                            0,
                            component,
                            control,
                            out mxc,
                            out _i);

            return retValue = b ? mxc.dwControlID : -1;
        }
Esempio n. 3
0
        public static void SetVolume(int vVolume)

        {
            int mixer;

            MIXERCONTROL volCtrl = new MIXERCONTROL();

            int currentVol;

            mixerOpen(out mixer, 0, 0, 0, 0);

            int type = MIXERCONTROL_CONTROLTYPE_VOLUME;

            GetVolumeControl(mixer,

                             MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out

                             currentVol);

            if (vVolume > volCtrl.lMaximum)
            {
                vVolume = volCtrl.lMaximum;
            }

            if (vVolume < volCtrl.lMinimum)
            {
                vVolume = volCtrl.lMinimum;
            }

            SetVolumeControl(mixer, volCtrl, vVolume);

            GetVolumeControl(mixer,

                             MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out

                             currentVol);

            if (vVolume != currentVol)

            {
                throw new Exception("Cannot Set Volume");
            }

            mixerClose(mixer);
        }
Esempio n. 4
0
            public static float GetVolume()
            {
                int          mixer;
                MIXERCONTROL volCtrl = new MIXERCONTROL();
                int          currentVol;

                mixerOpen(out mixer, 0, 0, 0, 0);
                int type = MIXERCONTROL_CONTROLTYPE_VOLUME;

                GetVolumeControl(
                    mixer,
                    MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
                    type,
                    out volCtrl,
                    out currentVol);
                mixerClose(mixer);
                return((float)currentVol / (float)volCtrl.lMaximum * 100.0f);
            }
Esempio n. 5
0
        private static MixerControl GetControl(Mixer mx, MixerLine ml, MIXERCONTROL mc)
        {
            MixerControl result = new MixerControl(mx, ml, mc);

            if (result.Class == MixerControlClass.FADER && ((uint)result.ControlType & MIXERCONTROL_CT_UNITS_MASK) == (uint)MixerControlType.MIXERCONTROL_CT_UNITS_UNSIGNED)
            {
                result = new FaderMixerControl(mx, ml, mc);
            }
            else if (result.Class == MixerControlClass.SWITCH && ((uint)result.ControlType & MIXERCONTROL_CT_SUBCLASS_MASK) == (uint)MixerControlType.MIXERCONTROL_CT_SC_SWITCH_BOOLEAN && ((uint)result.ControlType & MIXERCONTROL_CT_UNITS_MASK) == (uint)MixerControlType.MIXERCONTROL_CT_UNITS_BOOLEAN)
            {
                result = new BooleanMixerControl(mx, ml, mc);
            }
            else if (result.Class == MixerControlClass.LIST && ((uint)result.ControlType & MIXERCONTROL_CT_SUBCLASS_MASK) == (uint)MixerControlType.MIXERCONTROL_CT_SC_SWITCH_BOOLEAN && ((uint)result.ControlType & MIXERCONTROL_CT_UNITS_MASK) == (uint)MixerControlType.MIXERCONTROL_CT_UNITS_BOOLEAN)
            {
                result = new ListMixerControl(mx, ml, mc);
            }
            return(result);
        }
Esempio n. 6
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); }
        }
Esempio n. 7
0
        private static int getVolume()
        {
            int mixer;

            MIXERCONTROL volCtrl = new MIXERCONTROL();

            int currentVol;

            mixerOpen(out mixer, 0, 0, 0, 0);

            int type = MIXERCONTROL_CONTROLTYPE_VOLUME;

            getVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out currentVol);

            mixerClose(mixer);

            System.Diagnostics.Debug.WriteLine("Vol: " + currentVol.ToString());

            return(currentVol);
        }
Esempio n. 8
0
        public static bool setMicVolume(int mxid, int percentage)
        {
            if (mixerdisabled)
            {
                return(false);
            }

            bool         rc;
            int          mixer, vVolume, ctrltype, comptype;
            MIXERCONTROL volCtrl = new MIXERCONTROL();
            int          currentVol;
            int          mr = mixerOpen(out mixer, mxid, 0, 0, (int)MIXER_OBJECTF_WAVEIN);

            if (mr != MMSYSERR_NOERROR)
            {
                //Warning("mixerOpen() failed: " + mr.ToString());
                mixerdisabled = true;
                return(false);
            }
            ctrltype = MIXERCONTROL_CONTROLTYPE_VOLUME;
            comptype = (int)MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
            rc       = GetVolumeControl(mixer, comptype, ctrltype, out volCtrl, out currentVol);
            if (rc == false)
            {
                //Warning("SetMicVolume/GetVolumeControl() failed");
                mixerdisabled = true;
                mixerClose(mixer);
                return(false);
            }
            vVolume = ((int)((float)(volCtrl.lMaximum - volCtrl.lMinimum) / 100.0F) * percentage);
            rc      = SetVolumeControl(mixer, volCtrl, vVolume);
            if (rc == false)
            {
                //Warning("SetMicVolume/SetVolumeControl() failed");
                mixerdisabled = true;
                mixerClose(mixer);
                return(false);
            }
            mixerClose(mixer);
            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// 사운드볼륨을 퍼센트 단위로 설정
        /// </summary>
        /// <param name="iPercent">볼륨 퍼센트</param>
        public static void SetVolumePercent(int iPercent)
        {
            try
            {
                int iVolumn = 0;
                int mixer;
                int currentVol;

                if (iPercent < 0)
                {
                    iPercent = 0;
                }
                else if (iPercent > 100)
                {
                    iPercent = 100;
                }

                MIXERCONTROL volCtrl = new MIXERCONTROL();
                mixerOpen(out mixer, 0, 0, 0, 0);
                int type = MIXERCONTROL_CONTROLTYPE_VOLUME;
                GetVolumeControl(mixer,
                                 MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out
                                 currentVol);

                iVolumn = volCtrl.lMaximum * iPercent / 100;

                SetVolumeControl(mixer, volCtrl, iVolumn);
                GetVolumeControl(mixer,
                                 MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out
                                 currentVol);
                if (iVolumn != currentVol)
                {
                    throw new Exception("Cannot Set Volume");
                }
                mixerClose(mixer);
            }
            catch (Exception ex)
            {
                MainForm.log.write(ex.Message);
            }
        }
Esempio n. 10
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);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="vVolume"></param>
        public static void SetVolume(int vVolume)
        {
            int          mixer;
            MIXERCONTROL volCtrl = new MIXERCONTROL();
            int          currentVol;

            CheckErr(mixerOpen(out mixer, 0, 0, 0, 0));
            try
            {
                int type = MIXERCONTROL_CONTROLTYPE_VOLUME;
                GetVolumeControl(mixer,
                                 MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out
                                 currentVol);

                int diff = volCtrl.lMaximum - volCtrl.lMinimum;
                if (diff > 0)
                {
                    long normalized = (long)vVolume * (long)diff / 65535L;
                    vVolume = (int)normalized + volCtrl.lMinimum;
                }

                if (vVolume > volCtrl.lMaximum)
                {
                    vVolume = volCtrl.lMaximum;
                }
                if (vVolume < volCtrl.lMinimum)
                {
                    vVolume = volCtrl.lMinimum;
                }
                SetVolumeControl(mixer, volCtrl, vVolume);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                CheckErr(mixerClose(mixer));
            }
        }
Esempio n. 12
0
        private static bool SetVolumeControl(int hmixer, MIXERCONTROL mxc,
                                             int volume)
        {
            // This function sets the value for a volume control.
            // Returns True if successful

            bool retValue;
            int  rc;
            MIXERCONTROLDETAILS          mxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED vol  = new
                                                MIXERCONTROLDETAILS_UNSIGNED();

            mxcd.item        = 0;
            mxcd.dwControlID = mxc.dwControlID;
            mxcd.cbStruct    = Marshal.SizeOf(mxcd);
            mxcd.cbDetails   = Marshal.SizeOf(vol);

            // Allocate a buffer for the control value buffer
            mxcd.cChannels = 1;
            vol.dwValue    = volume;

            // Copy the data into the control value buffer
            mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(
                                                        typeof(MIXERCONTROLDETAILS_UNSIGNED)));
            Marshal.StructureToPtr(vol, mxcd.paDetails, false);

            // Set the control value
            rc = mixerSetControlDetails(hmixer, ref mxcd,
                                        MIXER_SETCONTROLDETAILSF_VALUE);

            if (MMSYSERR_NOERROR == rc)
            {
                retValue = true;
            }
            else
            {
                retValue = false;
            } return(retValue);
        }
        private static void SetVolumeControl(int hmixer, MIXERCONTROL mxc,
                                             int volume)
        {
            // This function sets the value for a volume control.
            // Returns True if successful
            MIXERCONTROLDETAILS          mxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED vol  = new
                                                MIXERCONTROLDETAILS_UNSIGNED();

            mxcd.item        = 0;
            mxcd.dwControlID = mxc.dwControlID;
            mxcd.cbStruct    = Marshal.SizeOf(mxcd);
            mxcd.cbDetails   = Marshal.SizeOf(vol);

            // Allocate a buffer for the control value buffer
            mxcd.cChannels = 1;
            vol.dwValue    = volume;

            // Copy the data into the control value buffer
            //mxcd.paDetails = vol;
            //(MIXERCONTROL)Marshal.PtrToStructure(mxlc.pamxctrl,typeof(MIXERCONTROL));
            mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED)));
            Marshal.StructureToPtr(vol, mxcd.paDetails, false);

            // Set the control value
            try
            {
                CheckErr(mixerSetControlDetails(hmixer, ref mxcd,
                                                MIXER_SETCONTROLDETAILSF_VALUE));
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                Marshal.FreeCoTaskMem(mxcd.paDetails);
            }
        }
Esempio n. 14
0
        /// <summary>Open the mixer</summary>
        /// <returns>error</returns>
        public MMSYSERR OpenMixer()
        {
            MMSYSERR err = MMSYSERR.NOERROR;

            err = mixerOpen(ref _hMixer, 0, IntPtr.Zero, IntPtr.Zero, 0);
            if (err == MMSYSERR.NOERROR)
            {
                _tVolume          = new MIXERCONTROL();
                _tVolume.cbStruct = (uint)Marshal.SizeOf(_tVolume);

                err = GetVolumeInfo(_hMixer, MIXERCONTROL_CONTROLTYPE_VOLUME, ref _tVolume);
                if (err == MMSYSERR.NOERROR)
                {
                    _iVolNorm = (int)_tVolume.fdwControl;
                    return(err);
                }
            }
            if (err != MMSYSERR.NOERROR && _hMixer != IntPtr.Zero)
            {
                CloseMixer();
            }
            return(err);
        }
Esempio n. 15
0
        private bool SetVolumeControl(                                                                       // SetVolumeControl
            int hmixer,
            MIXERCONTROL mxc,
            int volume)
        {
            bool retValue = false;
            int  rc;

            MIXERCONTROLDETAILS          mxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_UNSIGNED vol  = new MIXERCONTROLDETAILS_UNSIGNED();

            mxcd.item        = 0;
            mxcd.dwControlID = mxc.dwControlID;
            mxcd.cbStruct    = Marshal.SizeOf(mxcd);
            mxcd.cbDetails   = Marshal.SizeOf(vol);

            // Allocate a buffer for the control value buffer
            mxcd.cChannels = 1;
            vol.dwValue    = volume;

            // Copy the data into the control value buffer
            mxcd.paDetails = Marshal.AllocCoTaskMem(
                Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED)));

            Marshal.StructureToPtr(
                vol,
                mxcd.paDetails,
                false);

            // Set the control value
            rc = mixerSetControlDetails(
                hmixer,
                ref mxcd,
                MIXER_SETCONTROLDETAILSF_VALUE);

            return(retValue = MMSYSERR_NOERROR == rc ? true : false);
        }
Esempio n. 16
0
        private static void setVolume(int vVolume)
        {
            try
            {
                int mixer;

                MIXERCONTROL volCtrl = new MIXERCONTROL();

                int currentVol;

                mixerOpen(out mixer, 0, 0, 0, 0);

                int type = MIXERCONTROL_CONTROLTYPE_VOLUME;

                getVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out currentVol);

                if (vVolume > volCtrl.lMaximum)
                {
                    vVolume = volCtrl.lMaximum;
                }

                if (vVolume < volCtrl.lMinimum)
                {
                    vVolume = volCtrl.lMinimum;
                }

                setVolumeControl(mixer, volCtrl, vVolume);

                getVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out currentVol);

                mixerClose(mixer);
            }
            catch
            {
            }
        }
Esempio n. 17
0
		private static bool GetMute(int mixerID, uint dst_type, uint src_type)
		{
			int mixer;
			MIXERCONTROL muteCtrl = new MIXERCONTROL();
			int val;

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			bool success = GetControlByType(mixer, dst_type, src_type, MIXERCONTROL_CONTROLTYPE_MUTE, out muteCtrl);
			if(success == true)
			{
				MIXERCONTROLDETAILS details = new MIXERCONTROLDETAILS();

				int sizeofMIXERCONTROLDETAILS = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS)); 
				int sizeofMIXERCONTROLDETAILS_UNSIGNED = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED)); 
				details.cbStruct = sizeofMIXERCONTROLDETAILS; 
				details.dwControlID = muteCtrl.dwControlID; 
				details.paDetails = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED); 
				details.cChannels = 1; 
				details.item = 0; 
				details.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED; 

				int retval = mixerGetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE); 
				if(retval == MMSYSERR_NOERROR)				
				{
					MIXERCONTROLDETAILS_UNSIGNED du = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(details.paDetails, typeof(MIXERCONTROLDETAILS_UNSIGNED)); 
					val = du.dwValue; 
				}
				else val = -1;
				Marshal.FreeCoTaskMem(details.paDetails);
			}
			else val = -1;
			mixerClose(mixer);
			return (val == 1);
		}
Esempio n. 18
0
		private static bool SetVolume(int mixerID, uint dst_type, uint src_type, int val)
		{
			int mixer;
			MIXERCONTROL volCtrl = new MIXERCONTROL();
			int currentVol = GetVolume(mixerID, dst_type, src_type);
			if(currentVol == val) return true;

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			bool success = GetControlByType(mixer, dst_type, src_type, MIXERCONTROL_CONTROLTYPE_VOLUME, out volCtrl);
			if(success == true)
			{
				if(val>volCtrl.lMaximum) val = volCtrl.lMaximum; 
				if(val<volCtrl.lMinimum) val = volCtrl.lMinimum; 

				MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS(); 
				MIXERCONTROLDETAILS_UNSIGNED vol = new MIXERCONTROLDETAILS_UNSIGNED(); 

				mxcd.item = 0; 
				mxcd.dwControlID = volCtrl.dwControlID; 
				mxcd.cbStruct = Marshal.SizeOf(mxcd); 
				mxcd.cbDetails = Marshal.SizeOf(vol); 

				// Allocate a buffer for the control value buffer 
				mxcd.cChannels = 1; 
				vol.dwValue = val; 

				// Copy the data into the control value buffer 
				mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED))); 
				Marshal.StructureToPtr(vol, mxcd.paDetails,false); 

				// Set the control value 
				int retval = mixerSetControlDetails(mixer, ref mxcd, MIXER_SETCONTROLDETAILSF_VALUE); 
				if(retval == MMSYSERR_NOERROR) 
				{
					currentVol = GetVolume(mixerID, dst_type, src_type);
					if(currentVol != val)
						success = false;
					else success = true;
				}
				else success = false;
				Marshal.FreeCoTaskMem(mxcd.paDetails);
			}
			else success = false;
			mixerClose(mixer);
			return success;
		}
Esempio n. 19
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;
		}
Esempio n. 20
0
 public MuteAudioLineControl(AudioLine audioLine, MIXERCONTROL mc, Action <AudioLine> raiseEventDelegate)
     : base(audioLine, mc, raiseEventDelegate)
 {
 }
Esempio n. 21
0
 public static int GetMinMaxVolume(out int iMin, out int iMax)
 {
   int mixer;
   MIXERCONTROL volCtrl = new MIXERCONTROL();
   int currentVol;
   mixerOpen(out mixer, 0, 0, 0, 0);
   int type = MIXERCONTROL_CONTROLTYPE_VOLUME;
   GetVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out currentVol);
   mixerClose(mixer);
   iMin = volCtrl.lMinimum;
   iMax = volCtrl.lMaximum;
   return currentVol;
 }
Esempio n. 22
0
 internal MixerControl(Mixer mx, MixerLine ml, MIXERCONTROL ctrl)
 {
     this.mx   = mx;
     this.ml   = ml;
     this.ctrl = ctrl;
 }
Esempio n. 23
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;
		}
        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;
        }
Esempio n. 25
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);
		}
Esempio n. 26
0
		private static bool SetUnsigned(int mixer, MIXERCONTROL ctrl, int num)
		{
			int current_val;
			if(!GetUnsigned(mixer, ctrl, out current_val))
				return false;

			if(current_val == num)
				return true;
            
			if(num > ctrl.lMaximum) num = ctrl.lMaximum;
			if(num < ctrl.lMinimum) num = ctrl.lMinimum;

			MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS();
			MIXERCONTROLDETAILS_UNSIGNED val = new MIXERCONTROLDETAILS_UNSIGNED();

			mxcd.item = 0;
			mxcd.dwControlID = ctrl.dwControlID;
			mxcd.cbStruct = Marshal.SizeOf(mxcd);
			mxcd.cbDetails = Marshal.SizeOf(val);

			mxcd.cChannels = 1;
			val.dwValue = num;

			mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(val));
			Marshal.StructureToPtr(val, mxcd.paDetails, false);

			int retval = mixerSetControlDetails(mixer, ref mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
			Marshal.FreeCoTaskMem(mxcd.paDetails);

			if(retval != MMSYSERR_NOERROR)
				return false;
		
			if(!GetUnsigned(mixer, ctrl, out current_val))
				return false;

			if(current_val == num)
				return true;
			else
				return false;
		}
Esempio n. 27
0
        private static int GetVolume_RealtekHDaudio(int mixerID, int dst_type, int src_type)        // yt7pwr
        {
            if (mixerID > mixerGetNumDevs() - 1 ||
                mixerID < 0)
                return -1;

            int mixer;
            int val;
            MIXERCONTROL volCtrl = new MIXERCONTROL();

            int retval = mixerOpen(out mixer, mixerID, 0, 0, 0);
            if (retval != MMSYSERR_NOERROR)
                return -1;

            bool success = GetControlByID(mixer, dst_type, src_type, MIXERCONTROL_CONTROLTYPE_VOLUME, out volCtrl);
            if (success == true)
            {
                MIXERCONTROLDETAILS details = new MIXERCONTROLDETAILS();

                int sizeofMIXERCONTROLDETAILS = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
                int sizeofMIXERCONTROLDETAILS_UNSIGNED = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED));
                details.cbStruct = sizeofMIXERCONTROLDETAILS;
                details.dwControlID = volCtrl.dwControlID;
                details.paDetails = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED);
                details.cChannels = 1;
                details.item = 0;
                details.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED;

                retval = mixerGetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE);
                if (retval == MMSYSERR_NOERROR)
                {
                    MIXERCONTROLDETAILS_UNSIGNED du = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(details.paDetails, typeof(MIXERCONTROLDETAILS_UNSIGNED));
                    val = du.dwValue;
                }
                else val = -1;
                Marshal.FreeCoTaskMem(details.paDetails);
            }
            else val = -1;
            mixerClose(mixer);
            return val;
        }
Esempio n. 28
0
        public static bool InitRealtekHDaudioPlay(int mixerID)      // yt7pwr
        {
            try
            {
                int mixer;
                int retval = -1;
                retval = mixerOpen(out mixer, mixerID, 0, 0, 0);
                if (retval != MMSYSERR_NOERROR)
                    return false;

                MIXERCONTROL ctrl = new MIXERCONTROL();
                // set Playback Wave Volume to max
                bool success = GetControlByType(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
                    4104, MIXERCONTROL_CONTROLTYPE_MUX, out ctrl);
                if (!success)
                    goto failed;
                if (!SetUnsigned(mixer, ctrl, ctrl.lMaximum))
                    goto failed;

                mixerClose(mixer);
                return true;

            failed:
                mixerClose(mixer);
                return false;
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
                return false;
            }
        }
Esempio n. 29
0
        public static bool InitRealtekHDaudioRecord(int mixerID, int record_level)      // yt7pwr
        {
            try
            {
                int mixer;
                int retval = -1;
                retval = mixerOpen(out mixer, mixerID, 0, 0, 0);
                if (retval != MMSYSERR_NOERROR)
                    return false;

                // turn Main Mute Off
                MIXERCONTROL ctrl = new MIXERCONTROL();
                bool success = false;

                int i;
                for (i = -1; i < 4; i++)
                {
                    success = GetControlByID(mixer, 0, i, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
                    if (success)
                    {
                        if (ctrl.szName.Contains("Master Mute"))
                        {
                            if (!SetBool(mixer, ctrl, false))
                                goto failed;
                        }
                        // turn CD volume Mute off
                        else if (ctrl.szName.Contains("CD Volume"))
                        {
                            if (!SetBool(mixer, ctrl, true))
                                goto failed;
                        }
                        // turn Line volume Mute on
                        else if (ctrl.szName.Contains("Line Volume"))
                        {
                            if (!SetBool(mixer, ctrl, false))
                                goto failed;
                        }
                        // turn Mic Mute Off
                        else if (ctrl.szName.Contains("Mic Volume"))
                        {
                            if (!SetBool(mixer, ctrl, true))
                                goto failed;
                        }
                        // turn Stereo Mix Mute on
                        else if (ctrl.szName.Contains("Stereo Mix"))
                        {
                            if (!SetBool(mixer, ctrl, true))
                                goto failed;
                        }
                    }
                }

                // set Record Main Volume to max
                success = GetControlByID(mixer, 0, -1, MIXERCONTROL_CONTROLTYPE_VOLUME, out ctrl);
                if (!success && ctrl.szName.Contains("Recording"))
                    goto failed;
                if (!SetUnsigned(mixer, ctrl, UInt16.MaxValue * record_level / 100))
                    goto failed;

                mixerClose(mixer);
                return true;

            failed:
                mixerClose(mixer);
                return false;
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
                return false;
            }
        }
Esempio n. 30
0
		private static bool SetBool(int mixer, MIXERCONTROL ctrl, bool b)
		{
			bool current;
			if(!GetBool(mixer, ctrl, out current))
				return false;

			if(current == b) 
				return true;

            MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS(); 
			MIXERCONTROLDETAILS_UNSIGNED val = new MIXERCONTROLDETAILS_UNSIGNED(); 

			mxcd.item = 0; 
			mxcd.dwControlID = ctrl.dwControlID; 
			mxcd.cbStruct = Marshal.SizeOf(mxcd); 
			mxcd.cbDetails = Marshal.SizeOf(val); 

			// Allocate a buffer for the control value buffer 
			mxcd.cChannels = 1; 
			if(b) val.dwValue = 1;
			else val.dwValue = 0;

			// Copy the data into the control value buffer 
			mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(val)); 
			Marshal.StructureToPtr(val, mxcd.paDetails, false); 

			// Set the control value 
			int retval = mixerSetControlDetails(mixer, ref mxcd, MIXER_SETCONTROLDETAILSF_VALUE); 
			if(retval != MMSYSERR_NOERROR) 
			{
				Marshal.FreeCoTaskMem(mxcd.paDetails);
				return false;
			}
			Marshal.FreeCoTaskMem(mxcd.paDetails);

			if(!GetBool(mixer, ctrl, out current))
				return false;
			
			if(current != b)
				return false;
			else return true;
		}
Esempio n. 31
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);
        }
Esempio n. 32
0
		private static bool GetUnsigned(int mixer, MIXERCONTROL ctrl, out int num)
		{
			MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS();
			num = 0;

			int sizeofMIXERCONTROLDETAILS = Marshal.SizeOf(mxcd);
			int sizeofMIXERCONTROLDETAILS_UNSIGNED = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED)); 
			mxcd.cbStruct = sizeofMIXERCONTROLDETAILS; 
			mxcd.dwControlID = ctrl.dwControlID; 
			mxcd.paDetails = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_UNSIGNED); 
			mxcd.cChannels = 1; 
			mxcd.item = 0; 
			mxcd.cbDetails = sizeofMIXERCONTROLDETAILS_UNSIGNED; 

			int retval = mixerGetControlDetails(mixer, ref mxcd, MIXER_GETCONTROLDETAILSF_VALUE);
			if(retval != MMSYSERR_NOERROR)
			{
				Marshal.FreeCoTaskMem(mxcd.paDetails);
				return false;
			}

			MIXERCONTROLDETAILS_UNSIGNED du = 
				(MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(mxcd.paDetails, typeof(MIXERCONTROLDETAILS_UNSIGNED));
			num = du.dwValue;

			Marshal.FreeCoTaskMem(mxcd.paDetails);
			return true;
		}
Esempio n. 33
0
 internal BooleanMixerControl(Mixer mx, MixerLine ml, MIXERCONTROL mc) : base(mx, ml, mc)
 {
 }
Esempio n. 34
0
		private static bool SetMute(int mixerID, uint dst_type, uint src_type, bool val)
		{
			int mixer;
			MIXERCONTROL muteCtrl = new MIXERCONTROL();
			bool currentMute = GetMute(mixerID, dst_type, src_type);
			if(currentMute == val) return true;

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			bool success = GetControlByType(mixer, dst_type, src_type, MIXERCONTROL_CONTROLTYPE_MUTE, out muteCtrl);
			if(success == true)
			{

				MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS(); 
				MIXERCONTROLDETAILS_UNSIGNED mute = new MIXERCONTROLDETAILS_UNSIGNED(); 

				mxcd.item = 0; 
				mxcd.dwControlID = muteCtrl.dwControlID; 
				mxcd.cbStruct = Marshal.SizeOf(mxcd); 
				mxcd.cbDetails = Marshal.SizeOf(mute); 

				// Allocate a buffer for the control value buffer 
				mxcd.cChannels = 1; 
				if(val)	mute.dwValue = 1;
				else mute.dwValue = 0;

				// Copy the data into the control value buffer 
				mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED))); 
				Marshal.StructureToPtr(mute, mxcd.paDetails,false); 

				// Set the control value 
				int retval = mixerSetControlDetails(mixer, ref mxcd, MIXER_SETCONTROLDETAILSF_VALUE); 
				if(retval == MMSYSERR_NOERROR) 
				{
					currentMute = GetMute(mixerID, dst_type, src_type);
					if(currentMute != val)
						success = false;
					else success = true;
				}
				else success = false;
				Marshal.FreeCoTaskMem(mxcd.paDetails);
			}
			else success = false;
			mixerClose(mixer);
			return success;
		}
Esempio n. 35
0
        public static int GetVolume( int control, int component )                                             // GetVolume
        {
            int hmixer = 0;
            int currVol = -1;

            MIXERCONTROL volCtrl = new MIXERCONTROL();

            int rc = mixerOpen(
                            out hmixer,
                            0,
                            0,
                            0,
                            0);

            bool b = GetMixerControl(
                                hmixer,
                                component,
                                control,
                                out volCtrl,        // Not used
                                out currVol);

            mixerClose(hmixer);

            return currVol;
        }
Esempio n. 36
0
 internal FaderMixerControl(Mixer mx, MixerLine ml, MIXERCONTROL mc) : base(mx, ml, mc)
 {
 }
Esempio n. 37
0
        public static int GetControlID( int component, int control )                                        // GetControlID
        {
            MIXERCONTROL mxc = new MIXERCONTROL();
            int _i;         // Though we won't need _i, it still must be declared                                    

            bool b = false;
            int retValue = 0;

            b = GetMixerControl(
                            0,
                            component,
                            control,
                            out mxc,
                            out _i);

            return retValue = b ? mxc.dwControlID : -1;
        }
Esempio n. 38
0
 private static MixerControl GetControl(Mixer mx, MixerLine ml, MIXERCONTROL mc)
 {
     MixerControl result = new MixerControl(mx, ml, mc);
     if (result.Class == MixerControlClass.FADER && ((uint)result.ControlType & MIXERCONTROL_CT_UNITS_MASK) == (uint)MixerControlType.MIXERCONTROL_CT_UNITS_UNSIGNED)
     {
         result = new FaderMixerControl(mx, ml, mc);
     }
     else if (result.Class == MixerControlClass.SWITCH && ((uint)result.ControlType & MIXERCONTROL_CT_SUBCLASS_MASK) == (uint)MixerControlType.MIXERCONTROL_CT_SC_SWITCH_BOOLEAN && ((uint)result.ControlType & MIXERCONTROL_CT_UNITS_MASK) == (uint)MixerControlType.MIXERCONTROL_CT_UNITS_BOOLEAN)
     {
         result = new BooleanMixerControl(mx, ml, mc);
     }
     return result;
 }
Esempio n. 39
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;
    }
Esempio n. 40
0
		public static int GetNumMuxLines(int mixerID)
		{
			int mixer;
			MIXERCONTROL ctrl = new MIXERCONTROL();

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			bool response = GetControlByType(mixer, MIXERLINE_COMPONENTTYPE_DST_WAVEIN, 0, MIXERCONTROL_CONTROLTYPE_MUX, out ctrl);
			mixerClose(mixer);

			if(response)
				return ctrl.cMultipleItems;
			else
				return -1;
		}
Esempio n. 41
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);
                        }
                    }
                }
            }
        }
Esempio n. 42
0
		public static bool GetMuxLineNames(int mixerID, out ArrayList a)
		{
			int mixer;
			MIXERCONTROL ctrl = new MIXERCONTROL();
			a = new ArrayList();

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			GetControlByType(mixer, MIXERLINE_COMPONENTTYPE_DST_WAVEIN, 0, MIXERCONTROL_CONTROLTYPE_MUX, out ctrl);

			int n = ctrl.cMultipleItems;
			MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS();
			mxcd.cbStruct = Marshal.SizeOf(mxcd);
			mxcd.dwControlID = ctrl.dwControlID;     // <== MIXERCONTROL.dwControlID
			mxcd.cChannels = 1;
			mxcd.item = n;   // <== MIXERCONTROL.cMultipleItems

			int size = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_LISTTEXT))*n;
			mxcd.cbDetails = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_LISTTEXT));
			mxcd.paDetails = Marshal.AllocCoTaskMem(size);

			int result = mixerGetControlDetails(mixer, ref mxcd, MIXER_GETCONTROLDETAILSF_LISTTEXT);

			if(result != MMSYSERR_NOERROR)
			{
				mixerClose(mixer);
				return false;
			}

			for(int i=0; i<mxcd.item; i++)
			{
				MIXERCONTROLDETAILS_LISTTEXT ltxt = new MIXERCONTROLDETAILS_LISTTEXT();
				IntPtr ptr = new IntPtr(mxcd.paDetails.ToInt32() + i*mxcd.cbDetails);
				
				ltxt = (MIXERCONTROLDETAILS_LISTTEXT)Marshal.PtrToStructure(ptr, typeof(MIXERCONTROLDETAILS_LISTTEXT));
				a.Add(ltxt.szName);
			}
			mixerClose(mixer);
			return true;
		}
Esempio n. 43
0
		public static int GetMux(int mixerID)
		{
			int mixer;
			MIXERCONTROL ctrl = new MIXERCONTROL();

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			GetControlByType(mixer, MIXERLINE_COMPONENTTYPE_DST_WAVEIN, 0, MIXERCONTROL_CONTROLTYPE_MUX, out ctrl);
			
			MIXERCONTROLDETAILS details = new MIXERCONTROLDETAILS();
			int size = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_UNSIGNED));
			details.dwControlID = ctrl.dwControlID; 
			details.item = ctrl.cMultipleItems;
			details.cbDetails = size;
			if(details.item > 0) size *= ctrl.cMultipleItems;
			details.paDetails = Marshal.AllocCoTaskMem(size); 
			details.cbStruct = Marshal.SizeOf(details); 
			details.cChannels = 1;									
																		
			int retval = mixerGetControlDetails(mixer, ref details, MIXER_GETCONTROLDETAILSF_VALUE); 
			if(retval == MMSYSERR_NOERROR)
			{
				if(details.item > 0)
				{
					MIXERCONTROLDETAILS_UNSIGNED[] val = new MIXERCONTROLDETAILS_UNSIGNED[details.item];
					for(int m=0; m<details.item; m++)
					{
						IntPtr ptr = new IntPtr(details.paDetails.ToInt32() + m*details.cbDetails);
						val[m] = new MIXERCONTROLDETAILS_UNSIGNED();
						val[m] = (MIXERCONTROLDETAILS_UNSIGNED)Marshal.PtrToStructure(ptr, typeof(MIXERCONTROLDETAILS_UNSIGNED));
						if(val[m].dwValue == 1)
						{
							retval = m;
							m = details.item;
						}
					}
				}
			}
			mixerClose(mixer);
			return retval;
		}
Esempio n. 44
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
        }
Esempio n. 45
0
		public static bool SetMux(int mixerID, int index)
		{
			int mixer;
			int retval = -1;
			MIXERCONTROL ctrl = new MIXERCONTROL();

			mixerOpen(out mixer, mixerID, 0, 0, 0);
			GetControlByType(mixer,MIXERLINE_COMPONENTTYPE_DST_WAVEIN, 0, MIXERCONTROL_CONTROLTYPE_MUX, out ctrl);

			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)
			{
				int[] val = new int[details.item];
				for(int m=0; m<details.item; m++)
				{
					if(m == 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)
				return true;
			else return false;
		}
Esempio n. 46
0
        public static void SetVolume( int control, int component, int newVol )                              // SetVolume
        {
            int hmixer = 0;
            int currentVol;

            MIXERCONTROL volCtrl = new MIXERCONTROL();

            mixerOpen(
                    out hmixer,
                    0,
                    0,
                    0,
                    0);

            GetMixerControl(
                        hmixer,
                        component,
                        control,
                        out volCtrl,
                        out currentVol);            // Not used

            SetVolumeControl(hmixer, volCtrl, newVol);

            mixerClose(hmixer);
        }
Esempio n. 47
0
		public static bool InitSantaCruz(int mixerID)
		{
			int mixer;
			int retval = -1;
			retval = mixerOpen(out mixer, mixerID, 0, 0, 0);
			if(retval != MMSYSERR_NOERROR)
				return false;

			// Set Playback Wave Volume to max
			MIXERCONTROL ctrl = new MIXERCONTROL();
			bool success = GetControlByID(mixer, 0, 0, MIXERCONTROL_CONTROLTYPE_VOLUME, out ctrl);
			if(!success)
				goto failed;
			if(!SetUnsigned(mixer, ctrl, ctrl.lMaximum))
				goto failed;

			// Set Playback Wave Mute to off
			success = GetControlByID(mixer, 0, 0, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, false))
				goto failed;

			// Set Playback Synthesizer Mute to on
			success = GetControlByID(mixer, 0, 1, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// Set Playback Aux Mute to on
			success = GetControlByID(mixer, 0, 2, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// Set Playback CD Player Mute to on
			success = GetControlByID(mixer, 0, 3, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// Set Playback Line In Mute to on
			success = GetControlByID(mixer, 0, 4, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// Set Playback Synth Daughter Card Mute to on
			success = GetControlByID(mixer, 0, 5, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// Set Playback Microphone Mute to on
			success = GetControlByID(mixer, 0, 6, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// Set Playback Telephone Mute to on
			success = GetControlByID(mixer, 0, 7, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// Set 5.1 Emulation Mute to on
			success = GetControlByID(mixer, 2, 3, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// Disable equalizer
			success = GetControlByID(mixer, 3, -1, MIXERCONTROL_CONTROLTYPE_ONOFF, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, false))
				goto failed;

			// Disable effects 1 channel
			success = GetControlByID(mixer, 6, -1, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// Disable effects 2 channel
			success = GetControlByID(mixer, 7, -1, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			mixerClose(mixer);
			return true;
			
			failed:
				mixerClose(mixer);
			return false;
		}
Esempio n. 48
0
        internal static MixerControl[] GetControls(Mixer mx, MixerLine line, int controlCount)
        {
            if (controlCount == 0) return new MixerControl[0];
            MIXERCONTROL[] mc = new MIXERCONTROL[controlCount];
            int mxsize = Marshal.SizeOf(mc[0]);
            if (mxsize != 148) throw new Exception("" + mxsize);
            //mxsize = 148;

            MIXERLINECONTROLS mlc = new MIXERLINECONTROLS();
            mlc.cbStruct = Marshal.SizeOf(mlc);
            mlc.cControls = controlCount;
            mlc.dwLineID = line.Id;

            mlc.pamxctrl = Marshal.AllocCoTaskMem(mxsize * controlCount);
            mlc.cbmxctrl = mxsize;

            int err;
            if ((err = mixerGetLineControlsA(mx.Handle, ref mlc, MIXER_GETLINECONTROLSF_ALL)) != 0)
            {
                throw new Win32Exception("Error #" + err + " calling mixerGetLineControls()\n");
            }
            for (int i = 0; i < controlCount; i++)
            {
                mc[i] = (MIXERCONTROL)Marshal.PtrToStructure(new IntPtr(mlc.pamxctrl.ToInt64() + mxsize * i), typeof(MIXERCONTROL));
            }
            Marshal.FreeCoTaskMem(mlc.pamxctrl);
            MixerControl[] result = new MixerControl[controlCount];
            for (int i = 0; i < controlCount; i++)
            {
                result[i] = GetControl(mx, line, mc[i]);
            }
            return result;
        }
Esempio n. 49
0
		public static bool InitAudigy2(int mixerID)
		{
			int mixer;
			int retval = -1;
			retval = mixerOpen(out mixer, mixerID, 0, 0, 0);
			if(retval != MMSYSERR_NOERROR)
				return false;

			// turn Monitor Without Recording on
			MIXERCONTROL ctrl = new MIXERCONTROL();
			bool success = GetControlByID(mixer, 1, 4, MIXERCONTROL_CONTROLTYPE_ONOFF, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// turn Playback Wave Mute off
			success = GetControlByID(mixer, 0, 0, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, false))
				goto failed;

			// turn Playback Midi Synth Mute on
			success = GetControlByID(mixer, 0, 1, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// turn Playback S/PDIF-In Mute on
			success = GetControlByID(mixer, 0, 2, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// turn Playback CD Digital Mute on
			success = GetControlByID(mixer, 0, 3, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// turn Playback Auxiliary Mute on
			success = GetControlByID(mixer, 0, 4, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// turn Playback CD Audio Mute on
			success = GetControlByID(mixer, 0, 5, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// turn Playback Line In Mute off
			success = GetControlByID(mixer, 0, 6, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, false))
				goto failed;

			// turn Playback TAD-In Mute on
			success = GetControlByID(mixer, 0, 7, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// turn Playback Microphone Mute on
			success = GetControlByID(mixer, 0, 8, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// turn Main Mute off
			success = GetControlByID(mixer, 0, -1, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, false))
				goto failed;

			// turn Playback Wave Volume to Max
			success = GetControlByID(mixer, 0, 0, MIXERCONTROL_CONTROLTYPE_VOLUME, out ctrl);
			if(!success)
				goto failed;
			if(!SetUnsigned(mixer, ctrl, ctrl.lMaximum))
				goto failed;

			mixerClose(mixer);
			return true;

			failed:
				mixerClose(mixer);
			return false;
		}
Esempio n. 50
0
 internal MixerControl(Mixer mx, MixerLine ml, MIXERCONTROL ctrl)
 {
     this.mx = mx;
     this.ml = ml;
     this.ctrl = ctrl;
 }
Esempio n. 51
0
		public static bool InitMP3Plus(int mixerID)
		{
			int mixer;
			int retval = -1;
			retval = mixerOpen(out mixer, mixerID, 0, 0, 0);
			if(retval != MMSYSERR_NOERROR)
				return false;

			// turn Playback Wave Volume to max
			MIXERCONTROL ctrl = new MIXERCONTROL();
			bool success = GetControlByID(mixer, 0, 0, MIXERCONTROL_CONTROLTYPE_VOLUME, out ctrl);
			if(!success)
				goto failed;
			if(!SetUnsigned(mixer, ctrl, ctrl.lMaximum))
				goto failed;

			// turn Playback Wave Mute off
			success = GetControlByID(mixer, 0, 0, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, false))
				goto failed;

			// turn Playback Midi Mute on
			success = GetControlByID(mixer, 0, 1, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// turn Playback Microphone Mute on
			success = GetControlByID(mixer, 0, 2, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// turn Playback Line In Mute on
			success = GetControlByID(mixer, 0, 3, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			// turn Playback CD Audio Mute on
			success = GetControlByID(mixer, 0, 4, MIXERCONTROL_CONTROLTYPE_MUTE, out ctrl);
			if(!success)
				goto failed;
			if(!SetBool(mixer, ctrl, true))
				goto failed;

			mixerClose(mixer);
			return true;
			
			failed:
				mixerClose(mixer);
			return false;
		}
Esempio n. 52
0
    private static bool SetVolumeControl(int hmixer, MIXERCONTROL mxc, int volume)
    {
      // This function sets the value for a volume control. 
      // Returns True if successful 

      bool retValue;
      int rc;
      MIXERCONTROLDETAILS mxcd = new MIXERCONTROLDETAILS();
      MIXERCONTROLDETAILS_UNSIGNED vol = new MIXERCONTROLDETAILS_UNSIGNED();

      mxcd.item = 0;
      mxcd.dwControlID = mxc.dwControlID;
      mxcd.cbStruct = Marshal.SizeOf(mxcd);
      mxcd.cbDetails = Marshal.SizeOf(vol);

      // Allocate a buffer for the control value buffer 
      mxcd.cChannels = 1;
      vol.dwValue = volume;

      // Copy the data into the control value buffer 
      mxcd.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof (MIXERCONTROLDETAILS_UNSIGNED)));
      Marshal.StructureToPtr(vol, mxcd.paDetails, false);

      // Set the control value 
      rc = mixerSetControlDetails(hmixer, ref mxcd, MIXER_SETCONTROLDETAILSF_VALUE);

      if (MMSYSERR_NOERROR == rc)
      {
        retValue = true;
      }
      else
      {
        retValue = false;
      }
      return retValue;
    }
Esempio n. 53
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;
			}
		}
Esempio n. 54
0
 public static void SetVolume(int vVolume)
 {
   int mixer;
   MIXERCONTROL volCtrl = new MIXERCONTROL();
   int currentVol;
   mixerOpen(out mixer, 0, 0, 0, 0);
   int type = MIXERCONTROL_CONTROLTYPE_VOLUME;
   GetVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out currentVol);
   if (vVolume > volCtrl.lMaximum) vVolume = volCtrl.lMaximum;
   if (vVolume < volCtrl.lMinimum) vVolume = volCtrl.lMinimum;
   SetVolumeControl(mixer, volCtrl, vVolume);
   GetVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, out volCtrl, out currentVol);
   if (vVolume != currentVol)
   {
     throw new Exception("Cannot Set Volume");
   }
   mixerClose(mixer);
 }
Esempio n. 55
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));
        }