private void sndTestCheckBox_CheckedChanged(object sender, EventArgs e) { ItemData input = (ItemData) sndinputComboBox.SelectedItem; ItemData output = (ItemData)sndoutputComboBox.SelectedItem; if (sndTestCheckBox.Checked) { //Extract input device and get its default samplerate. //WASAPI devices only support one sample rate so it's important to use the correct one. SoundDevice[] devs; TeamTalk.GetSoundDevices(out devs); int in_samplerate = 0; foreach (SoundDevice dev in devs) { if (dev.nDeviceID == input.id) in_samplerate = dev.nDefaultSampleRate; } SpeexDSP spxdsp = new SpeexDSP(true); spxdsp.bEnableAGC = true; spxdsp.bEnableDenoise = true; spxdsp.bEnableEchoCancellation = echocancelCheckBox.Checked; soundloop = TeamTalk.StartSoundLoopbackTest(input.id, output.id, in_samplerate, 1, duplexCheckBox.Checked, spxdsp); if (soundloop == IntPtr.Zero) { MessageBox.Show("Failed to test selected device"); sndTestCheckBox.Checked = false; } } else TeamTalk.CloseSoundLoopbackTest(soundloop); }
private void button1_Click(object sender, EventArgs e) { ClientFlag flags = ttclient.GetFlags(); //Audio-tab if ((ttclient.Flags & ClientFlag.CLIENT_SNDINOUTPUT_DUPLEX) == ClientFlag.CLIENT_SNDINOUTPUT_DUPLEX) ttclient.CloseSoundDuplexDevices(); else { ttclient.CloseSoundInputDevice(); ttclient.CloseSoundOutputDevice(); } ItemData inputItem = (ItemData)sndinputComboBox.SelectedItem; ItemData outputItem = (ItemData)sndoutputComboBox.SelectedItem; settings.sndinputid = inputItem.id; settings.sndoutputid = outputItem.id; if (duplexCheckBox.Checked) { if (!ttclient.InitSoundDuplexDevices(settings.sndinputid, settings.sndoutputid)) MessageBox.Show("Failed to init sound devices"); SpeexDSP spxdsp = new SpeexDSP(false); ttclient.GetSoundInputPreprocess(ref spxdsp); spxdsp.nEchoSuppress = SpeexDSPConstants.DEFAULT_ECHO_SUPPRESS; spxdsp.nEchoSuppressActive = SpeexDSPConstants.DEFAULT_ECHO_SUPPRESS_ACTIVE; spxdsp.bEnableEchoCancellation = echocancelCheckBox.Checked; ttclient.SetSoundInputPreprocess(spxdsp); } else { if (!ttclient.InitSoundInputDevice(settings.sndinputid)) MessageBox.Show("Failed to init sound input device"); if (!ttclient.InitSoundOutputDevice(settings.sndoutputid)) MessageBox.Show("Failed to init sound output device"); } if (wasapiRadioButton.Checked) settings.soundsystem = SoundSystem.SOUNDSYSTEM_WASAPI; else if (dsoundRadioButton.Checked) settings.soundsystem = SoundSystem.SOUNDSYSTEM_DSOUND; else if(winmmRadioButton.Checked) settings.soundsystem = SoundSystem.SOUNDSYSTEM_WINMM; //Video-tab if (viddevComboBox.Items.Count > 0) { VideoCodec codec = new VideoCodec(); codec.nCodec = Codec.WEBM_VP8_CODEC; codec.webm_vp8.nRcTargetBitrate = (int)vidbitrateNumericUpDown.Value; codec.webm_vp8.nEncodeDeadline = WebMVP8CodecConstants.WEBM_VPX_DL_REALTIME; VideoFormat capformat = videodevs[viddevComboBox.SelectedIndex].videoFormats[formatComboBox.SelectedIndex]; if (ttclient.Flags.HasFlag(ClientFlag.CLIENT_VIDEOCAPTURE_READY) && !(settings.videoid == videodevs[viddevComboBox.SelectedIndex].szDeviceID && Util.Equals(codec, settings.codec) && Util.Equals(capformat, settings.capformat))) ttclient.CloseVideoCaptureDevice(); settings.codec.nCodec = Codec.WEBM_VP8_CODEC; settings.codec.webm_vp8.nRcTargetBitrate = (int)vidbitrateNumericUpDown.Value; settings.videoid = videodevs[viddevComboBox.SelectedIndex].szDeviceID; settings.capformat = capformat; if (!ttclient.Flags.HasFlag(ClientFlag.CLIENT_VIDEOCAPTURE_READY)) { if(!ttclient.InitVideoCaptureDevice(settings.videoid, settings.capformat)) MessageBox.Show("Failed to initialize video capture device"); } } //Advanced-tab if (fwCheckBox.Checked != WindowsFirewall.AppExceptionExists(Application.ExecutablePath)) { if (fwCheckBox.Checked) WindowsFirewall.AddAppException(Application.ProductName, Application.ExecutablePath); else WindowsFirewall.RemoveAppException(Application.ExecutablePath); } }
/** * @brief Enable sound preprocessor which should be used for * processing audio recorded by the sound input device (voice input). * * To ensure common settings for all users in a channel it's * possible to use the @c audiocfg member of #BearWare.Channel as shared * source for audio settings. * * In order for echo cancellation to work best it's important to * also enable AGC in the #BearWare.SpeexDSP. * * @param lpSpeexDSP The sound preprocessor settings to use. * Preferably from the #BearWare.Channel's @c audiocfg member to ensure common * settings for all users. * @return TRUE on success, FALSE on failure. */ public bool SetSoundInputPreprocess(SpeexDSP lpSpeexDSP) { return TTDLL.TT_SetSoundInputPreprocess(m_ttInst, ref lpSpeexDSP); }
/** * @brief Perform a record and playback test of specified sound * devices along with an audio configuration and ability to try * echo cancellation. * * This function allows the use of #BearWare.SpeexDSP to enable AGC and echo * cancellation. * * @param nInputDeviceID Should be the @a nDeviceID extracted through * TeamTalk.GetSoundDevices(). * @param nOutputDeviceID Should be the @a nDeviceID extracted through * TeamTalk.GetSoundDevices(). * @param nSampleRate The sample rate the client's recorder should * use. * @param nChannels Number of channels to use, i.e. 1 = mono, 2 = stereo. * @param bDuplexMode Both input and output devices MUST support * the specified sample rate since this loop back test uses duplex * mode ( @see TeamTalk.InitSoundDuplexDevices() ). Check out @c * supportedSampleRates of #BearWare.SoundDevice to see which sample rates * are supported. * @param lpSpeexDSP The preprocessing settings to use, i.e. AGC * and denoising properties. * @return Returns IntPtr.Zero in case of error, otherwise sound loop instance * which can be closed by TeamTalk.CloseSoundLoopbackTest(); * @see TeamTalk.InitSoundInputDevice() * @see TeamTalk.InitSoundOutputDevice() * @see TeamTalk.InitSoundDuplexDevices() * @see TeamTalk.StopSoundLoopbackTest() */ public static IntPtr StartSoundLoopbackTest(int nInputDeviceID, int nOutputDeviceID, int nSampleRate, int nChannels, bool bDuplexMode, SpeexDSP lpSpeexDSP) { return TTDLL.TT_StartSoundLoopbackTest(nInputDeviceID, nOutputDeviceID, nSampleRate, nChannels, bDuplexMode, ref lpSpeexDSP); }
private void InitSound(TeamTalk ttclient) { int devin = 0, devout = 0; Assert.IsTrue(TeamTalk.GetDefaultSoundDevicesEx(SoundSystem.SOUNDSYSTEM_WASAPI, ref devin, ref devout), "Get default DSound devices"); SpeexDSP spxdsp = new SpeexDSP(); spxdsp.bEnableAGC = true; spxdsp.nGainLevel = SpeexDSPConstants.DEFAULT_AGC_GAINLEVEL; spxdsp.nMaxIncDBSec = SpeexDSPConstants.DEFAULT_AGC_INC_MAXDB; spxdsp.nMaxDecDBSec = SpeexDSPConstants.DEFAULT_AGC_DEC_MAXDB; spxdsp.nMaxGainDB = SpeexDSPConstants.DEFAULT_AGC_GAINMAXDB; spxdsp.bEnableDenoise = true; spxdsp.nMaxNoiseSuppressDB = SpeexDSPConstants.DEFAULT_DENOISE_SUPPRESS; spxdsp.bEnableEchoCancellation = true; spxdsp.nEchoSuppress = SpeexDSPConstants.DEFAULT_ECHO_SUPPRESS; spxdsp.nEchoSuppressActive = SpeexDSPConstants.DEFAULT_ECHO_SUPPRESS_ACTIVE; Assert.IsTrue(ttclient.InitSoundInputDevice(devin), "Init sound input"); Assert.IsTrue(ttclient.Flags.HasFlag(ClientFlag.CLIENT_SNDINPUT_READY), "Input ready"); Assert.IsTrue(ttclient.InitSoundOutputDevice(devout), "Init sound output"); Assert.IsTrue(ttclient.Flags.HasFlag(ClientFlag.CLIENT_SNDOUTPUT_READY), "Output ready"); }
public void TestSoundInputPreprocess() { const string USERNAME = "******", PASSWORD = "******"; string NICKNAME = "TeamTalk.NET - " + GetCurrentMethod(); const UserRight USERRIGHTS = UserRight.USERRIGHT_CREATE_TEMPORARY_CHANNEL | UserRight.USERRIGHT_TRANSMIT_VOICE; MakeUserAccount(GetCurrentMethod(), USERNAME, PASSWORD, USERRIGHTS); TeamTalk ttclient = NewClientInstance(); int cmdid; Connect(ttclient); InitSound(ttclient); Login(ttclient, NICKNAME, USERNAME, PASSWORD); SpeexDSP spxdsp = new SpeexDSP(true), spxdsp2 = new SpeexDSP(); Assert.IsTrue(ttclient.SetSoundInputPreprocess(spxdsp), "set aud cfg"); Channel chan = BuildDefaultChannel(ttclient, "foo"); Assert.AreEqual(chan.audiocodec.nCodec, Codec.OPUS_CODEC); Assert.IsTrue(ttclient.GetSoundInputPreprocess(ref spxdsp2)); Assert.AreEqual(spxdsp2.bEnableAGC, spxdsp.bEnableAGC); Assert.AreEqual(spxdsp2.nGainLevel, spxdsp.nGainLevel); Assert.AreEqual(spxdsp2.nMaxIncDBSec, spxdsp.nMaxIncDBSec); Assert.AreEqual(spxdsp2.nMaxDecDBSec, spxdsp.nMaxDecDBSec); Assert.AreEqual(spxdsp2.nMaxGainDB, spxdsp.nMaxGainDB); Assert.AreEqual(spxdsp2.bEnableDenoise, spxdsp.bEnableDenoise); Assert.AreEqual(spxdsp2.nMaxNoiseSuppressDB, spxdsp.nMaxNoiseSuppressDB); Assert.AreEqual(spxdsp2.bEnableEchoCancellation, spxdsp.bEnableEchoCancellation); Assert.AreEqual(spxdsp2.nEchoSuppress, spxdsp.nEchoSuppress); Assert.AreEqual(spxdsp2.nEchoSuppressActive, spxdsp.nEchoSuppressActive); cmdid = ttclient.DoJoinChannel(chan); }
public void TestSoundDevices() { SoundDevice[] devs; Assert.IsTrue(TeamTalk.GetSoundDevices(out devs)); foreach (SoundDevice s in devs) { Assert.IsTrue(s.nDefaultSampleRate > 0); Assert.IsTrue(s.szDeviceName.Length > 0); Assert.IsTrue(s.nSoundSystem != SoundSystem.SOUNDSYSTEM_NONE); } int devin = 0, devout = 0; Assert.IsTrue(TeamTalk.GetDefaultSoundDevices(ref devin, ref devout), "Get default devices"); SoundDevice sin = devs.First<SoundDevice>(m => m.nDeviceID == devin); SoundDevice sout = devs.First<SoundDevice>(m => m.nDeviceID == devout); int minChan = Math.Min(sin.nMaxInputChannels, sout.nMaxOutputChannels); IntPtr sndloop = TeamTalk.StartSoundLoopbackTest(devin, devout, sin.nDefaultSampleRate, minChan, false, new SpeexDSP()); Assert.IsTrue(sndloop != IntPtr.Zero, "Start loopback test"); Assert.IsTrue(TeamTalk.CloseSoundLoopbackTest(sndloop), "Stop loopback test"); Assert.IsTrue(TeamTalk.GetDefaultSoundDevicesEx(SoundSystem.SOUNDSYSTEM_DSOUND, ref devin, ref devout), "Get default DSound devices"); sin = devs.First<SoundDevice>(m => m.nDeviceID == devin); sout = devs.First<SoundDevice>(m => m.nDeviceID == devout); SpeexDSP spxdsp = new SpeexDSP(); spxdsp.bEnableAGC = SpeexDSPConstants.DEFAULT_AGC_ENABLE; spxdsp.nGainLevel = SpeexDSPConstants.DEFAULT_AGC_GAINLEVEL; spxdsp.nMaxIncDBSec = SpeexDSPConstants.DEFAULT_AGC_INC_MAXDB; spxdsp.nMaxDecDBSec = SpeexDSPConstants.DEFAULT_AGC_DEC_MAXDB; spxdsp.nMaxGainDB = SpeexDSPConstants.DEFAULT_AGC_GAINMAXDB; sndloop = TeamTalk.StartSoundLoopbackTest(sin.nDeviceID, sout.nDeviceID, sin.nDefaultSampleRate, 1, true, spxdsp); Assert.IsTrue(sndloop != IntPtr.Zero, "Testing duplex with AGC"); System.Threading.Thread.Sleep(500); Assert.IsTrue(TeamTalk.CloseSoundLoopbackTest(sndloop), "Stop duplex test with AGC"); spxdsp.bEnableAGC = false; spxdsp.bEnableDenoise = SpeexDSPConstants.DEFAULT_DENOISE_ENABLE; spxdsp.nMaxNoiseSuppressDB = SpeexDSPConstants.DEFAULT_DENOISE_SUPPRESS; sndloop = TeamTalk.StartSoundLoopbackTest(sin.nDeviceID, sout.nDeviceID, sin.nDefaultSampleRate, 1, true, spxdsp); Assert.IsTrue(IntPtr.Zero != sndloop, "Testing duplex with denoise"); System.Threading.Thread.Sleep(500); Assert.IsTrue(TeamTalk.CloseSoundLoopbackTest(sndloop), "Stop duplex test with denoise"); spxdsp.bEnableDenoise = false; spxdsp.bEnableEchoCancellation = true; spxdsp.nEchoSuppress = SpeexDSPConstants.DEFAULT_ECHO_SUPPRESS; spxdsp.nEchoSuppressActive = SpeexDSPConstants.DEFAULT_ECHO_SUPPRESS_ACTIVE; sndloop = TeamTalk.StartSoundLoopbackTest(sin.nDeviceID, sout.nDeviceID, sin.nDefaultSampleRate, 1, true, spxdsp); Assert.IsTrue(IntPtr.Zero != sndloop, "Testing duplex with AEC"); System.Threading.Thread.Sleep(500); Assert.IsTrue(TeamTalk.CloseSoundLoopbackTest(sndloop), "Stop duplex test with AEC"); spxdsp.bEnableAGC = spxdsp.bEnableDenoise = spxdsp.bEnableEchoCancellation = true; sndloop = TeamTalk.StartSoundLoopbackTest(sin.nDeviceID, sout.nDeviceID, sin.nDefaultSampleRate, 1, true, spxdsp); Assert.IsTrue(IntPtr.Zero != sndloop, "Testing duplex with AGC, AEC, denoise"); System.Threading.Thread.Sleep(500); Assert.IsTrue(TeamTalk.CloseSoundLoopbackTest(sndloop), "Stop duplex test with AGC, AEC, denoise"); sndloop = TeamTalk.StartSoundLoopbackTest(sin.nDeviceID, sout.nDeviceID, sin.nDefaultSampleRate, 2, true, spxdsp); Assert.IsTrue(IntPtr.Zero != sndloop, "Testing duplex with AGC, AEC, denoise in stereo"); System.Threading.Thread.Sleep(500); Assert.IsTrue(TeamTalk.CloseSoundLoopbackTest(sndloop), "Stop duplex test with AGC, AEC, denoise"); sndloop = TeamTalk.StartSoundLoopbackTest(sin.nDeviceID, sout.nDeviceID, sin.nDefaultSampleRate, 2, false, spxdsp); Assert.IsTrue(IntPtr.Zero == sndloop, "Testing AEC without duplex"); }