OVH Cloud OVH Cloud

Plusieurs cartes audio...

1 réponse
Avatar
michel.montias
Bonjour =E0 tous...

VB6.
je d=E9sire envoyer un son Wav sur 1 carte audio, et un=20
autre sur une 2=E8me carte audio, simultan=E9ment.
Quel OCX existant peut faire ceci, ou quel programme peut=20
le g=E9rer.

Merci

1 réponse

Avatar
François Picalausa
Bonjour/soir,

Tu peux essayer par MCI comme ceci (le code est probablement optimisable):

'Form, name = Form1
'Combobox, style = 2 - dropdownlist, name = Combo1
'Combobox, style = 2 - dropdownlist, name = Combo2
'CommandButton, name = Command1

Option Explicit

Private Const MAXPNAMELEN = 32 ' max product name length (including NULL)
Private Const MMSYSERR_NOERROR = 0 ' no error
Private Const MIXER_OBJECTF_MIXER = &H0&
Private Const MCI_OPEN_TYPE = &H2000&
Private Const MCI_OPEN_ELEMENT = &H200&
Private Const MCI_PLAY = &H806
Private Const MCI_OPEN = &H803
Private Const MCI_SET = &H80D
Private Const MCI_CLOSE = &H804
Private Const MCI_WAVE_OUTPUT = &H800000
Private Const MCI_WAIT = &H2&
Private Const MCI_SEEK_TO_START = &H100&
Private Const MCI_SEEK = &H807

Private Type MCI_GENERIC_PARMS
dwCallback As Long
End Type

Private Type MCI_PLAY_PARMS
dwCallback As Long
dwFrom As Long
dwTo As Long
End Type

Private Type WAVEOUTCAPS
wMid As Integer
wPid As Integer
vDriverVersion As Long
szPname As String * MAXPNAMELEN
dwFormats As Long
wChannels As Integer
dwSupport As Long
End Type

Private Type MCI_OPEN_PARMS
dwCallback As Long
wDeviceID As Long
lpstrDeviceType As String
lpstrElementName As String
lpstrAlias As String
End Type
Private Type MCI_WAVE_SET_PARMS
dwCallback As Long
dwTimeFormat As Long
dwAudio As Long
wInput As Long
wOutput As Long
wFormatTag As Integer
wReserved2 As Integer
nChannels As Integer
wReserved3 As Integer
nSamplesPerSec As Long
nAvgBytesPerSec As Long
nBlockAlign As Integer
wReserved4 As Integer
wBitsPerSample As Integer
wReserved5 As Integer
End Type

Private Type MCI_SEEK_PARMS
dwCallback As Long
dwTo As Long
End Type

Private Declare Function waveOutGetDevCaps Lib "winmm.dll" Alias
"waveOutGetDevCapsA" (ByVal uDeviceID As Long, lpCaps As WAVEOUTCAPS, ByVal
uSize As Long) As Long
Private Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Long
Private Declare Function mixerGetID Lib "winmm.dll" (ByVal hmxobj As Long,
pumxID As Long, ByVal fdwId As Long) As Long
Private Declare Function mciSendCommand Lib "winmm.dll" Alias
"mciSendCommandA" (ByVal wDeviceID As Long, ByVal uMessage As Long, ByVal
dwParam1 As Long, dwParam2 As Any) As Long

Private mciDevice1 As Long
Private mciDevice2 As Long
Private bIsInit As Boolean

Private Sub Command1_Click()
Dim PlayParms As MCI_PLAY_PARMS
Dim SeekParms As MCI_SEEK_PARMS

If bIsInit Then
mciSendCommand mciDevice1, MCI_SEEK, MCI_SEEK_TO_START, SeekParms
mciSendCommand mciDevice2, MCI_SEEK, MCI_SEEK_TO_START, SeekParms
mciSendCommand mciDevice1, MCI_PLAY Or MCI_WAIT, 0, PlayParms
mciSendCommand mciDevice2, MCI_PLAY Or MCI_WAIT, 0, PlayParms
End If
End Sub

Private Sub Form_Load()
Dim i As Long, woc As WAVEOUTCAPS

For i = 0 To waveOutGetNumDevs - 1
If waveOutGetDevCaps(i, woc, Len(woc)) = MMSYSERR_NOERROR Then
'Permet de sélectionner les cartes son
Combo1.AddItem TrimNullChars(woc.szPname)
Combo2.AddItem TrimNullChars(woc.szPname)
Combo1.ItemData(Combo2.NewIndex) = i
Combo2.ItemData(Combo2.NewIndex) = i
End If
Next i

If Combo1.ListCount > 0 Then
Combo1.ListIndex = 0
Combo2.ListIndex = 0
End If

'Ouverture des devices MCI
Dim OpenParms As MCI_OPEN_PARMS
Dim SetParms As MCI_WAVE_SET_PARMS

OpenParms.lpstrDeviceType = "waveaudio"
OpenParms.lpstrElementName = "c:windowsmediading.wav"

If mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_ELEMENT,
OpenParms) = 0 Then
mciDevice1 = OpenParms.wDeviceID

OpenParms.lpstrElementName = "c:windowsmediatada.wav"

If mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_ELEMENT,
OpenParms) = 0 Then
mciDevice2 = OpenParms.wDeviceID

SetParms.wOutput = Combo1.ItemData(Combo1.ListIndex)

If mciSendCommand(mciDevice1, MCI_SET, MCI_WAVE_OUTPUT,
SetParms) = 0 Then

SetParms.wOutput = Combo2.ItemData(Combo2.ListIndex)

If mciSendCommand(mciDevice2, MCI_SET, MCI_WAVE_OUTPUT,
SetParms) = 0 Then
bIsInit = True
End If
End If
End If
End If
End Sub

Private Function TrimNullChars(strText As String) As String
Dim lngNullPos As Long

lngNullPos = InStr(1, strText, vbNullChar)
If lngNullPos > 0 Then
TrimNullChars = Left$(strText, lngNullPos - 1)
Else
TrimNullChars = strText
End If
End Function

Private Sub Form_Unload(Cancel As Integer)
Dim CloseParms As MCI_GENERIC_PARMS

If mciDevice2 <> 0 Then
mciSendCommand mciDevice2, MCI_CLOSE, 0, CloseParms
End If

If mciDevice1 <> 0 Then
mciSendCommand mciDevice1, MCI_CLOSE, 0, CloseParms
End If
End Sub

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"michel.montias" a écrit dans le message de
news:058201c35ff7$233da830$
Bonjour à tous...

VB6.
je désire envoyer un son Wav sur 1 carte audio, et un
autre sur une 2ème carte audio, simultanément.
Quel OCX existant peut faire ceci, ou quel programme peut
le gérer.

Merci