我希望使用TarsosDSP在Android中进行音高转换。这是我正在使用的代码,但是当我添加pitchshifter时,它将返回数组索引超出范围异常;我该如何调试呢?
在Android上使用TarsosDSP进行PitchShift的任何其他示例均受到赞赏new AndroidFFMPEGLocator(MainActivity.this);
String sourcefile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/UCDownloads/google.mp3";
File fileFromString=new File(sourcefile);
//String sourcefile=audioList.get(currentSongIndex).getData();
File inputFile = new File(sourcefile);
double sampleRate = 44100;
double factor = 1;
RateTransposer rateTransposer = new RateTransposer(factor);
final int size = 2048;
final int overlap = 2048 - 128;
WaveformSimilarityBasedOverlapAdd wsola=new WaveformSimilarityBasedOverlapAdd(WaveformSimilarityBasedOverlapAdd.Parameters.musicDefaults(factor,sampleRate));
AudioDispatcher audioDispatcher = AudioDispatcherFactory.fromPipe(sourcefile, 44100, wsola.getInputBufferSize(), wsola.getOverlap());
audioDispatcher.addAudioProcessor(new MultichannelToMono(1,true));
wsola.setDispatcher(audioDispatcher);
audioDispatcher.addAudioProcessor(wsola);
PitchShifter pitchShifter=new PitchShifter(1.0/factor,44100,wsola.getInputBufferSize(),wsola.getOverlap());
System.out.println("input buffer size : "+wsola.getInputBufferSize()+" &^&&*^(&^&*^&(^&^&^&(^&^^&^^&^%$%^$%^$&^%$$%$%$%$&%%$%$%$%^$%^$%^$%^$%");
System.out.println("input buffer size : "+wsola.getOverlap()+" &^&&*^(&^&*^&(^&^&^&(^&^^&^^&^%$%^$%^$&^%$$%$%$%$&%%$%$%$%^$%^$%^$%^$%");
audioDispatcher.addAudioProcessor(rateTransposer);
audioDispatcher.addAudioProcessor(pitchShifter);
try {
RandomAccessFile outputFile=new RandomAccessFile("/storage/emulated/0/UCDownloads/google_pitch.mp3","rw");
TarsosDSPAudioFormat outputFormat=new TarsosDSPAudioFormat(44100,16,1,true,false);
WriterProcessor writer=new WriterProcessor(outputFormat,outputFile);
audioDispatcher.addAudioProcessor(writer);
audioDispatcher.run();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
});