コード例 #1
0
 public BasicSpectrumProvider(int channels, int sampleRate, FftSize fftSize)
     : base(channels, fftSize)
 {
     if (sampleRate <= 0)
         throw new ArgumentOutOfRangeException("sampleRate");
     _sampleRate = sampleRate;
 }
コード例 #2
0
        public VoicePrint3DSpectrum(FftSize fftSize)
        {
            _colorCalculator = new GradientCalculator();
            Colors           = new[] { Color.Black, Color.Blue, Color.Cyan, Color.Lime, Color.Yellow, Color.Red };

            FftSize = fftSize;
        }
コード例 #3
0
        public static NumberOfFrequencyBands[] GetPossibleNumberOfFrequencyBands(this FftSize fftSize)
        {
            int maxFrequency = (int)fftSize / 4;
            var enumValues   = typeof(NumberOfFrequencyBands).GetEnumValues().Cast <NumberOfFrequencyBands>();

            return(enumValues.Where(bands => (int)bands <= maxFrequency).ToArray());
        }
コード例 #4
0
ファイル: MusicPlayer.cs プロジェクト: week9/Switch-Toolbox
        private void SetupSampleSource(ISampleSource aSampleSource)
        {
            const FftSize fftSize = FftSize.Fft4096;
            //create a spectrum provider which provides fft data based on some input
            var spectrumProvider = new BasicSpectrumProvider(aSampleSource.WaveFormat.Channels,
                                                             aSampleSource.WaveFormat.SampleRate, fftSize);

            //linespectrum and voiceprint3dspectrum used for rendering some fft data
            //in oder to get some fft data, set the previously created spectrumprovider
            _lineSpectrum = new LineSpectrum(fftSize)
            {
                SpectrumProvider = spectrumProvider,
                UseAverage       = true,
                BarCount         = 50,
                BarSpacing       = 2,
                IsXLogScale      = true,
                ScalingStrategy  = ScalingStrategy.Sqrt
            };

            //the SingleBlockNotificationStream is used to intercept the played samples
            var notificationSource = new SingleBlockNotificationStream(aSampleSource);

            //pass the intercepted samples as input data to the spectrumprovider (which will calculate a fft based on them)
            notificationSource.SingleBlockRead += (s, a) => spectrumProvider.Add(a.Left, a.Right);

            _waveSource = notificationSource.ToWaveSource(16);
        }
コード例 #5
0
            public SoundCapture()
            {
                // This uses the wasapi api to get any sound data played by the computer
                capture = new WasapiLoopbackCapture();

                capture.Initialize();

                // Get our capture as a source
                IWaveSource source = new SoundInSource(capture);


                // From https://github.com/filoe/cscore/blob/master/Samples/WinformsVisualization/Form1.cs

                // This is the typical size, you can change this for higher detail as needed
                fftSize = FftSize.Fft4096;

                // Actual fft data
                fftBuffer = new float[(int)fftSize];


                // Tells us when data is available to send to our spectrum
                var notificationSource = new SingleBlockNotificationStream(source.ToSampleSource());

                notificationSource.SingleBlockRead += NotificationSource_SingleBlockRead;

                // We use this to request data so it actualy flows through (figuring this out took forever...)
                finalSource = notificationSource.ToWaveSource();

                capture.DataAvailable += Capture_DataAvailable;
                capture.Start();
            }
コード例 #6
0
        /// <summary>
        /// Initializes a new BlobSpectrum instance.
        /// </summary>
        /// <param name="game"></param>
        /// <param name="device"></param>
        /// <param name="spectrumProvider"></param>
        /// <param name="fftSize"></param>
        public BlobSpectrum(MainGame game, SpectrumProvider spectrumProvider, FftSize fftSize)
            : base(fftSize)
        {
            SpectrumProvider = spectrumProvider;
            UseAverage       = true;
            Resolution       = 500;
            IsXLogScale      = true;
            ScalingStrategy  = ScalingStrategy.Linear;

            emitter = new Emitter(game, MainGame.ViewportWidth, MainGame.ViewportHeight);

            camera          = game.Camera;
            circleTexture   = game.Content.Load <Texture2D>("Images/Circle");
            rvCircleTexture = game.Content.Load <Texture2D>("Images/MachCircle");

            blobs = new Blob[BlobCount];

            random = new Random();

            for (int i = 0; i < blobs.Length; i++)
            {
                blobs[i] = new Blob(circleTexture, new HslColor(i * (255 / blobs.Length), 0.5f, 0.5f).ToRgb(), random);
            }

            lowAvgBuffer  = 0;
            highAvgBuffer = 0;
        }
