@Override public void actionPerformed(final ActionEvent e) { String name = e.getActionCommand(); PitchEstimationAlgorithm newAlgo = PitchEstimationAlgorithm.valueOf(name); algo = newAlgo; if (currentFile != null) { estimationDispatcher.stop(); sourceDispatcher.stop(); startFile(currentFile); } }
@Override public void actionPerformed(final ActionEvent e) { String name = e.getActionCommand(); PitchEstimationAlgorithm newAlgo = PitchEstimationAlgorithm.valueOf(name); algo = newAlgo; try { setNewMixer(currentMixer); } catch (LineUnavailableException e1) { e1.printStackTrace(); } catch (UnsupportedAudioFileException e1) { e1.printStackTrace(); } }
private void run(String[] args) throws UnsupportedAudioFileException, IOException, IllegalArgumentException, LineUnavailableException { PitchEstimationAlgorithm algo = PitchEstimationAlgorithm.FFT_YIN; String inputFile = args[0]; String outputFile = null; String combinedFile = null; if (args.length == 3 && args[0].equalsIgnoreCase("--detector")) { algo = PitchEstimationAlgorithm.valueOf(args[1].toUpperCase()); inputFile = args[2]; } else if (args.length == 3 && args[0].equalsIgnoreCase("--output")) { outputFile = args[1]; inputFile = args[2]; } else if (args.length == 5 && args[0].equalsIgnoreCase("--detector") && args[2].equalsIgnoreCase("--output")) { algo = PitchEstimationAlgorithm.valueOf(args[1].toUpperCase()); outputFile = args[3]; inputFile = args[4]; } else if (args.length == 7 && args[0].equalsIgnoreCase("--detector") && args[2].equalsIgnoreCase("--output") && args[4].equalsIgnoreCase("--combined")) { algo = PitchEstimationAlgorithm.valueOf(args[1].toUpperCase()); outputFile = args[3]; combinedFile = args[5]; inputFile = args[6]; } else if (args.length != 1) { printError(); SharedCommandLineUtilities.printLine(); System.err.println("Current error:"); System.err.println( "\tThe command expects the options in the specified order, the current command is not parsed correctly!"); return; } File audioFile = new File(inputFile); AudioFormat format = AudioSystem.getAudioFileFormat(audioFile).getFormat(); float samplerate = format.getSampleRate(); int size = 1024; int overlap = 0; PitchResyntheziser prs = new PitchResyntheziser(samplerate); AudioDispatcher dispatcher = AudioDispatcher.fromFile(audioFile, size, overlap); dispatcher.addAudioProcessor(new PitchProcessor(algo, samplerate, size, prs)); if (outputFile != null) { dispatcher.addAudioProcessor(new WaveformWriter(format, outputFile)); } else { dispatcher.addAudioProcessor(new AudioPlayer(format)); } dispatcher.addAudioProcessor( new AudioProcessor() { @Override public void processingFinished() {} @Override public boolean process(AudioEvent audioEvent) { System.err.print(String.format("%3.0f %%", audioEvent.getProgress() * 100)); System.err.print(String.format("\b\b\b\b\b", audioEvent.getProgress())); return true; } }); dispatcher.run(); if (combinedFile != null) { combineTwoMonoAudioFilesInTwoChannels(inputFile, outputFile, combinedFile); } }