Пример #1
0
        private void ProcessGathering(SpectrumProcessor sink)
        {
            CheckStopConditions();

            CurrentActivityDescription = "Gathering data...";
            CurrentActivityIndex       = 2;
        }
Пример #2
0
        public DiscChanger()
        {
            _trackList = new Playlist();

            var audioEngine = AudioEngine.CreateDefault();

            if (audioEngine == null)
            {
                throw new Exception("Failed to create an audio backend!");
            }

            var specProcessor = new SpectrumProcessor();

            _soundSink = new SoundSink(audioEngine, specProcessor);

            Observable.FromEventPattern <EventArgs>(this, nameof(TrackChanged))
            .Select(x => _currentTrack)
            .Where(x => x != null)
            .Select(x => x.SoundStream)
            .Subscribe(OnTrackChanged);

            Observable.FromEventPattern <double[, ]>(specProcessor, nameof(specProcessor.FftDataReady))
            .Subscribe(x =>
            {
                CurrentSpectrumData = x.EventArgs;
                SpectrumDataReady?.Invoke(this, EventArgs.Empty);
            });
        }
Пример #3
0
        protected void RegisterSink(int channel, SpectrumProcessor sink)
        {
            sink.OnItemProcessed += OnItemProcessed;

            _sinks[channel] = sink;
            _testSignalPresentMap[channel] = false;
        }
Пример #4
0
        public DiscChanger()
        {
            _trackList = new Playlist();

            var audioEngine = AudioEngine.CreateDefault();

            if (audioEngine == null)
            {
                throw new Exception("Failed to create an audio backend!");
            }

            var spectrumProcessor = new SpectrumProcessor();

            _soundSink = new SoundSink(audioEngine, spectrumProcessor);

            _internalDisposables = new CompositeDisposable();

            Observable.FromEventPattern <double[, ]>(spectrumProcessor, nameof(spectrumProcessor.FftDataReady))
            .Subscribe(x =>
            {
                CurrentSpectrumData = x.EventArgs;
            })
            .DisposeWith(_internalDisposables);

            this.WhenAnyValue(x => x.InternalState)
            .DistinctUntilChanged()
            .Subscribe(x => IsPlaying = (x == DiscChangerState.Playing))
            .DisposeWith(_internalDisposables);

            InternalState = (DiscChangerState.Idle);
        }
Пример #5
0
        private void SetGatheringPhase(SpectrumProcessor sink)
        {
            SetStopConditions();
            sink.Data.Reset();
            sink.Data.DefaultValue = Spectrum.DefaultValueType.Mean;

            _phase = Phase.Gathering;
        }
Пример #6
0
        private void ProcessWarmUp(SpectrumProcessor sink)
        {
            sink.Data.DefaultValue     = Spectrum.DefaultValueType.Last;
            CurrentActivityDescription = "Warming up...";
            CurrentActivityIndex       = 1;

            var warmable = Settings as IWarmable;
            var warmUpDurationSeconds = warmable.WarmUpEnabled ? warmable.WarmUpDurationSeconds : 0;

            if (DateTime.Now.Subtract(_inputSignalReceivedAt).Duration().TotalSeconds >= warmUpDurationSeconds)
            {
                SetGatheringPhase(sink);
            }
        }
Пример #7
0
        private void Initialize()
        {
            RegisterGenerator(AppSettings.Current.Device.PrimaryOutputChannel, GetGenerator());

            _processor = new SpectrumProcessor(AppSettings.Current.Fft.WindowSize,
                                               AppSettings.Current.Fft.WindowOverlapFactor,
                                               (int)(AppSettings.Current.Device.SampleRate * 0.5),
                                               AppSettings.Current.Fft.WindowFunction);

            RegisterSink(AppSettings.Current.Device.PrimaryInputChannel, _processor);

            ApplyStopConditions();
            ApplyCorrectionProfile(_processor.Data);
        }
Пример #8
0
        private void ProcessAwaitInput(SpectrumProcessor sink)
        {
            CurrentActivityDescription = "Awaiting signal...";

            var allInputSingnalsPresent = _testSignalPresentMap.Values.All(v => v == true);

            if (!allInputSingnalsPresent)
            {
                var expectedLoopbackDelay = Math.Max(
                    (AppSettings.Current.Device.InputDevice.LatencyMilliseconds + AppSettings.Current.Device.OutputDevice.LatencyMilliseconds),
                    2.0 * 1000.0 * Settings.Fft.Value.WindowSize / AppSettings.Current.Device.SampleRate
                    );

                if (Elapsed.TotalMilliseconds > expectedLoopbackDelay)
                {
                    var channel = Sinks.First(s => s.Value == sink).Key;
                    _testSignalPresentMap[channel] = CheckSignalPresent(sink.Data);

                    if (!_testSignalPresentMap[channel])
                    {
                        var channels = _testSignalPresentMap.Where(m => m.Value == false).Select(m => m.Key.ToString()).OrderBy(k => k);

                        var message = $"No test signal detected in channels {channels.Aggregate((a, b) => (a + ", " + b))}.";
                        OnError(new Exception(message));
                        Stop(true);

                        return;
                    }


                    _inputSignalReceivedAt = DateTime.Now;
                    if (Settings is IWarmable warmable)
                    {
                        _phase = Phase.WarmUp;
                    }
                    else
                    {
                        SetGatheringPhase(sink);
                    }

                    sink.Data.Reset();
                }
            }
        }