コード例 #7
0
ファイル: RLSpectrum.cs プロジェクト: MackinnonBuck/real-vis
        /// <summary>
        /// Initializes a new RLSpectrum instance
        /// </summary>
        /// <param name="game"></param>
        /// <param name="provider"></param>
        /// <param name="fftSize"></param>
        public RLSpectrum(MainGame game, SpectrumProvider provider, FftSize fftSize) : base(fftSize)
        {
            this.game = game;

            SpectrumProvider = provider;
            UseAverage       = true;
            Resolution       = MatrixResolution + LowCut + HighCut;
            IsXLogScale      = true;
            ScalingStrategy  = ScalingStrategy.Decibel;

            effect = new BasicEffect(game.GraphicsDevice)
            {
                DiffuseColor = RetroPurple.ToVector3()
            };

            random = new Random();

            matrix = new RLMatrix(game, MatrixNumEntries, MatrixResolution);

            linePlot = new RLLinePlot(MatrixResolution, LineCache, RetroPurple);

            carTexture     = game.Content.Load <Texture2D>("Images/Octane");
            messageTexture = game.Content.Load <Texture2D>("Images/Message");
            spriteFont     = game.Content.Load <SpriteFont>("Fonts/Lazer84");

            car = new RLCar(carTexture, RetroBlue, random);

            countdown        = new RLCountdown(spriteFont, RetroRed);
            countdown.Alarm += CountdownAlarm;

            constrainedPoints = new SpectrumPointData[MatrixResolution];

            globalHook          = Hook.GlobalEvents();
            globalHook.KeyDown += KeyDown;
        }
コード例 #8
0
        public VoicePrint3DSpectrum(FftSize fftSize)
        {
            _colorCalculator = new GradientCalculator();
            Colors = new[] {Color.Black, Color.Blue, Color.Cyan, Color.Lime, Color.Yellow, Color.Red};

            FftSize = fftSize;
        }
コード例 #9
0
        public FFTDataProvider(FftSize fftSize)
        {
            this.fftSize = fftSize;
            _soundIn     = new WasapiLoopbackCapture();
            _soundIn.Initialize();
            var           soundInSource = new SoundInSource(_soundIn);
            ISampleSource source        = soundInSource.ToSampleSource();

            fftProvider  = new FftProvider(source.WaveFormat.Channels, fftSize);
            fftProvider2 = new FftProvider(source.WaveFormat.Channels, fftSize);
            var notificationSource = new SingleBlockNotificationStream(source);

            SamplesRate = source.WaveFormat.SampleRate;
            //pass the intercepted samples as input data to the spectrumprovider (which will calculate a fft based on them)
            notificationSource.SingleBlockRead += addToFFTs;
            var _source = notificationSource.ToWaveSource(16);

            byte[] buffer = new byte[_source.WaveFormat.BytesPerSecond / 8];// 1/8 seconds
            soundInSource.DataAvailable += (s, aEvent) =>
            {
                int read;
                while ((read = _source.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ;
                }
            };
            _readStarted = false;
        }
コード例 #10
0
        public float[] GetRawSpectrData(string filename, FftSize size, float fps, int maxwidth, int startscan = 0)
        {
            GetFftData(filename, size, fps, maxwidth, startscan);
            var spectr = DoScanSpectr(ref _data);

            return(spectr);
        }
コード例 #11
0
 public FFTHandler(int channels, int sampleRate, FftSize fftSize) : base(channels, fftSize)
 {
     if (sampleRate <= 0)
     {
         throw new ArgumentOutOfRangeException("sampleRate");
     }
     this.sampleRate = sampleRate;
 }
コード例 #12
0
ファイル: SingleSpectrum.cs プロジェクト: tamasseller/Artemis
        public SingleSpectrum(FftSize fftSize, ISpectrumProvider spectrumProvider)
        {
            SpectrumProvider   = spectrumProvider;
            SpectrumResolution = 1;
            FftSize            = fftSize;

            UpdateFrequencyMapping();
        }
コード例 #13
0
 public BasicSpectrumProvider(int channels, int sampleRate, FftSize fftSize) : base(channels, fftSize)
 {
     if (sampleRate <= 0)
     {
         throw new ArgumentOutOfRangeException("Invalid sample rate.");
     }
     this.sampleRate = sampleRate;
 }
コード例 #14
0
 public SpectrumProvider(int channels, int sampleRate, FftSize fftSize) : base(channels, fftSize)
 {
     if (sampleRate <= 0)
     {
         throw new ArgumentOutOfRangeException("sampleRate");
     }
     _sampleRate = sampleRate;
 }
コード例 #15
0
 public LpsFFTProvider(int channels, int sampleRate, FftSize fftSize = FftSize.Fft4096)
     : base(channels, fftSize)
 {
     if (sampleRate <= 0)
     {
         throw new ArgumentOutOfRangeException("sampleRate");
     }
     _sampleRate = sampleRate;
 }
コード例 #16
0
        public SimpleSpectrumProvider(int channels, int sampleRate, FftSize fftSize) : base(channels, fftSize)
        {
            if (sampleRate <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(sampleRate));
            }
            this.SampleRate = sampleRate;

            // TODO: Set WindowFunction to WindowFunctions.Hanning once CSCore version 1.3 (or >1.2.1.2) is out.
        }
