public static void Main(string[] argv) { ISampleProvider decoder = new AudioFileReader(FILE); FFT fft = new FFT(1024, 44100); float[] samples = new float[1024]; float[] spectrum = new float[1024 / 2 + 1]; float[] lastSpectrum = new float[1024 / 2 + 1]; List <float> spectralFlux = new List <float>(); while (decoder.Read(samples, 0, samples.Length) > 0) { fft.Forward(samples); System.Array.Copy(spectrum, 0, lastSpectrum, 0, spectrum.Length); System.Array.Copy(fft.GetSpectrum(), 0, spectrum, 0, spectrum.Length); float flux = 0; for (int i = 0; i < spectrum.Length; i++) { flux += (spectrum[i] - lastSpectrum[i]); } spectralFlux.Add(flux); } Plot plot = new Plot("Spectral Flux", 1024, 512); plot.plot(spectralFlux, 1, Color.Red); new PlaybackVisualizer(plot, 1024, FILE); //new PlaybackVisualizer(plot, spectralFlux.Count, FILE); }
public static void Main(string[] argv) { const float frequency = 440; // Note A float increment = (float)(2*Math.PI) * frequency / 44100; float angle = 0; float[] samples = new float[1024]; FFT fft = new FFT(1024, 44100); for(int i = 0; i < samples.Length; i++) { samples[i] = (float)Math.Sin(angle); angle += increment; } fft.Forward(samples); Plot plot = new Plot("Note A Spectrum", 512, 512); plot.plot(fft.GetSpectrum(), 1, Color.Red); Application.Run(plot); }
public static void Main(string[] argv) { const float frequency = 440; // Note A float increment = (float)(2 * Math.PI) * frequency / 44100; float angle = 0; float[] samples = new float[1024]; FFT fft = new FFT(1024, 44100); for (int i = 0; i < samples.Length; i++) { samples[i] = (float)Math.Sin(angle); angle += increment; } fft.Forward(samples); Plot plot = new Plot("Note A Spectrum", 512, 512); plot.plot(fft.GetSpectrum(), 1, Color.Red); Application.Run(plot); }
public static void Main(string[] argv) { ISampleProvider decoder = new AudioFileReader(FILE); FFT fft = new FFT(1024, 44100); fft.Window(FFT.HAMMING); float[] samples = new float[1024]; float[] spectrum = new float[1024 / 2 + 1]; float[] lastSpectrum = new float[1024 / 2 + 1]; List<float> spectralFlux = new List<float>(); while(decoder.Read(samples, 0, samples.Length) > 0) { fft.Forward(samples); System.Array.Copy(spectrum, 0, lastSpectrum, 0, spectrum.Length); System.Array.Copy(fft.GetSpectrum(), 0, spectrum, 0, spectrum.Length); float flux = 0; for(int i = 0; i < spectrum.Length; i++) { float @value = (spectrum[i] - lastSpectrum[i]); flux += @value < 0 ? 0 : @value; } spectralFlux.Add(flux); } Plot plot = new Plot("Hamming Spectral Flux", 1024, 512); plot.plot(spectralFlux, 1, Color.Red); new PlaybackVisualizer(plot, 1024, FILE); }