Beispiel #1
0
        protected virtual void StartNextTest()
        {
            Deployment.Current.Dispatcher.BeginInvoke(() => Status = string.Format("Executing test for latency {0} and filter length {1}", ExpectedLatency, FilterLength));

            mTestStartTime = DateTime.Now;
            IAudioFilter playedResampler;
            IAudioFilter recordedResampler;

            mCancelledFrames = new List <byte[]>();

            // Decide whether to synchronize the audio or not.
            if (AecIsSynchronized)
            {
                playedResampler   = new ResampleFilter(audioFormat, audioFormat);
                recordedResampler = new ResampleFilter(audioFormat, audioFormat);
            }
            else
            {
                playedResampler   = new NullAudioFilter(audioFormat.BytesPerFrame);
                recordedResampler = new NullAudioFilter(audioFormat.BytesPerFrame);
            }

            // Initialize the echo canceller
            playedResampler.InstanceName     = "EchoCanceller_played";
            recordedResampler.InstanceName   = "EchoCanceller_recorded";
            mediaConfig.ExpectedAudioLatency = ExpectedLatency;
            mediaConfig.FilterLength         = FilterLength;

            switch (mEchoCancellerType)
            {
            case EchoCancellerType.Speex2:
                mEchoCancelFilter = new SpeexEchoCanceller2(mediaConfig, audioFormat, AudioFormat.Default);
                break;

            case EchoCancellerType.WebRtc:
                mEchoCancelFilter = new WebRtcFilter(mediaConfig.ExpectedAudioLatency,
                                                     mediaConfig.FilterLength,
                                                     audioFormat,
                                                     AudioFormat.Default,
                                                     true,
                                                     true,
                                                     false,
                                                     playedResampler, recordedResampler);
                break;

            case EchoCancellerType.TimeDomain:
                mEchoCancelFilter = new TimeDomainEchoCancelFilter(ExpectedLatency, FilterLength, audioFormat, AudioFormat.Default, playedResampler, recordedResampler);
                break;

            case EchoCancellerType.Speex:
                mEchoCancelFilter = new SpeexEchoCancelFilter(ExpectedLatency, FilterLength, audioFormat, AudioFormat.Default, playedResampler, recordedResampler);
                break;

            default:
                throw new Exception();
            }

            mPlayer   = GetPlayer();
            mRecorder = GetRecorder();

            mRecorder.StartRecording(SpeakerFrames, FinishTest);
            mPlayer.StartPlaying(SourceFrames, mRecorder.StopRecording);
        }
Beispiel #2
0
        private void btnPlay_Click(object sender, RoutedEventArgs e)
        {
            if (btnPlay.Content.ToString() == "Start")
            {
                try
                {
                    // Setup the parameters.
                    playedFrameIndex = 0;
                    int playbackDelay = Int32.Parse(txtPlaybackDelay.Text);
                    framePlaybackInterval = playbackDelay / 20;
                    expectedLatency       = Int32.Parse(txtExpectedLatency.Text);
                    filterLength          = Int32.Parse(txtTailSize.Text);

                    IAudioFilter playedResampler;
                    IAudioFilter recordedResampler;

                    // Decide whether to synchronize the audio or not.
                    if (chkSynchronize.IsChecked == true)
                    {
                        playedResampler = new ResampleFilter(AudioFormat.Default, AudioFormat.Default);

                        recordedResampler = new ResampleFilter(AudioFormat.Default, AudioFormat.Default);
                    }
                    else
                    {
                        playedResampler   = new NullAudioFilter(AudioFormat.Default.BytesPerFrame);
                        recordedResampler = new NullAudioFilter(AudioFormat.Default.BytesPerFrame);
                    }

                    // Initialize the echo canceller
                    playedResampler.InstanceName   = "EchoCanceller_played";
                    recordedResampler.InstanceName = "EchoCanceller_recorded";
                    echoCanceller = new SpeexEchoCancelFilter(expectedLatency, filterLength, AudioFormat.Default, AudioFormat.Default, playedResampler, recordedResampler);

                    if (chkPlaySilently.IsChecked == true)
                    {
                        PerformEchoCancellation();
                        return;
                    }
                    if (chkPlayWithAEC.IsChecked == true)
                    {
                        playbackFunction = GetNextAECFrame;
                    }
                    else
                    {
                        playbackFunction = GetNextRawFrame;
                    }

                    // Start playing the audio.
                    mediaElement.Play();
                    btnPlay.Content = "Stop";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                btnPlay.Content = "Start";
                mediaElement.Stop();
            }
        }