コード例 #17
0
ファイル: LineSpectrum.cs プロジェクト: Mesutmst/LEDMatrix
        private void SetFftSize(FftSize size)
        {
            if ((int)Math.Log((int)size, 2) % 1 != 0)
            {
                throw new ArgumentOutOfRangeException("value");
            }

            _fftSize     = (int)size;
            _maxFftIndex = _fftSize / 2 - 1;
        }
コード例 #18
0
    void Awake()
    {
        barData = new float[numBars];
        // This uses the wasapi api to get any sound data played by the computer
        switch (audioType)
        {
        case AudioSourceType.Microphone: capture = new WasapiCapture();
            break;

        case AudioSourceType.Speakers: capture = new WasapiLoopbackCapture();
            break;
        }

        capture.Initialize();

        // Get our capture as a source
        IWaveSource source = new SoundInSource(capture);


        // From https://github.com/filoe/cscore/blob/master/Samples/WinformsVisualization/Form1.cs

        // This is the typical size, you can change this for higher detail as needed
        fftSize = FftSize.Fft4096;

        // Actual fft data
        fftBuffer = new float[(int)fftSize];

        // These are the actual classes that give you spectrum data
        // The specific vars of lineSpectrum are changed below in the editor so most of these aren't that important here
        spectrumProvider = new BasicSpectrumProvider(capture.WaveFormat.Channels,
                                                     capture.WaveFormat.SampleRate, fftSize);

        lineSpectrum = new LineSpectrum(fftSize)
        {
            SpectrumProvider = spectrumProvider,
            UseAverage       = isAverage,
            BarCount         = numBars,
            BarSpacing       = 2,
            IsXLogScale      = false,
            ScalingStrategy  = ScalingStrategy.Linear
        };

        // Tells us when data is available to send to our spectrum
        var notificationSource = new SingleBlockNotificationStream(source.ToSampleSource());

        notificationSource.SingleBlockRead += NotificationSource_SingleBlockRead;

        // We use this to request data so it actualy flows through (figuring this out took forever...)
        finalSource = notificationSource.ToWaveSource();

        capture.DataAvailable += Capture_DataAvailable;
        capture.Start();
    }
コード例 #19
0
        public FftResultStream(FftSize fftSize, WindowFunction windowFunction, MMDevice device)
        {
            FftSize        = (int)fftSize;
            Device         = device;
            _fft           = new float[(int)fftSize];
            _wasapiCapture = CreateWaspiCapture();
            var sampleSource = CreateSampleSource(_wasapiCapture);

            _fftProvider = new CustomFftProvider(sampleSource.WaveFormat.Channels, fftSize, windowFunction);
            _waveSource  = CreateWaveSource(sampleSource, _fftProvider);
            _buffer      = new byte[_waveSource.WaveFormat.BytesPerSecond / 2];
        }
