public void InitVoiceHost(Peer host, Voice.Server dpvs, Voice.Client dpvc, Form wnd) { try { server = dpvs; client = dpvc; TestAudioSetup(wnd); //Audio Setup was successful, open the configuration form mConfigForm.ShowDialog(mClientConfig, dpvs.CompressionTypes, false); if (mConfigForm.DialogResult == DialogResult.Cancel) { throw new Exception("Voice configuration cancelled"); } mClientConfig = mConfigForm.ClientConfig; //create the voice session CreateVoiceSession(host, Voice.SessionType.Peer, mConfigForm.CompressionGuid); //Connect to the voice session ConnectToVoiceSession(host, wnd); } catch (Exception e) { MessageBox.Show("Error attempting to start Voice Server Session. This sample will now exit.", "Exiting", MessageBoxButtons.OK, MessageBoxIcon.Information); throw e; } }
public DialogResult ShowDialog(Voice.ClientConfig config, Voice.CompressionInformation[] cInfo, bool inSession) { mConfig = config; mCompressionInfo = cInfo; mIsHost = true; mInSession = inSession; UpdateControls(); return(this.ShowDialog()); }
public DialogResult ShowDialog(Voice.ClientConfig config, bool inSession) { mConfig = config; mCompressionInfo = null; mIsHost = false; mInSession = inSession; UpdateControls(); return(this.ShowDialog()); }
public void ChangeVoiceClientSettings(Voice.ClientConfig config) { try { client.ClientConfig = config; } catch (Exception e) { throw e; } }
public VoiceWizard() { mClientConfig = new Voice.ClientConfig(); mClientConfig.BufferAggressiveness = Voice.BufferAggressiveness.Default; mClientConfig.BufferQuality = Voice.BufferQuality.Default; mClientConfig.Flags = Voice.ClientConfigFlags.AutoVoiceActivated | Voice.ClientConfigFlags.AutoRecordVolume; mClientConfig.Threshold = Voice.Threshold.Default; mClientConfig.NotifyPeriod = 0; mClientConfig.PlaybackVolume = (int)Voice.PlaybackVolume.Default; mClientConfig.RecordVolume = (int)Voice.RecordVolume.Last; mConfigForm = new DPlayVoiceConfigForm(); mInSession = false; mIsHost = false; }
public void ShowClientSetupDialog(IntPtr hWnd) { try { using (mConfigForm = new DPlayVoiceConfigForm()) { mConfigForm.ShowDialog(mClientConfig, mInSession); mClientConfig = mConfigForm.ClientConfig; client.ClientConfig = mClientConfig; } } catch (Exception e) { throw e; } }
public void InitVoiceClient(Peer dpp, Voice.Client dpvc, Form wnd) { try { TestAudioSetup(wnd); //Audio Setup was successful, open the configuration form mConfigForm.ShowDialog(mClientConfig, false); mClientConfig = mConfigForm.ClientConfig; client = dpvc; //connect to the voice session ConnectToVoiceSession(dpp, wnd); } catch (Exception e) { MessageBox.Show("Error attempting to connect to a Voice Server. This sample will now exit.", "Exiting", MessageBoxButtons.OK, MessageBoxIcon.Information); throw e; } }
/// <summary> /// Initializes the DirectPlayVoice Client and Server objects /// </summary> private void InitDirectPlayVoice() { // Release any existing resources if (m_VoiceClient != null) { m_VoiceClient.Dispose(); m_VoiceClient = null; } if (m_VoiceServer != null) { m_VoiceServer.Dispose(); m_VoiceServer = null; } // Initialize UI variables this.m_NumPlayersTalking = 0; // Based on the current connection, create DirectPlay voice objects. #region About DirectPlay Voice // Since the DirectPlay Voice API defines server and client interfaces, // but not a peer interface, one of the peers must act as the server // for voice communication; the logical choice is the session host, so // for this sample, the session host creates a server object in addition // to a client object. Note that in order to send and receive voice // messages you must have a connected voice client object, even if you // are acting as the voice server. #endregion switch (Connection) { case ConnectionType.Hosting: { // Create a new Voice Server m_VoiceServer = new Voice.Server(m_Peer); // Create a Session Description for the voice session Voice.SessionDescription desc = new Voice.SessionDescription(); desc.SessionType = Voice.SessionType.Peer; desc.BufferQuality = Voice.BufferQuality.Default; desc.GuidCompressionType = Voice.CompressionGuid.Default; desc.BufferAggressiveness = Voice.BufferAggressiveness.Default; // Launch a new voice session m_VoiceServer.StartSession(desc); // Fall-through to create client object goto case ConnectionType.Connected; } case ConnectionType.Connected: { // Test Direct Voice if (TestDirectVoice() == false) { return; } // Create a new Voice Client m_VoiceClient = new Voice.Client(m_Peer); // Add event handlers m_VoiceClient.PlayerStarted += new Voice.PlayerStartedEventHandler(PlayerStartedHandler); m_VoiceClient.PlayerStopped += new Voice.PlayerStoppedEventHandler(PlayerStoppedHandler); m_VoiceClient.RecordStarted += new Voice.RecordStartedEventHandler(RecordStartedHandler); m_VoiceClient.RecordStopped += new Voice.RecordStoppedEventHandler(RecordStoppedHandler); // Fill in description object for device configuration Voice.SoundDeviceConfig soundConfig = new Voice.SoundDeviceConfig(); soundConfig.Flags = Voice.SoundConfigFlags.AutoSelect; soundConfig.GuidPlaybackDevice = DSoundHelper.DefaultPlaybackDevice; soundConfig.GuidCaptureDevice = DSoundHelper.DefaultCaptureDevice; soundConfig.Window = m_Form; soundConfig.MainBufferPriority = 0; // Fill in description object for client configuration Voice.ClientConfig clientConfig = new Voice.ClientConfig(); clientConfig.Flags = Voice.ClientConfigFlags.AutoVoiceActivated | Voice.ClientConfigFlags.AutoRecordVolume; clientConfig.RecordVolume = (int)Voice.RecordVolume.Last; clientConfig.PlaybackVolume = (int)Voice.PlaybackVolume.Default; clientConfig.Threshold = Voice.Threshold.Unused; clientConfig.BufferQuality = Voice.BufferQuality.Default; clientConfig.BufferAggressiveness = Voice.BufferAggressiveness.Default; clientConfig.NotifyPeriod = 0; try { // Connect to the voice session m_VoiceClient.Connect(soundConfig, clientConfig, Voice.VoiceFlags.Sync); } catch (Exception ex) { m_Form.ShowException(ex, "Connect", true); m_Form.Dispose(); return; } // Set DirectPlay to send voice messages to all players int[] targets = { (int)Voice.PlayerId.AllPlayers }; m_VoiceClient.TransmitTargets = targets; break; } case ConnectionType.Disconnected: { return; } } }
private void buttonOK_Click(object sender, System.EventArgs e) { //clear the config mConfig = new Voice.ClientConfig(); mConfig.Flags = 0; // Set playback parameters if (radioButtonPlaybackDefault.Checked) { mConfig.PlaybackVolume = (int)Voice.PlaybackVolume.Default; } else { mConfig.PlaybackVolume = (int)Volume.Min + (int)((trackBarPlaybackVolume.Value / 100.0f) * (Volume.Max - Volume.Min)); } // Set recording parameters if (radioButtonRecordVolumeAuto.Checked) { mConfig.RecordVolume = 0; mConfig.Flags |= Voice.ClientConfigFlags.AutoRecordVolume; } else if (radioButtonRecordVolumeDefault.Checked) { mConfig.RecordVolume = (int)Voice.PlaybackVolume.Default; } else { mConfig.RecordVolume = (int)Volume.Min + (int)((trackBarRecordVolume.Value / 100.0f) * (Volume.Max - Volume.Min)); } // Set threshold parameters if (radioButtonThresholdAuto.Checked) { mConfig.Threshold = Voice.Threshold.Unused; mConfig.Flags |= Voice.ClientConfigFlags.AutoVoiceActivated; } else if (radioButtonThresholdDefault.Checked) { mConfig.Threshold = Voice.Threshold.Default; mConfig.Flags |= Voice.ClientConfigFlags.ManualVoiceActivated; } else { mConfig.Threshold = (Voice.Threshold)((int)Voice.Threshold.Min + (trackBarThreshold.Value / 100.0f * ((int)Voice.Threshold.Max - (int)Voice.Threshold.Min))); mConfig.Flags |= Voice.ClientConfigFlags.ManualVoiceActivated; } //Can only be set at the beginning, when the host is not in a session if (mIsHost && !mInSession) { mSelectedCompressionGuid = mCompressionInfo[CompressionTypeComboBox.SelectedIndex].GuidType; } this.DialogResult = DialogResult.OK; this.Hide(); }