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) { 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); 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); }