コード例 #20
0
        static void Main(string[] args)
        {
            WasapiGeneral wasapi = new WasapiGeneral();

            wasapi.StartCaptureMicrophone();
            wasapi.ApplyEffect(new DmoEchoEffect(wasapi.wave));
            wasapi.StartOutput();

            FftSize fftsize = CSCore.DSP.FftSize.Fft1024;

            FFTHandler fftHandler = new FFTHandler(wasapi.sis.WaveFormat.Channels, wasapi.sis.WaveFormat.SampleRate, CSCore.DSP.FftSize.Fft1024);

            float[] fftValues = new float[(int)fftsize];

            var notificationSource = new SingleBlockNotificationStream(wasapi.output.WaveSource.ToSampleSource());

            string gainGraph = "";
            int    i;

            while (true)
            {
                gainGraph = "";

                i = 0;

                notificationSource.SingleBlockRead += (s, a) => fftHandler.Add(a.Left, a.Right);
                fftHandler.GetFftData(fftValues);

                foreach (int x in fftValues)
                {
                    foreach (int y in Enumerable.Range(0, x))
                    {
                        /*
                         * i += 1;
                         * if (i == 1)
                         * {
                         *  gainGraph += "#";
                         *  i = 0;
                         * }
                         */
                        Console.WriteLine(y);
                    }
                    Console.WriteLine(x);
                }

                //Console.WriteLine(gainGraph);
            }

            Console.ReadKey();

            wasapi.StopCapture();
            wasapi.StopPlayback();
        }
コード例 #21
0
ファイル: AudioManager.cs プロジェクト: Slion/CIC
        /// <summary>
        ///
        /// </summary>
        private void StartAudioVisualization()
        {
            //Open the default device
            iSoundIn = new WasapiLoopbackCapture();
            //Our loopback capture opens the default render device by default so the following is not needed
            //iSoundIn.Device = MMDeviceEnumerator.DefaultAudioEndpoint(DataFlow.Render, Role.Console);
            iSoundIn.Initialize();

            SoundInSource soundInSource = new SoundInSource(iSoundIn);
            ISampleSource source        = soundInSource.ToSampleSource();

            const FftSize fftSize = FftSize.Fft2048;
            //create a spectrum provider which provides fft data based on some input
            BasicSpectrumProvider spectrumProvider = new BasicSpectrumProvider(source.WaveFormat.Channels, source.WaveFormat.SampleRate, fftSize);

            //linespectrum and voiceprint3dspectrum used for rendering some fft data
            //in oder to get some fft data, set the previously created spectrumprovider
            iLineSpectrum = new LineSpectrum(fftSize)
            {
                SpectrumProvider = spectrumProvider,
                UseAverage       = false, // Does not matter since we hacked it
                BarCount         = 16,
                BarSpacing       = 1,
                IsXLogScale      = true,                   // Does not matter since we hacked it
                ScalingStrategy  = ScalingStrategy.Decibel // Does not matter since we hacked it
            };


            //the SingleBlockNotificationStream is used to intercept the played samples
            var notificationSource = new SingleBlockNotificationStream(source);

            //pass the intercepted samples as input data to the spectrumprovider (which will calculate a fft based on them)
            notificationSource.SingleBlockRead += (s, a) => spectrumProvider.Add(a.Left, a.Right);

            iWaveSource = notificationSource.ToWaveSource(16);


            // We need to read from our source otherwise SingleBlockRead is never called and our spectrum provider is not populated
            byte[] buffer = new byte[iWaveSource.WaveFormat.BytesPerSecond / 2];
            soundInSource.DataAvailable += (s, aEvent) =>
            {
                int read;
                while ((read = iWaveSource.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ;
                }
            };


            //Start recording
            iSoundIn.Start();
        }
コード例 #22
0
ファイル: Form1.cs プロジェクト: noah4477/HardwareMixer
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog()
            {
                Filter = CodecFactory.SupportedFilesFilterEn,
                Title  = "Select a file..."
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Stop();

                const FftSize fftSize = FftSize.Fft4096;

                IWaveSource source = CodecFactory.Instance.GetCodec(openFileDialog.FileName);

                var spectrumProvider = new BasicSpectrumProvider(source.WaveFormat.Channels,
                                                                 source.WaveFormat.SampleRate, fftSize);
                _lineSpectrum = new LineSpectrum(fftSize)
                {
                    SpectrumProvider = spectrumProvider,
                    UseAverage       = true,
                    BarCount         = 50,
                    BarSpacing       = 2,
                    IsXLogScale      = true,
                    ScalingStrategy  = ScalingStrategy.Sqrt
                };
                _voicePrint3DSpectrum = new VoicePrint3DSpectrum(fftSize)
                {
                    SpectrumProvider = spectrumProvider,
                    UseAverage       = true,
                    PointCount       = 200,
                    IsXLogScale      = true,
                    ScalingStrategy  = ScalingStrategy.Sqrt
                };

                var notificationSource = new SingleBlockNotificationStream(source.ToSampleSource());
                notificationSource.SingleBlockRead += (s, a) => spectrumProvider.Add(a.Left, a.Right);

                _source = notificationSource.ToWaveSource(16);

                _soundOut = new WasapiOut();
                _soundOut.Initialize(_source.ToMono());
                _soundOut.Play();

                timer1.Start();

                propertyGridTop.SelectedObject    = _lineSpectrum;
                propertyGridBottom.SelectedObject = _voicePrint3DSpectrum;
            }
        }
