private void Add(float value) { if (PerformFFT && FftCalculated != null) { fftBuffer[fftPos].X = /*value;//*/ (float)(value * FastFourierTransform.BlackmannHarrisWindow(fftPos, fftLength)); fftBuffer[fftPos].Y = 0; fftPos++; if (fftPos >= fftBuffer.Length) { fftPos = 0; // 1024 = 2^10 FastFourierTransform.FFT(true, m, fftBuffer); for (int i = 0; i < fftBuffer.Length; i++) { Complex c = fftBuffer[i]; double intensityDB = (4 + Math.Log(Math.Sqrt(c.X * c.X + c.Y * c.Y), 16)) / 4; //double minDB = -32; //if (intensityDB < minDB) intensityDB = minDB; //double percent =- (intensityDB - minDB) / minDB; double percent = Math.Max(0, intensityDB); _spectrum[i] = (float)Math.Max(_spectrum[i] - downspeed, percent); } FftCalculated(this, fftArgs); } } maxValue = Math.Max(maxValue, value); minValue = Math.Min(minValue, value); count++; if (count >= NotificationCount && NotificationCount > 0) { MaximumCalculated?.Invoke(this, new MaxSampleEventArgs(minValue, maxValue)); Reset(); } }
private void Add(float value) { if (PerformFFT && FftCalculated != null) { fftBuffer[fftPos].X = (float)(value * FastFourierTransform.HammingWindow(fftPos, fftLength)); fftBuffer[fftPos].Y = 0; fftPos++; if (fftPos >= fftBuffer.Length) { fftPos = 0; // 1024 = 2^10 FastFourierTransform.FFT(true, m, fftBuffer); FftCalculated(this, fftArgs); } } maxValue = Math.Max(maxValue, value); minValue = Math.Min(minValue, value); count++; if (count >= NotificationCount && NotificationCount > 0) { MaximumCalculated?.Invoke(this, new MaxSampleEventArgs(minValue, maxValue)); Reset(); } }
private void Add(float value) { if (PerformFFT && FftCalculated != null) { _fftBuffer[_fftPos].X = (float)(value * FastFourierTransform.HammingWindow(_fftPos, _fftLength)); _fftBuffer[_fftPos].Y = 0; _fftPos++; if (_fftPos >= _fftBuffer.Length) { _fftPos = 0; FastFourierTransform.FFT(true, _dim, _fftBuffer); FftCalculated(this, _fftArgs); } } _maxValue = Math.Max(_maxValue, value); _minValue = Math.Min(_minValue, value); _count++; if (_count >= NotificationCount && NotificationCount > 0) { MaximumCalculated?.Invoke(this, new MaxSampleEventArgs(_minValue, _maxValue)); Reset(); } }
public void Add(float value) { maxValue = Math.Max(maxValue, value); minValue = Math.Min(minValue, value); count++; if (count >= NotificationCount && NotificationCount > 0) { MaximumCalculated?.Invoke(this, new MaxSampleEventArgs(minValue, maxValue)); Reset(); } }
public void Add(float value) { this.maxValue = Math.Max(this.maxValue, value); this.minValue = Math.Min(this.minValue, value); this.count++; if (this.count >= this.NotificationCount && this.NotificationCount > 0) { MaximumCalculated?.Invoke(this, new MaxSampleEventArgs(this.minValue, this.maxValue)); this.Reset(); } }
public void Add(float value) { _maxValue = Math.Max(_maxValue, value); _minValue = Math.Min(_minValue, value); _count++; if (_count < NotificationCount || NotificationCount <= 0) { return; } MaximumCalculated?.Invoke(this, new MaxSampleEventArgs(_minValue, _maxValue)); Reset(); }
private void Add(float value) { _maxValue = Math.Max(_maxValue, value); _minValue = Math.Min(_minValue, value); _count++; if (_count >= NotificationCount && NotificationCount > 0) { if (MaximumCalculated != null) { MaximumCalculated.Invoke(this, new MaxSampleEventArgs(_minValue, _maxValue)); } Reset(); } }
private void OpenFile(string fileName) { try { var inputStream = new AudioFileReader(fileName); fileStream = inputStream; var aggregator = new SampleAggregator(inputStream); aggregator.NotificationCount = inputStream.WaveFormat.SampleRate / 100; aggregator.PerformFFT = true; aggregator.FftCalculated += (s, a) => FftCalculated?.Invoke(this, a); aggregator.MaximumCalculated += (s, a) => MaximumCalculated?.Invoke(this, a); playbackDevice.Init(aggregator); } catch (Exception e) { MessageBox.Show(e.Message, "Problem opening file"); CloseFile(); } }
public AudioEngine(string fileName) { try { var inputStream = new AudioFileReader(fileName); fileStream = inputStream; var aggregator = new SampleAggregator(inputStream) { NotificationCount = inputStream.WaveFormat.SampleRate / 100, PerformFFT = true }; aggregator.FftCalculated += (s, a) => FftCalculated?.Invoke(this, a); aggregator.MaximumCalculated += (s, a) => MaximumCalculated?.Invoke(this, a); } catch (Exception e) { Console.WriteLine(e.Message, "Problem opening file"); CloseFile(); } }
private void OpenFile(string fileName) { try { var inputStream = new MediaFoundationReader(fileName); fileStream = inputStream; SampleAggregator = new SampleAggregator(fileStream.ToSampleProvider()); SampleAggregator.NotificationCount = inputStream.WaveFormat.SampleRate / 100; SampleAggregator.PerformFFT = true; SampleAggregator.FftCalculated += (s, a) => FftCalculated?.Invoke(this, a); SampleAggregator.MaximumCalculated += (s, a) => MaximumCalculated?.Invoke(this, a); Volume = 0.5f; playbackDevice.Volume = Volume; playbackDevice.Init(SampleAggregator); } catch (Exception e) { MessageBox.Show(e.Message, "Проблема открытия файла"); CloseFile(); } }
public void Add(float value) { if (PerformFFT && FftCalculated != null) { fftBuffer[fftPos].X = value * (float)FastFourierTransform.HammingWindow(fftPos, fftLength); fftBuffer[fftPos].Y = 0; fftPos++; if (fftPos >= fftLength) { fftPos = 0; // 1024 = 2^10 FastFourierTransform.FFT(true, 10, fftBuffer); //intesities for (int i = 0; i < fftLength / 2; i += 2) { // Calculate actual intensities for the FFT results. fftOutputBuffer[i] = (float)Math.Sqrt(fftBuffer[i].X * fftBuffer[i].X + fftBuffer[i].Y * fftBuffer[i].Y); //fftOutputBuffer[i] = fftBuffer[i].X; //Real fftOutputBuffer[i + 1] = fftBuffer[i].Y; //Complex } FftCalculated(this, new FftEventArgs(fftOutputBuffer)); } } maxValue = Math.Max(maxValue, value); minValue = Math.Min(minValue, value); count++; if (count >= fftLength) { MaximumCalculated?.Invoke(this, new MaxSampleEventArgs(minValue, maxValue)); Reset(); } }
private void OpenFile(string fileName, bool isVorbis = false) { try { if (isVorbis) { var inputStream = new VorbisWaveReader(fileName); fileStream = inputStream; var aggregator = new AudioSampleAggregator(inputStream); aggregator.NotificationCount = inputStream.WaveFormat.SampleRate / 100; aggregator.PerformFFT = true; aggregator.FftCalculated += (s, a) => FftCalculated?.Invoke(this, a); aggregator.MaximumCalculated += (s, a) => MaximumCalculated?.Invoke(this, a); playbackDevice.Init(aggregator); playbackDevice.PlaybackStopped += OnPlaybackStopped; } else { var inputStream = new AudioFileReader(fileName); fileStream = inputStream; var aggregator = new AudioSampleAggregator(inputStream); aggregator.NotificationCount = inputStream.WaveFormat.SampleRate / 100; aggregator.PerformFFT = true; aggregator.FftCalculated += (s, a) => FftCalculated?.Invoke(this, a); aggregator.MaximumCalculated += (s, a) => MaximumCalculated?.Invoke(this, a); playbackDevice.Init(aggregator); playbackDevice.PlaybackStopped += OnPlaybackStopped; } } catch (Exception) { CloseFile(); throw; } }
protected virtual void OnMaximumCalculated(MaxSampleEventArgs e) { MaximumCalculated?.Invoke(this, e); }