Exemple #1
0
        public CrossTimeEngine(string configurationFilePath, CrossTimeEngineLog log)
        {
            this.Configuration = CrossTimeDspConfiguration.Load(configurationFilePath);
            this.disposed      = false;
            this.log           = log;
            this.Stopping      = false;

            MediaFoundationApi.Startup();

            Filter firstReverseTimeFilter = this.Configuration.Filters.FirstOrDefault(filter => filter.TimeDirection == TimeDirection.Reverse);

            if (firstReverseTimeFilter != null)
            {
                firstReverseTimeFilter.AdjustGain(this.Configuration.Engine.ReverseTimeAntiClippingAttenuationInDB);
            }
        }
        private void FilterStream(CrossTimeDspConfiguration configuration, SampleBuffer inputBuffer, SampleType dataPathSampleType, SampleType outputSampleType)
        {
            // setup
            FilterBank filters = new FilterBank(configuration.Engine.Precision, inputBuffer.WaveFormat.SampleRate, inputBuffer.WaveFormat.Channels, configuration.Engine.Q31Adaptive.Q31_32x64_Threshold, configuration.Engine.Q31Adaptive.Q31_64x64_Threshold);

            foreach (Filter filter in configuration.Filters)
            {
                filter.AddTo(filters);
            }

            // time duration of reverse time pass
            DateTime filteringStartedUtc = DateTime.UtcNow;

            using (SampleBuffer reverseTimeBuffer = new SampleBuffer(inputBuffer.WaveFormat.SampleRate, outputSampleType.BitsPerSample(), inputBuffer.WaveFormat.Channels))
            {
                SampleBlock recirculatingDataPathBlock = null;
                for (LinkedListNode <SampleBlock> blockNode = inputBuffer.Blocks.Last; blockNode != null; blockNode = blockNode.Previous)
                {
                    SampleBlock filteredBlock = filters.FilterReverse(blockNode.Value, dataPathSampleType, outputSampleType, ref recirculatingDataPathBlock);
                    reverseTimeBuffer.Blocks.AddFirst(filteredBlock);
                }
                if (recirculatingDataPathBlock != null)
                {
                    recirculatingDataPathBlock.Dispose();
                }
                reverseTimeBuffer.RecalculateBlocks();

                DateTime filteringStoppedUtc = DateTime.UtcNow;
                if (filters.TimingAvailable)
                {
                    this.TestContext.WriteLine("{0} ({1} {2} {3})", (filteringStoppedUtc - filteringStartedUtc).ToString(Constant.ElapsedTimeFormat), filters.ToDataPathTime.ToString(Constant.ElapsedTimeFormat), filters.FilterTime.ToString(Constant.ElapsedTimeFormat), filters.ToOutputTime.ToString(Constant.ElapsedTimeFormat));
                }
                else
                {
                    this.TestContext.WriteLine("{0}", (filteringStoppedUtc - filteringStartedUtc).ToString(Constant.ElapsedTimeFormat));
                }
            }
        }