コード例 #23
0
ファイル: MainGame.cs プロジェクト: MackinnonBuck/real-vis
        void SetupSampleSource(ISampleSource sampleSource)
        {
            FftSize fftSize = FftSize.Fft4096;

            SpectrumProvider spectrumProvider = new SpectrumProvider(sampleSource.WaveFormat.Channels,
                sampleSource.WaveFormat.SampleRate, fftSize);

            //spectrum = new BlobSpectrum(this, spectrumProvider, FftSize.Fft4096);
            spectrum = new RLSpectrum(this, spectrumProvider, FftSize.Fft4096);

            SingleBlockNotificationStream notificationSource = new SingleBlockNotificationStream(sampleSource);
            notificationSource.SingleBlockRead += (s, a) => spectrumProvider.Add(a.Left, a.Right);

            source = notificationSource.ToWaveSource(16);
        }
コード例 #24
0
ファイル: FftProvider.cs プロジェクト: hoangduit/cscore
        /// <summary>
        /// Initializes a new instance of the <see cref="FftProvider"/> class.
        /// </summary>
        /// <param name="channels">Number of channels of the input data.</param>
        /// <param name="fftSize">The number of bands to use.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="channels"/> is less than zero.</exception>
        public FftProvider(int channels, FftSize fftSize)
        {
            if(channels < 1)
                throw new ArgumentOutOfRangeException("channels");
            var exponent = Math.Log((int)fftSize, 2);
            // ReSharper disable CompareOfFloatsByEqualityOperator
            if (exponent % 1 != 0 || exponent == 0)
            // ReSharper restore CompareOfFloatsByEqualityOperator
                throw new ArgumentOutOfRangeException("fftSize");

            _channels = channels;
            _fftSize = fftSize; //todo: add validation for the fftSize parameter.
            _fftSizeExponent = (int)exponent;
            _storedSamples = new Complex[(int) fftSize];
        }
コード例 #25
0
        public LineSpectrum(Frame frame, FftSize size, BasicSpectrumProvider provider)
        {
            Frame       = frame;
            FftSize     = (int)size;
            MaxFftIndex = FftSize / 2 - 1;

            SpectrumProvider = provider;

            Amplifier = 1;

            MinimumFrequency = 20;
            MaximumFrequency = 20000;

            SpectrumResolution = MatrixPanel.Width;

            UpdateFrequencyMapping();
        }
コード例 #26
0
ファイル: SoundEffect.cs プロジェクト: jetgarcia/TTController
        public SoundEffect(SoundEffectConfig config) : base(config)
        {
            _soundIn = new WasapiLoopbackCapture();
            _soundIn.Initialize();

            var soundInSource = new SoundInSource(_soundIn);
            var sampleSource  = soundInSource.ToSampleSource();

            const FftSize fftSize = FftSize.Fft1024;

            _fftBuffer        = new float[(int)fftSize];
            _spectrumProvider = new SpectrumProvider(sampleSource.WaveFormat.Channels, sampleSource.WaveFormat.SampleRate, fftSize);

            var notificationSource = new DataNotificationSource(sampleSource);

            notificationSource.DataRead += (s, e) => _spectrumProvider.Add(e.Data, e.Data.Length);

            var waveSource = notificationSource.ToWaveSource(16);
            var buffer     = new byte[waveSource.WaveFormat.BytesPerSecond / 2];

            soundInSource.DataAvailable += (s, e) => { while (waveSource.Read(buffer, 0, buffer.Length) > 0)
                                                       {
                                                           ;
                                                       }
            };

            _spectrum = new LedSpectrum(GenerateColor)
            {
                FftSize            = fftSize,
                SpectrumProvider   = _spectrumProvider,
                UseAverage         = Config.UseAverage,
                MinimumFrequency   = Config.MinimumFrequency,
                MaximumFrequency   = Config.MaximumFrequency,
                ScalingStrategy    = Config.ScalingStrategy,
                ScalingFactor      = Config.ScalingFactor,
                IsXLogScale        = false,
                SpectrumResolution = (int)fftSize
            };

            _spectrum.UpdateFrequencyMapping();
            _soundIn.Start();
        }
