控制左右声道

'Code By 魑魅魍魉
'mailto:[email protected]

Private Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long
Private Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long
Const WAVE_MAPPER = -1&

Public Function SetLR(ByVal L As Long, ByVal R As Long) As Long
Dim mLR As String
mLR = "&H" & Right("0000" & Hex(L), 4) & Right("0000" & Hex(R), 4)
waveOutSetVolume WAVE_MAPPER, CLng(mLR)
End Function


Public Function GetLR(ByRef L As Long, ByRef R As Long) As Long
Dim LR As Long
waveOutGetVolume WAVE_MAPPER, LR
L = CLng("&H" & Left(Hex(LR), 4))
R = CLng("&H" & Right(Hex(LR), 4))
End Function

以上2个自定义的函数可以方便的取得和设置左右声道。

如:

Private Sub Form_Load()
Dim mL As Long, mR As Long
GetLR mL, mR
MsgBox "左" & mL & "--右" & mR
End Sub

Private Sub Command1_Click()
SetLR 65535, 22222
End Sub

可以用一个Slider来进行细致的控制。

原理:

waveOutGetVolume取得的音量值转换成16进制,高位是左声道的值,低位是右声道的值。

 

你可能感兴趣的:(源码)