private void openToolStripMenuItem_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog(); if (ofd.ShowDialog() != DialogResult.OK) { return; } using (var stream = new FileStream(ofd.FileName, FileMode.Open)) { var waveFile = new WaveFile(stream); _signal = waveFile[Channels.Left]; } _stft = new Stft(_frameSize, _hopSize); var frameDuration = (double)_frameSize / _signal.SamplingRate; var hopDuration = (double)_hopSize / _signal.SamplingRate; var freqs = new[] { 300f, 600, 1000, 2000, 4000, 7000 }; var pitchExtractor = new PitchExtractor(_signal.SamplingRate, frameDuration, hopDuration, high: 900 /*Hz*/); var pitchTrack = pitchExtractor.ParallelComputeFrom(_signal) .Select(p => p.Features[0]) .ToArray(); var tdExtractor = new TimeDomainFeaturesExtractor(_signal.SamplingRate, "all", frameDuration, hopDuration); var spectralExtractor = new SpectralFeaturesExtractor(_signal.SamplingRate, "sc+sn", frameDuration, hopDuration, frequencies: freqs); var mpeg7Extractor = new Mpeg7SpectralFeaturesExtractor(_signal.SamplingRate, "all", frameDuration, hopDuration); mpeg7Extractor.IncludeHarmonicFeatures("all"); mpeg7Extractor.SetPitchTrack(pitchTrack); tdExtractor.AddFeature("pitch_zcr", (signal, start, end) => { return(Pitch.FromZeroCrossingsSchmitt(signal, start, end)); }); //spectralExtractor.AddFeature("pitch_hss", (spectrum, fs) => { return Pitch.FromHss(spectrum, _signal.SamplingRate); } ); var tdVectors = tdExtractor.ParallelComputeFrom(_signal); var spectralVectors = spectralExtractor.ParallelComputeFrom(_signal); var mpeg7Vectors = mpeg7Extractor.ParallelComputeFrom(_signal); _vectors = FeaturePostProcessing.Join(tdVectors, spectralVectors, mpeg7Vectors); //FeaturePostProcessing.NormalizeMean(_vectors); //FeaturePostProcessing.AddDeltas(_vectors); var descriptions = tdExtractor.FeatureDescriptions .Concat(spectralExtractor.FeatureDescriptions) .Concat(mpeg7Extractor.FeatureDescriptions); FillFeaturesList(_vectors, descriptions); spectrogramPlot.ColorMapName = "afmhot"; spectrogramPlot.MarklineThickness = 2; spectrogramPlot.Spectrogram = _stft.Spectrogram(_signal); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog(); if (ofd.ShowDialog() != DialogResult.OK) { return; } using (var stream = new FileStream(ofd.FileName, FileMode.Open)) { var waveFile = new WaveFile(stream); _signal = waveFile[Channels.Left]; } _fftSize = int.Parse(fftSizeTextBox.Text); _cepstrumSize = int.Parse(cepstrumSizeTextBox.Text); _hopSize = int.Parse(hopSizeTextBox.Text); _fft = new RealFft(_fftSize); _cepstralTransform = new CepstralTransform(_cepstrumSize, _fftSize); var options = new PitchOptions { SamplingRate = _signal.SamplingRate, FrameDuration = (double)_fftSize / _signal.SamplingRate, HopDuration = (double)_hopSize / _signal.SamplingRate }; var pitchExtractor = new PitchExtractor(options); _pitches = pitchExtractor.ParallelComputeFrom(_signal); _specNo = 0; specNoComboBox.DataSource = Enumerable.Range(1, _pitches.Count).ToArray(); // obtain spectrogram _stft = new Stft(_fftSize, _hopSize, WindowTypes.Rectangular); var spectrogram = _stft.Spectrogram(_signal); spectrogramPanel.ColorMapName = "viridis"; spectrogramPanel.MarklineThickness = 6; spectrogramPanel.Spectrogram = spectrogram.Select(s => s.Take(224).ToArray()).ToList(); spectrogramPanel.Markline = _pitches.Select(p => p[0] * _fftSize / _signal.SamplingRate).ToArray(); }
public async void StartRecording() { if (_recorder != null) { StopRecording(); } var context = Android.App.Application.Context; var audioManager = (AudioManager)context.GetSystemService(Context.AudioService); _samplingRate = int.Parse(audioManager.GetProperty(AudioManager.PropertyOutputSampleRate)); //_bufferSize = 4 * AudioRecord.GetMinBufferSize(_samplingRate, ChannelIn.Mono, Encoding.PcmFloat); _bufferSize = 4 * AudioRecord.GetMinBufferSize(_samplingRate, ChannelIn.Mono, Encoding.Pcm16bit); _recorder = new AudioRecord(AudioSource.Mic, _samplingRate, _channelCount, _audioEncodingType, _bufferSize); //uncomment for PcmFloat mode: ===================== //_sizeInFloats = _bufferSize / sizeof(float); //instead of Pcm16bit: ============================= _sizeInFloats = _bufferSize / sizeof(short); _data = new float[1][]; _data[0] = new float[_sizeInFloats]; // only one channel (mono) _bytes = new byte[_bufferSize]; _temp = new byte[_sizeInFloats * sizeof(float)]; var options = new PitchOptions { SamplingRate = _samplingRate, FrameDuration = (double)_sizeInFloats / _samplingRate }; _pitchExtractor = new PitchExtractor(options); _pitch = new float[1]; _robotizer = new RobotEffect(216, 1024); _recorder.StartRecording(); _isRecording = true; await ProcessAudioData(); }