public static void Main(string[] argv) { ISampleProvider decoder = new AudioFileReader(FILE); SpectrumProvider spectrumProvider = new SpectrumProvider(decoder, 1024, HOP_SIZE, true); float[] spectrum = spectrumProvider.nextSpectrum(); float[] lastSpectrum = new float[spectrum.Length]; List <List <float> > spectralFlux = new List <List <float> >(); for (int i = 0; i < bands.Length / 2; i++) { spectralFlux.Add(new List <float>()); } do { for (int i = 0; i < bands.Length; i += 2) { int startFreq = spectrumProvider.getFFT().FreqToIndex(bands[i]); int endFreq = spectrumProvider.getFFT().FreqToIndex(bands[i + 1]); float flux = 0; for (int j = startFreq; j <= endFreq; j++) { float @value = (spectrum[j] - lastSpectrum[j]); @value = (@value + Math.Abs(@value)) / 2; flux += @value; } spectralFlux[i / 2].Add(flux); } System.Array.Copy(spectrum, 0, lastSpectrum, 0, spectrum.Length); } while((spectrum = spectrumProvider.nextSpectrum()) != null); List <List <float> > thresholds = new List <List <float> >(); for (int i = 0; i < bands.Length / 2; i++) { List <float> threshold = new ThresholdFunction(HISTORY_SIZE, multipliers[i]).calculate(spectralFlux[i]); thresholds.Add(threshold); } Plot plot = new Plot("Multiband Spectral Flux", 1024, 512); for (int i = 0; i < bands.Length / 2; i++) { plot.plot(spectralFlux[i], 1, -0.6f * (bands.Length / 2 - 2) + i, false, Color.Red); plot.plot(thresholds[i], 1, -0.6f * (bands.Length / 2 - 2) + i, true, Color.Green); } new PlaybackVisualizer(plot, HOP_SIZE, FILE); }
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) { ISampleProvider reader = new AudioFileReader("samples/sample.wav"); List <float> allSamples = new List <float>(); float[] samples = new float[1024]; while (reader.Read(samples, 0, samples.Length) > 0) { for (int i = 0; i < samples.Length; i++) { allSamples.Add(samples[i]); } } samples = new float[allSamples.Count]; for (int i = 0; i < samples.Length; i++) { samples[i] = allSamples[i]; } Plot plot = new Plot("Wave Plot", 512, 512); plot.plot(samples, 44100 / 1000, Color.Red); Application.Run(plot); }
public static void Main(string[] argv) { ISampleProvider decoder = new AudioFileReader(FILE); SpectrumProvider spectrumProvider = new SpectrumProvider(decoder, 1024, HOP_SIZE, true); float[] spectrum = spectrumProvider.nextSpectrum(); float[] lastSpectrum = new float[spectrum.Length]; List<float> spectralFlux = new List<float>(); do { 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); System.Array.Copy(spectrum, 0, lastSpectrum, 0, spectrum.Length); } while((spectrum = spectrumProvider.nextSpectrum()) != null); Plot plot = new Plot("Hopping Spectral Flux", 1024, 512); plot.plot(spectralFlux, 1, Color.Red); new PlaybackVisualizer(plot, HOP_SIZE, FILE); }
public static void Main(string[] argv) { ISampleProvider decoder = new AudioFileReader(FILE); SpectrumProvider spectrumProvider = new SpectrumProvider(decoder, 1024, HOP_SIZE, true); float[] spectrum = spectrumProvider.nextSpectrum(); float[] lastSpectrum = new float[spectrum.Length]; List <float> spectralFlux = new List <float>(); do { 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); System.Array.Copy(spectrum, 0, lastSpectrum, 0, spectrum.Length); } while((spectrum = spectrumProvider.nextSpectrum()) != null); Plot plot = new Plot("Hopping Spectral Flux", 1024, 512); plot.plot(spectralFlux, 1, Color.Red); new PlaybackVisualizer(plot, HOP_SIZE, FILE); }
public static void Main(string[] argv) { float[] samples = ReadInAllSamples(FILE); Plot plot = new Plot("Wave Plot", 1024, 512); plot.plot(samples, SAMPLE_WINDOW_SIZE, Color.Red); plot.Shown += new EventHandler(PlotShown); Application.Run(plot); }
public static void Main(string[] argv) { ISampleProvider decoder = new AudioFileReader(FILE); SpectrumProvider spectrumProvider = new SpectrumProvider(decoder, 1024, HOP_SIZE, true); float[] spectrum = spectrumProvider.nextSpectrum(); float[] lastSpectrum = new float[spectrum.Length]; List<List<float>> spectralFlux = new List<List<float>>(); for(int i = 0; i < bands.Length / 2; i++) { spectralFlux.Add(new List<float>()); } do { for(int i = 0; i < bands.Length; i+=2) { int startFreq = spectrumProvider.getFFT().FreqToIndex(bands[i]); int endFreq = spectrumProvider.getFFT().FreqToIndex(bands[i+1]); float flux = 0; for(int j = startFreq; j <= endFreq; j++) { float @value = (spectrum[j] - lastSpectrum[j]); @value = (@value + Math.Abs(@value))/2; flux += @value; } spectralFlux[i/2].Add(flux); } System.Array.Copy(spectrum, 0, lastSpectrum, 0, spectrum.Length); } while((spectrum = spectrumProvider.nextSpectrum()) != null); List<List<float>> thresholds = new List<List<float>>(); for(int i = 0; i < bands.Length / 2; i++) { List<float> threshold = new ThresholdFunction(HISTORY_SIZE, multipliers[i]).calculate(spectralFlux[i]); thresholds.Add(threshold); } Plot plot = new Plot("Multiband Spectral Flux", 1024, 512); for(int i = 0; i < bands.Length / 2; i++) { plot.plot(spectralFlux[i], 1, -0.6f * (bands.Length / 2 - 2) + i, false, Color.Red); plot.plot(thresholds[i], 1, -0.6f * (bands.Length / 2 - 2) + i, true, Color.Green); } new PlaybackVisualizer(plot, HOP_SIZE, FILE); }
public static void Main(string[] argv) { ISampleProvider reader = new AudioFileReader("samples/sample.wav"); List<float> allSamples = new List<float>(); float[] samples = new float[1024]; while(reader.Read(samples, 0, samples.Length) > 0) { for(int i = 0; i < samples.Length; i++) allSamples.Add(samples[i]); } samples = new float[allSamples.Count]; for(int i = 0; i < samples.Length; i++) samples[i] = allSamples[i]; Plot plot = new Plot("Wave Plot", 512, 512); plot.plot(samples, 44100 / 1000, 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) { 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); }