我正在研究我的最终项目,因此我需要阅读wav文件 - 我成功了。
当我在java中运行代码时,花费的时间不到1秒,但是当我尝试在Nexus 5上运行代码时,花费将近1分钟!!
将(sb.get(i))
复制到original_signal[i]
需要花费大量时间。
for (int i = 0; i < 1710080; i++) {
original_signal[i] = (sb.get(i));
}
请,需要帮助, 感谢!!!
public static void jjjj(){
String filepath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ilia.wav";
Wave wave = new Wave(filepath);
byte[] arr = wave.getBytes();
System.out.println();
wave.length();
ByteBuffer bb = ByteBuffer.wrap(arr);
System.out.println(bb.capacity());
bb.order(ByteOrder.LITTLE_ENDIAN);
ShortBuffer sb = bb.asShortBuffer();
original_signal = new double[1710080];
// double firstSample;
//THIS FOR LOOP TAKE A LOF OF TIME
for (int i = 0; i < 1710080; i++) {
original_signal[i] = (sb.get(i));
}
System.out.println("sss");
}
我解决了问题
Wave wave = new Wave(filepath);
double[] original_signal = wave.getNormalizedAmplitudes();
System.out.println(wave.getWaveHeader());
Parameters.Fs = wave.getWaveHeader().getSampleRate();
return original_signal;