コード例 #27
0
        /// <summary>
        /// Setup the spectrum analyzer
        /// </summary>
        public static void SetupSampleSource(ISampleSource aSampleSource)
        {
            FFTSize          = FftSize.Fft2048;
            SpectrumProvider = new BasicSpectrumProvider(aSampleSource.WaveFormat.Channels, aSampleSource.WaveFormat.SampleRate, FFTSize);

            m_SpectrumAnalyzer = new SpectrumAnalyzer(FFTSize)
            {
                SpectrumProvider = SpectrumProvider,
                UseAverage       = true,
                BarCount         = NumberOfAnalysisBars,
                UseLogScale      = true,
                ScalingStrategy  = ScalingStrategy.Sqrt
            };

            var notificationSource = new SingleBlockNotificationStream(aSampleSource);

            notificationSource.SingleBlockRead += (s, a) => SpectrumProvider.Add(a.Left, a.Right);

            m_Source = notificationSource.ToWaveSource(16);
        }
コード例 #28
0
ファイル: FftProvider.cs プロジェクト: wangfu91/Visualizer
        /// <summary>
        /// Initializes a new instance of the <see cref="FftProvider"/> class.
        /// </summary>
        /// <param name="channels">Number of channels of the input data.</param>
        /// <param name="fftSize">The number of bands to use.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="channels"/> is less than zero.</exception>
        public FftProvider(int channels, FftSize fftSize)
        {
            if (channels < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(channels));
            }
            var exponent = Math.Round(Math.Log((int)fftSize, 2));

            // ReSharper disable CompareOfFloatsByEqualityOperator
            if (exponent % 1 != 0 || exponent == 0)
            {
                // ReSharper restore CompareOfFloatsByEqualityOperator
                throw new ArgumentOutOfRangeException(nameof(fftSize));
            }

            _channels        = channels;
            _fftSize         = fftSize; //todo: add validation for the fftSize parameter.
            _fftSizeExponent = (int)exponent;
            _storedSamples   = new Complex[(int)fftSize];
        }
コード例 #29
0
        void StartCapture()
        {
            capture = new WasapiLoopbackCapture();
            capture.Initialize();
            IWaveSource source = new SoundInSource(capture);

            fftSize     = FftSize.Fft2048;
            fftBuffer   = new float[2048];
            fftBuffer   = new float[(int)fftSize];
            fftProvider = new FftProvider(1, fftSize);

            notificationSource = new SingleBlockNotificationStream(source.ToSampleSource());
            notificationSource.SingleBlockRead += SingleBlockRead;
            finalSource = notificationSource.ToWaveSource();

            capture.DataAvailable += CaptureDataAvailable;
            capture.Start();

            initialized = true;
        }
コード例 #30
0
        private void SetupSampleSource(ISampleSource aSampleSource)
        {
            const FftSize fftSize          = FftSize.Fft128;
            var           spectrumProvider = new BasicSpectrumProvider(aSampleSource.WaveFormat.Channels,
                                                                       aSampleSource.WaveFormat.SampleRate, fftSize);

            _lineSpectrum = new LineSpectrum(fftSize)
            {
                SpectrumProvider = spectrumProvider,
                UseAverage       = true,
                BarCount         = 50,
                BarSpacing       = 2,
                IsXLogScale      = true,
                ScalingStrategy  = ScalingStrategy.Linear
            };
            var notificationSource = new SingleBlockNotificationStream(aSampleSource);

            notificationSource.SingleBlockRead += (s, a) => spectrumProvider.Add(a.Left, a.Right);
            _source = notificationSource.ToWaveSource(16);
        }
