Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: vb.net code for volume control

  1. #1
    Constant Bitrate takissd's Avatar
    Join Date
    May 2004
    Location
    San Diego, CA
    Posts
    118

    vb.net code for volume control

    hello vb.net coders.. i've been trying to control volume thru vb.net and i cannot see how to do that. I searched but all i could find was vb6 code. i know several of you are working with vb.net... is there any sample source code they can send me or post here for others to be able to use? thanx
    -VIA EPIA M10000/512MB/40GB HD
    -DWW motorized 7'
    -BU 303 GPS w/iGuidance/ CF
    -Opus90w
    -Belkin Bluetooth
    -Pioneer HU

    [||||||||||] 95% done

  2. #2
    FLAC SFiorito's Avatar
    Join Date
    May 2004
    Posts
    1,364
    i've got it at home... (at work right now). it's pretty straight forward. i'll post it tonight (around 6PM EST).

  3. #3
    Constant Bitrate takissd's Avatar
    Join Date
    May 2004
    Location
    San Diego, CA
    Posts
    118
    thnx
    -VIA EPIA M10000/512MB/40GB HD
    -DWW motorized 7'
    -BU 303 GPS w/iGuidance/ CF
    -Opus90w
    -Belkin Bluetooth
    -Pioneer HU

    [||||||||||] 95% done

  4. #4
    FLAC SFiorito's Avatar
    Join Date
    May 2004
    Posts
    1,364
    okay, the one i use is in c#. can't remember where I found it online since it took a **** load of googling. i didn't feel like writing all the marshalling stuff myself, but this is the best one i found. shouldn't be hard to convert it to Vb.net.

    Code:
    using System; 
    using System.Runtime.InteropServices; 
    
    namespace PhidgetTest
    {
    	public class AudioMixerHelper 
    	{ 
    		public const int MMSYSERR_NOERROR = 0; 
    		public const int MAXPNAMELEN = 32; 
    		public const int MIXER_LONG_NAME_CHARS = 64; 
    		public const int MIXER_SHORT_NAME_CHARS = 16; 
    		public const int MIXER_GETLINEINFOF_COMPONENTTYPE = 0x3; 
    		public const int MIXER_GETCONTROLDETAILSF_VALUE = 0x0; 
    		public const int MIXER_GETLINECONTROLSF_ONEBYTYPE = 0x2; 
    		public const int MIXER_SETCONTROLDETAILSF_VALUE = 0x0; 
    		public const int MIXERLINE_COMPONENTTYPE_DST_FIRST = 0x0; 
    		public const int MIXERLINE_COMPONENTTYPE_SRC_FIRST = 0x1000; 
    		public const int MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = 
    			(MIXERLINE_COMPONENTTYPE_DST_FIRST + 4); 
    		public const int MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = 
    			(MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3); 
    		public const int MIXERLINE_COMPONENTTYPE_SRC_LINE = 
    			(MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2); 
    		public const int MIXERCONTROL_CT_CLASS_FADER = 0x50000000; 
    		public const int MIXERCONTROL_CT_UNITS_UNSIGNED = 0x30000; 
    		public const int MIXERCONTROL_CONTROLTYPE_FADER = 
    			(MIXERCONTROL_CT_CLASS_FADER | MIXERCONTROL_CT_UNITS_UNSIGNED); 
    		public const int MIXERCONTROL_CONTROLTYPE_VOLUME = 
    			(MIXERCONTROL_CONTROLTYPE_FADER + 1); 
    
    		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
    		private static extern int mixerClose (int hmx); 
    		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
    		private static extern int mixerGetControlDetailsA (int hmxobj,ref 
    			MIXERCONTROLDETAILS pmxcd , int fdwDetails); 
    		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
    		private static extern int mixerGetDevCapsA(int uMxId, MIXERCAPS 
    			pmxcaps, int cbmxcaps); 
    		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
    		private static extern int mixerGetID (int hmxobj, int pumxID, int 
    			fdwId); 
    		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
    		private static extern int mixerGetLineControlsA (int hmxobj,ref 
    			MIXERLINECONTROLS pmxlc, int fdwControls); 
    		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
    		private static extern int mixerGetLineInfoA (int hmxobj,ref 
    			MIXERLINE pmxl , int fdwInfo); 
    		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
    		private static extern int mixerGetNumDevs(); 
    		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
    		private static extern int mixerMessage(int hmx , int uMsg , int 
    			dwParam1 , int dwParam2); 
    		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
    		private static extern int mixerOpen (out int phmx , int uMxId , 
    			int dwCallback , int dwInstance , int fdwOpen); 
    		[DllImport("winmm.dll", CharSet=CharSet.Ansi)] 
    		private static extern int mixerSetControlDetails(int hmxobj ,ref 
    			MIXERCONTROLDETAILS pmxcd , int fdwDetails); 
    
    		public struct MIXERCAPS 
    		{ 
    			public int wMid; 
    			public int wPid; 
    			public int vDriverVersion; 
    			[MarshalAs(UnmanagedType.ByValTStr, SizeConst=MAXPNAMELEN)] 
    			public string szPname; 
    			public int fdwSupport; 
    			public int cDestinations; 
    		} 
    
    		public struct MIXERCONTROL 
    		{ 
    			public int cbStruct; 
    			public int dwControlID; 
    			public int dwControlType; 
    			public int fdwControl; 
    			public int cMultipleItems; 
    			[MarshalAs( UnmanagedType.ByValTStr, 
    				 SizeConst=MIXER_SHORT_NAME_CHARS)] 
    			public string szShortName ; 
    			[MarshalAs( UnmanagedType.ByValTStr, 
    				 SizeConst=MIXER_LONG_NAME_CHARS)] 
    			public string szName; 
    			public int lMinimum; 
    			public int lMaximum; 
    			[MarshalAs(UnmanagedType.U4, SizeConst=10)] 
    			public int reserved; 
    		} 
    
    		public struct MIXERCONTROLDETAILS 
    		{ 
    			public int cbStruct; 
    			public int dwControlID; 
    			public int cChannels; 
    			public int item; 
    			public int cbDetails; 
    			public IntPtr paDetails; 
    		} 
    
    		public struct MIXERCONTROLDETAILS_UNSIGNED 
    		{ 
    			public int dwValue; 
    		} 
    
    		public struct MIXERLINE 
    		{ 
    			public int cbStruct; 
    			public int dwDestination; 
    			public int dwSource; 
    			public int dwLineID; 
    			public int fdwLine; 
    			public int dwUser; 
    			public int dwComponentType; 
    			public int cChannels; 
    			public int cConnections; 
    			public int cControls; 
    			[MarshalAs(UnmanagedType.ByValTStr, 
    				 SizeConst=MIXER_SHORT_NAME_CHARS)] 
    			public string szShortName; 
    			[MarshalAs(UnmanagedType.ByValTStr, 
    				 SizeConst=MIXER_LONG_NAME_CHARS )] 
    			public string szName; 
    			public int dwType; 
    			public int dwDeviceID; 
    			public int wMid; 
    			public int wPid; 
    			public int vDriverVersion ; 
    			[MarshalAs(UnmanagedType.ByValTStr, SizeConst=MAXPNAMELEN)] 
    			public string szPname ; 
    		} 
    
    		public struct MIXERLINECONTROLS 
    		{ 
    			public int cbStruct; 
    			public int dwLineID; 
    
    			public int dwControl; 
    			public int cControls; 
    			public int cbmxctrl; 
    			public IntPtr pamxctrl; 
    		} 
    
    		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; 
    		} 
    
    		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; 
    		} 
    
    		public 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); 
    
    			return currentVol; 
    		} 
    
    		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); 
    		} 
    	} 
    }

  5. #5
    Constant Bitrate
    Join Date
    Apr 2004
    Posts
    154
    Here is a neat site that translates c# into VB. Its not 100% but its makes it a lot easier... http://authors.aspalliance.com/aldot...translate.aspx

  6. #6
    FLAC IntellaWorks's Avatar
    Join Date
    Jun 2004
    Location
    NH
    Posts
    1,173

    .

    This is great I was just going to ask the same damn question... I was actually think about using directX 8.0 for mixer controls..
    Progress [I will seriously never be done!]
    Via EPIA MII
    512MB RAM
    OEM GPS (embedded)
    nLite WinXP pro on
    1GB Extreme III CF card
    Carnetix 1260 startup/ DC-DC regulator
    Software: Still, re-Writing my existing front end in .Net

  7. #7
    FLAC IntellaWorks's Avatar
    Join Date
    Jun 2004
    Location
    NH
    Posts
    1,173

    bah

    This definalty is tough to impliment into VB.net
    Progress [I will seriously never be done!]
    Via EPIA MII
    512MB RAM
    OEM GPS (embedded)
    nLite WinXP pro on
    1GB Extreme III CF card
    Carnetix 1260 startup/ DC-DC regulator
    Software: Still, re-Writing my existing front end in .Net

  8. #8
    FLAC SFiorito's Avatar
    Join Date
    May 2004
    Posts
    1,364
    I used that C#->VB.NET translator, but had to make a few corrections:

    Code:
    Imports System
    Imports System.Runtime.InteropServices
    
    Public Class AudioMixerHelper
        Public Const MMSYSERR_NOERROR As Integer = 0
        Public Const MAXPNAMELEN As Integer = 32
        Public Const MIXER_LONG_NAME_CHARS As Integer = 64
        Public Const MIXER_SHORT_NAME_CHARS As Integer = 16
        Public Const MIXER_GETLINEINFOF_COMPONENTTYPE As Integer = &H3
        Public Const MIXER_GETCONTROLDETAILSF_VALUE As Integer = &H0
        Public Const MIXER_GETLINECONTROLSF_ONEBYTYPE As Integer = &H2
        Public Const MIXER_SETCONTROLDETAILSF_VALUE As Integer = &H0
        Public Const MIXERLINE_COMPONENTTYPE_DST_FIRST As Integer = &H0
        Public Const MIXERLINE_COMPONENTTYPE_SRC_FIRST As Integer = &H1000
        Public Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS As Integer = MIXERLINE_COMPONENTTYPE_DST_FIRST + 4
        Public Const MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE As Integer = MIXERLINE_COMPONENTTYPE_SRC_FIRST + 3
        Public Const MIXERLINE_COMPONENTTYPE_SRC_LINE As Integer = MIXERLINE_COMPONENTTYPE_SRC_FIRST + 2
        Public Const MIXERCONTROL_CT_CLASS_FADER As Integer = &H50000000
        Public Const MIXERCONTROL_CT_UNITS_UNSIGNED As Integer = &H30000
        Public Const MIXERCONTROL_CONTROLTYPE_FADER As Integer = MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED
        Public Const MIXERCONTROL_CONTROLTYPE_VOLUME As Integer = MIXERCONTROL_CONTROLTYPE_FADER + 1
    
        Private Declare Ansi Function mixerClose Lib "winmm.dll" (ByVal hmx As Integer) As Integer
    
        Private Declare Ansi Function mixerGetControlDetailsA Lib "winmm.dll" (ByVal hmxobj As Integer, ByRef pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Integer) As Integer
    
        Private Declare Ansi Function mixerGetDevCapsA Lib "winmm.dll" (ByVal uMxId As Integer, ByVal pmxcaps As MIXERCAPS, ByVal cbmxcaps As Integer) As Integer
    
        Private Declare Ansi Function mixerGetID Lib "winmm.dll" (ByVal hmxobj As Integer, ByVal pumxID As Integer, ByVal fdwId As Integer) As Integer
    
        Private Declare Ansi Function mixerGetLineControlsA Lib "winmm.dll" (ByVal hmxobj As Integer, ByRef pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Integer) As Integer
    
        Private Declare Ansi Function mixerGetLineInfoA Lib "winmm.dll" (ByVal hmxobj As Integer, ByRef pmxl As MIXERLINE, ByVal fdwInfo As Integer) As Integer
    
        Private Declare Ansi Function mixerGetNumDevs Lib "winmm.dll" () As Integer
    
        Private Declare Ansi Function mixerMessage Lib "winmm.dll" (ByVal hmx As Integer, ByVal uMsg As Integer, ByVal dwParam1 As Integer, ByVal dwParam2 As Integer) As Integer
    
        Private Declare Ansi Function mixerOpen Lib "winmm.dll" (ByRef phmx As Integer, ByVal uMxId As Integer, ByVal dwCallback As Integer, ByVal dwInstance As Integer, ByVal fdwOpen As Integer) As Integer
    
        Private Declare Ansi Function mixerSetControlDetails Lib "winmm.dll" (ByVal hmxobj As Integer, ByRef pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Integer) As Integer
    
        Public Structure MIXERCAPS
            Public wMid As Integer
            Public wPid As Integer
            Public vDriverVersion As Integer
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> Public szPname As String
            Public fdwSupport As Integer
            Public cDestinations As Integer
        End Structure 'MIXERCAPS
           _
    
        Public Structure MIXERCONTROL
            Public cbStruct As Integer
            Public dwControlID As Integer
            Public dwControlType As Integer
            Public fdwControl As Integer
            Public cMultipleItems As Integer
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String
            Public lMinimum As Integer
            Public lMaximum As Integer
            <MarshalAs(UnmanagedType.U4, SizeConst:=10)> Public reserved As Integer
        End Structure 'MIXERCONTROL
           _
    
        Public Structure MIXERCONTROLDETAILS
            Public cbStruct As Integer
            Public dwControlID As Integer
            Public cChannels As Integer
            Public item As Integer
            Public cbDetails As Integer
            Public paDetails As IntPtr
        End Structure 'MIXERCONTROLDETAILS
           _
    
        Public Structure MIXERCONTROLDETAILS_UNSIGNED
            Public dwValue As Integer
        End Structure 'MIXERCONTROLDETAILS_UNSIGNED
           _
    
        Public Structure MIXERLINE
            Public cbStruct As Integer
            Public dwDestination As Integer
            Public dwSource As Integer
            Public dwLineID As Integer
            Public fdwLine As Integer
            Public dwUser As Integer
            Public dwComponentType As Integer
            Public cChannels As Integer
            Public cConnections As Integer
            Public cControls As Integer
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String
            Public dwType As Integer
            Public dwDeviceID As Integer
            Public wMid As Integer
            Public wPid As Integer
            Public vDriverVersion As Integer
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> Public szPname As String
        End Structure 'MIXERLINE
           _
    
        Public Structure MIXERLINECONTROLS
            Public cbStruct As Integer
            Public dwLineID As Integer
    
            Public dwControl As Integer
            Public cControls As Integer
            Public cbmxctrl As Integer
            Public pamxctrl As IntPtr
        End Structure 'MIXERLINECONTROLS
    
    
        Private Shared Function GetVolumeControl(ByVal hmixer As Integer, ByVal componentType As Integer, ByVal ctrlType As Integer, ByRef mxc As MIXERCONTROL, ByRef vCurrentVol As Integer) As Boolean
            ' This function attempts to obtain a mixer control. 
            ' Returns True if successful. 
            Dim mxlc As New MIXERLINECONTROLS
            Dim mxl As New MIXERLINE
            Dim pmxcd As New MIXERCONTROLDETAILS
            Dim du As New MIXERCONTROLDETAILS_UNSIGNED
            mxc = New MIXERCONTROL
            Dim rc As Integer
            Dim retValue As Boolean
            vCurrentVol = -1
    
            mxl.cbStruct = Marshal.SizeOf(mxl)
            mxl.dwComponentType = componentType
    
            rc = mixerGetLineInfoA(hmixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)
    
            If MMSYSERR_NOERROR = rc Then
                Dim sizeofMIXERCONTROL As Integer = 152
                Dim ctrl As Integer = Marshal.SizeOf(GetType(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, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
    
                If MMSYSERR_NOERROR = rc Then
                    retValue = True
    
                    ' Copy the control into the destination structure 
                    mxc = CType(Marshal.PtrToStructure(mxlc.pamxctrl, GetType(MIXERCONTROL)), MIXERCONTROL)
                Else
                    retValue = False
                End If
                Dim sizeofMIXERCONTROLDETAILS As Integer = Marshal.SizeOf(GetType(MIXERCONTROLDETAILS))
                Dim sizeofMIXERCONTROLDETAILS_UNSIGNED As Integer = Marshal.SizeOf(GetType(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, pmxcd, MIXER_GETCONTROLDETAILSF_VALUE)
    
                du = Marshal.PtrToStructure(pmxcd.paDetails, GetType(MIXERCONTROLDETAILS_UNSIGNED))
    
                vCurrentVol = du.dwValue
    
                Return retValue
            End If
    
            retValue = False
            Return retValue
        End Function 'GetVolumeControl
    
    
        Private Shared Function SetVolumeControl(ByVal hmixer As Integer, ByVal mxc As MIXERCONTROL, ByVal volume As Integer) As Boolean
            ' This function sets the value for a volume control. 
            ' Returns True if successful 
            Dim retValue As Boolean
            Dim rc As Integer
            Dim mxcd As New MIXERCONTROLDETAILS
            Dim vol As 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(GetType(MIXERCONTROLDETAILS_UNSIGNED)))
            Marshal.StructureToPtr(vol, mxcd.paDetails, False)
    
            ' Set the control value 
            rc = mixerSetControlDetails(hmixer, mxcd, MIXER_SETCONTROLDETAILSF_VALUE)
    
            If MMSYSERR_NOERROR = rc Then
                retValue = True
            Else
                retValue = False
            End If
            Return retValue
        End Function 'SetVolumeControl

  9. #9
    FLAC SFiorito's Avatar
    Join Date
    May 2004
    Posts
    1,364
    continued because forums complained text was too long...

    Code:
        Public Shared Function GetVolume() As Integer
            Dim mixer As Integer
            Dim volCtrl As New MIXERCONTROL
            Dim currentVol As Integer
            mixerOpen(mixer, 0, 0, 0, 0)
            Dim type As Integer = MIXERCONTROL_CONTROLTYPE_VOLUME
            GetVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, volCtrl, currentVol)
            mixerClose(mixer)
    
            Return currentVol
        End Function 'GetVolume
    
    
        Public Shared Sub SetVolume(ByVal vVolume As Integer)
            Dim mixer As Integer
            Dim volCtrl As New MIXERCONTROL
            Dim currentVol As Integer
            mixerOpen(mixer, 0, 0, 0, 0)
            Dim type As Integer = MIXERCONTROL_CONTROLTYPE_VOLUME
            GetVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, volCtrl, currentVol)
            If vVolume > volCtrl.lMaximum Then
                vVolume = volCtrl.lMaximum
            End If
            If vVolume < volCtrl.lMinimum Then
                vVolume = volCtrl.lMinimum
            End If
            SetVolumeControl(mixer, volCtrl, vVolume)
            GetVolumeControl(mixer, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, type, volCtrl, currentVol)
            If vVolume <> currentVol Then
                Throw New Exception("Cannot Set Volume")
            End If
            mixerClose(mixer)
        End Sub 'SetVolume
    End Class 'AudioMixerHelper

  10. #10
    Newbie
    Join Date
    Dec 2004
    Posts
    18
    Sorry, but me English is not very good....

    I want to make a program to set the balance control to center always. Could I have it with this code?

    Somebody has compiled it?
    Thank you.

    Greetings....

Page 1 of 2 12 LastLast

Similar Threads

  1. GPS/MapPoint VB Source Code
    By stevieg in forum Software & Software Development
    Replies: 7
    Last Post: 01-28-2011, 04:59 PM
  2. AC97 Control Panel Switcher Program (could be useful for many)
    By Vinister in forum Software & Software Development
    Replies: 0
    Last Post: 02-02-2005, 04:50 PM
  3. Replies: 3
    Last Post: 05-26-2004, 05:08 AM
  4. Writting code in VB to control a LCD?
    By Dr.Sparkle in forum Software & Software Development
    Replies: 24
    Last Post: 10-07-2001, 02:45 PM
  5. Replies: 22
    Last Post: 08-13-2001, 02:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •