private final void printError() { SharedCommandLineUtilities.printPrefix(); System.err.println("Name:"); System.err.println("\tTarsosDSP resynthesizer"); SharedCommandLineUtilities.printLine(); System.err.println("Synopsis:"); System.err.println( "\tjava -jar CommandLineResynthesizer.jar [--detector DETECTOR] [--output out.wav] [--combined combined.wav] input.wav"); SharedCommandLineUtilities.printLine(); System.err.println("Description:"); System.err.println( "\tExtracts pitch and loudnes from audio and resynthesises the audio with that information.\n\t" + "The result is either played back our written in an output file. \n\t" + "There is als an option to combine source and synthezized material\n\t" + "in the left and right channels of a stereo audio file."); String descr = ""; descr += "\n\n\tinput.wav\t\ta readable wav file."; descr += "\n\n\t--output out.wav\t\ta writable file."; descr += "\n\n\t--combined combined.wav\t\ta writable output file. One channel original, other synthesized."; descr += "\n\t--detector DETECTOR\tdefaults to FFT_YIN or one of these:\n\t\t\t\t"; for (PitchEstimationAlgorithm algo : PitchEstimationAlgorithm.values()) { descr += algo.name() + "\n\t\t\t\t"; } System.err.println(descr); }
@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); } }