Hi,
I've been getting some very odd results with DirectPlayVoice. When use
the Simple Voice sample program to create a new game, everything works
fine. My quick test is to make some noise near the mic and observer the
volume control slider moving as the automatic gain control kicks in -
this confirms that the audio is working.
But I haven't been able to make the same functionality work in the
fairly large app that this is part of. I even went so far as to copy and
paste a subset of the demo code - worked fine in a standalone, but not
in the large app. My first thought was that this had something to do
with memory boundaries, but now I'm not so sure because ...
In the process of "professionalizing" the standalone, I did something
to it that caused it to not work there either. Arrgh. Far too many hours
later ...
1. Peer hosting seems to work okay (generates a good CreatePlayer
event.)
2. StartVoiceServer seems to be okay, but doesn't raise any events.
Should it?
3. StartVoiceClient goes through the motions, gets
DirectPlayVoiceEvent8_ConnectResult of 0 and a CreateVoicePlayer event.
But according to the "slider motion test" the app doesn't seem to hear
the microphone. The audio wizard (CheckAudioSetup) runs okay and hears
the mic okay. SimpleVoice still runs okay.
Things that don't make any difference:
- Restarting VB
- Rebooting
- Making MaxPlayers = 10 instead of 0 (no limit)
This code is in a class module whose lifetime is the lifetime of the
app. (Yes, I checked with breakpoints to make sure the object wasn't
accidentally being destroyed and re-created.) On the theory that being
in a class module might have something to do with it, I tried making the
Peer object a module-level one on the calling form and passing it into
the routines (ByRef of course). It didn't change anything so I put it
back to the simpler case of the Peer being a module-level object in the
class.
Code is below. For testing, and to make sure everything has plenty of
time, I call each of the subs from a separate button in the order Host,
StartVoiceServer, StartVoiceClient.
I've been too close to this for too long, so there's a good chance I'm
missing something perfectly obvious. (This seems like a good candiate
for one of those 'slap your forehead' moments.)
Anyone been there? Thoughts? Ideas? Half ideas?
Thanks in advance.
Reg Jacklin
===================
Windows 2000, 700 MHz true Pentium II, 512 meg RAM, SoundBlaster AWE32.
Selected subsets of the code shown below: (Error handlers etc. omitted
for brevity.)
Public Sub HostSession( _
ByRef pFrm As Form)
Dim DPAddress As DirectPlay8Address
Dim PlayerInfo As DPN_PLAYER_INFO
On Error GoTo ErrorHandler
Set DPAddress = mDX8.DirectPlayAddressCreate
DPAddress.SetSP DP8SP_TCPIP
' If mPORT > 0 Then
' DPAddress.AddComponentLong DPN_KEY_PORT, mPORT
' Commented out to eliminate a potential confusion factor
' End If
Set mDX8 = New DirectX8
Set mDPPeer = mDX8.DirectPlayPeerCreate
mDPPeer.RegisterMessageHandler pFrm
'Set up my peer info
PlayerInfo.Name = "Abcd"
PlayerInfo.lInfoFlags = DPNINFO_NAME
mDPPeer.SetPeerInfo PlayerInfo, DPNOP_SYNC
mDPPeer.Host mAppDesc, DPAddress
Exit Sub
'Invoked by Class_Initialize
Public Sub DescribeApp( _
ByVal pSessionName As String _
, Optional ByVal pPort As Long = 0 _
, Optional ByVal pMaxPlayers As Long = 0)
With mAppDesc
.guidApplication = mVOICE_GUID
.SessionName = pSessionName
.lMaxPlayers = pMaxPlayers 'MaxPlayers of 0 is unlimited
.lFlags = DPNSESSION_MIGRATE_HOST
End With
mPORT = pPort
End Sub
Public Function StartVoiceServer( _
ByRef pForm As Form)
Dim Session As DVSESSIONDESC
On Error GoTo ErrorHandler
'Initialize and start the session
Session.lBufferAggressiveness = DVBUFFERAGGRESSIVENESS_DEFAULT
Session.lBufferQuality = DVBUFFERQUALITY_DEFAULT
Session.lSessionType = DVSESSIONTYPE_PEER
Session.guidCT = vbNullString
Set mdvServer = mDX8.DirectPlayVoiceServerCreate
mdvServer.StartServerNotification pForm
mdvServer.Initialize mDPPeer, 0
mdvServer.StartSession Session, 0
Exit Function
Public Function StartVoiceClient( _
ByRef pForm As Form)
Dim Flags As Long
Dim SoundConfig As DVSOUNDDEVICECONFIG
Dim VoiceClient As DVCLIENTCONFIG
On Error GoTo ErrorHandler
Flags = 0
Set mdvClient = mDX8.DirectPlayVoiceClientCreate
mdvClient.StartClientNotification pForm
mdvClient.Initialize mDPPeer, Flags
VoiceClient.lFlags = DVCLIENTCONFIG_AUTOVOICEACTIVATED Or
DVCLIENTCONFIG_AUTORECORDVOLUME
VoiceClient.lBufferAggressiveness = DVBUFFERAGGRESSIVENESS_DEFAULT
VoiceClient.lBufferQuality = DVBUFFERQUALITY_DEFAULT
VoiceClient.lNotifyPeriod = 0
VoiceClient.lThreshold = DVTHRESHOLD_UNUSED
VoiceClient.lPlaybackVolume = DVPLAYBACKVOLUME_DEFAULT
SoundConfig.hwndAppWindow = pForm.hWnd
mdvClient.Connect SoundConfig, VoiceClient, Flags
Exit Function