Exemplo n.º 1
0
 private void OpenFile(string fileName)
 {
     try
     {
         var inputStream = new AudioFileReader(fileName);
         fileStream = inputStream;
         var aggregator = new SampleAggregator(inputStream);
         aggregator.NotificationCount  = inputStream.WaveFormat.SampleRate / 10;
         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();
     }
 }
Exemplo n.º 2
0
 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();
     }
 }
        public SoundProcessor(string fileName)
        {
            try
            {
                var inputStream = new AudioFileReader(fileName);
                _fileStream        = inputStream;
                _fftSampleProvider = new FftSampleProvider(inputStream);
                _fftSampleProvider.FftCalculated += (result) => FftCalculated?.Invoke(result);

                _playbackDevice = new WaveOut {
                    DesiredLatency = 200
                };
                _playbackDevice.Init(_fftSampleProvider);
            }
            catch (Exception ex)
            {
                CloseFile();
                throw ex;
            }
        }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
0
        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;
            }
        }
Exemplo n.º 6
0
 protected virtual void OnFftCalculated(SampleProcessor.FftEventArgs e)
 {
     FftCalculated?.Invoke(this, e);
 }
Exemplo n.º 7
0
 protected virtual void OnFftCalculated(FftEventArgs e)
 {
     FftCalculated?.Invoke(this, e);
 }