Пример #9
0
        private static void TestSpectrumProcessor(TransitionBinner transBinner, AbstractIsoWindowMapper isoMapper,
                                                  MsDataFileImpl file, int testSpectrumNum)
        {
            int lastSpectrum      = testSpectrumNum + 60;
            int firstSpectrum     = testSpectrumNum - 60;
            var spectrumProcessor = new SpectrumProcessor(lastSpectrum + 1, isoMapper, transBinner);

            // Make a new spectrum processor using the testing constructor that takes in
            // a TransitionBinner, which will be the one used for overlap
            // Add the spectra to the cache +/- 60 from the spectrum of interest
            for (int i = firstSpectrum; i <= lastSpectrum; ++i)
            {
                var spectrum = file.GetSpectrum(i);
                spectrumProcessor.AddSpectrum(i, spectrum);
            }

            // Check that the caching worked correctly
            for (int spectrumIndex = firstSpectrum; spectrumIndex <= lastSpectrum; ++spectrumIndex)
            {
                ScanCached specData;
                Assert.IsTrue(spectrumProcessor.TryGetSpectrum(spectrumIndex, out specData));

                // Check that the cached processing results match the output of
                // redoing the processing manually by extracting the spectrum from
                // the file again and using transBinner to bin the data
                var      testSpectrum       = file.GetSpectrum(spectrumIndex);
                double[] expectedBinnedData = new double[transBinner.NumBins];
                transBinner.BinData(testSpectrum.Mzs, testSpectrum.Intensities, ref expectedBinnedData);
                ScanCached testSpecData;
                spectrumProcessor.TryGetSpectrum(spectrumIndex, out testSpecData);
                var seenBinnedData = testSpecData.Data;
                Assert.AreEqual(expectedBinnedData.Length, seenBinnedData.Length);
                for (int i = 0; i < expectedBinnedData.Length; ++i)
                {
                    Assert.AreEqual(expectedBinnedData[i], seenBinnedData[i], 0.0001);
                }
            }
        }
Пример #10
0
        private static void TestSpectrumProcessor(TransitionBinner transBinner,AbstractIsoWindowMapper isoMapper, 
            MsDataFileImpl file, int testSpectrumNum)
        {
            int lastSpectrum = testSpectrumNum + 60;
            int firstSpectrum = testSpectrumNum - 60;
            var spectrumProcessor = new SpectrumProcessor(lastSpectrum + 1, isoMapper, transBinner);

            // Make a new spectrum processor using the testing constructor that takes in
            // a TransitionBinner, which will be the one used for overlap
            // Add the spectra to the cache +/- 60 from the spectrum of interest
            for (int i = firstSpectrum; i <= lastSpectrum; ++i)
            {
                var spectrum = file.GetSpectrum(i);
                spectrumProcessor.AddSpectrum(i, spectrum);
            }

            // Check that the caching worked correctly
            for (int spectrumIndex = firstSpectrum; spectrumIndex <= lastSpectrum; ++spectrumIndex)
            {
                ScanCached specData;
                Assert.IsTrue(spectrumProcessor.TryGetSpectrum(spectrumIndex, out specData));

                // Check that the cached processing results match the output of
                // redoing the processing manually by extracting the spectrum from
                // the file again and using transBinner to bin the data
                var testSpectrum = file.GetSpectrum(spectrumIndex);
                double[] expectedBinnedData = new double[transBinner.NumBins];
                transBinner.BinData(testSpectrum.Mzs, testSpectrum.Intensities, ref expectedBinnedData);
                ScanCached testSpecData;
                spectrumProcessor.TryGetSpectrum(spectrumIndex, out testSpecData);
                var seenBinnedData = testSpecData.Data;
                Assert.AreEqual(expectedBinnedData.Length, seenBinnedData.Length);
                for (int i = 0; i < expectedBinnedData.Length; ++i)
                {
                    Assert.AreEqual(expectedBinnedData[i], seenBinnedData[i], 0.0001);
                }
            }
        }