コード例 #31
0
        public void LoadFile(string filePath, int resoulution = 9, FftSize fftSize = FftSize.Fft256)
        {
            var source = CodecFactory.Instance.GetCodec(filePath).ToSampleSource();

            NotificationStream = new SingleBlockNotificationStream(source);
            NotificationStream.SingleBlockRead += (s, a) =>
            {
                SpectrumProvider.Add(a.Left, a.Right);
            };

            SpectrumProvider = new BasicSpectrumProvider(source.WaveFormat.Channels, source.WaveFormat.SampleRate, fftSize);
            Spectrum         = new SpectrumBase()
            {
                SpectrumProvider   = SpectrumProvider,
                SpectrumResolution = resoulution,
                MaximumFrequency   = 20000,
                MinimumFrequency   = 20,
                ScalingStrategy    = ScalingStrategy.Linear,
                UseAverage         = true,
            };
        }
コード例 #32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FftProvider"/> class.
        /// </summary>
        /// <param name="channels">Number of channels of the input data.</param>
        /// <param name="fftSize">The number of bands to use.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="channels"/> is less than zero.</exception>
        public CustomFftProvider(int channels, FftSize fftSize, WindowFunction windowFunction)
        {
            if (channels < 1)
            {
                throw new ArgumentOutOfRangeException("channels");
            }
            var exponent = Math.Log((int)fftSize, 2);

            // ReSharper disable CompareOfFloatsByEqualityOperator
            if (exponent % 1 != 0 || exponent == 0)
            {
                // ReSharper restore CompareOfFloatsByEqualityOperator
                throw new ArgumentOutOfRangeException("fftSize");
            }

            _channels        = channels;
            _fftSize         = fftSize;
            _fftSizeExponent = (int)exponent;
            _storedSamples   = new Complex[(int)fftSize];

            WindowFunction = windowFunction;
        }
コード例 #33
0
        private bool Initialize()
        {
            if (_initialized)
            {
                return(true);
            }

            var currentTicks = Environment.TickCount;

            if (currentTicks - _lastInitializeTickCount < 1000)
            {
                return(false);
            }
            _lastInitializeTickCount = currentTicks;

            try
            {
                _soundIn = new WasapiLoopbackCapture();
                _soundIn.Initialize();
            }
            catch (Exception e)
            {
                Logger.Debug(e, "Failed to initialize WasapiLoopbackCapture!");
                return(false);
            }

            Logger.Debug($"Initialized WasapiLoopbackCapture on \"{_soundIn.Device.FriendlyName}\"");

            var soundInSource = new SoundInSource(_soundIn);
            var sampleSource  = soundInSource.ToSampleSource();

            const FftSize fftSize = FftSize.Fft1024;

            _fftBuffer        = new float[(int)fftSize];
            _spectrumProvider = new SpectrumProvider(sampleSource.WaveFormat.Channels, sampleSource.WaveFormat.SampleRate, fftSize);

            var notificationSource = new DataNotificationSource(sampleSource);

            notificationSource.DataRead += (s, e) => _spectrumProvider.Add(e.Data, e.Data.Length);

            var waveSource = notificationSource.ToWaveSource(16);
            var buffer     = new byte[waveSource.WaveFormat.BytesPerSecond / 2];

            soundInSource.DataAvailable += (s, e) => { while (waveSource.Read(buffer, 0, buffer.Length) > 0)
                                                       {
                                                           ;
                                                       }
            };

            _spectrum = new LedSpectrum(Config.ColorGradient)
            {
                FftSize          = fftSize,
                SpectrumProvider = _spectrumProvider,
                UseAverage       = Config.UseAverage,
                MinimumFrequency = Config.MinimumFrequency,
                MaximumFrequency = Config.MaximumFrequency,
                ScalingStrategy  = Config.ScalingStrategy,
                ScalingFactor    = Config.ScalingFactor,
                IsXLogScale      = false
            };

            _soundIn.Start();

            _initialized = true;
            return(true);
        }
コード例 #34
0
ファイル: FFTHandler.cs プロジェクト: codyohlsen/SuiteLights
 public FFTHandler(FftSize fftSize)
 {
     FftSize = fftSize;
 }
コード例 #35
0
ファイル: LineSpectrum.cs プロジェクト: opcon/cscore
 public LineSpectrum(FftSize fftSize)
 {
     FftSize = fftSize;
 }