Java 使用apache';s FFT将.wav文件转换为freq数组

Java 使用apache';s FFT将.wav文件转换为freq数组,java,fft,Java,Fft,以下是我目前掌握的情况: InputStream is = AudioSystem.getAudioInputStream(new File("C:/users/barnao/desktop/uotm.wav")); byte[] bytes = IOUtils.toByteArray(is); short[] shorts = new short[bytes.length/2]; ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).as

以下是我目前掌握的情况:

InputStream is = AudioSystem.getAudioInputStream(new File("C:/users/barnao/desktop/uotm.wav"));
byte[] bytes = IOUtils.toByteArray(is);

short[] shorts = new short[bytes.length/2];
ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts);

double[] vals = new double[shorts.length];
for (int i = 0; i < shorts.length; i++)
    vals[i] = (double) shorts[i];

FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
Complex[] freqs = fft.transform(vals, TransformType.FORWARD);

如何解决此问题?

您不想对整个文件进行FFT处理-通常,您会进行一系列重叠的固定大小FFT(例如,N=2048),也称为STFTs序列,也称为光谱图。啊,好的,对于样本大小或STFTs的距离有什么标准吗?我有一系列的缺点,例如(FFT 1024个元素,间隔512?)我意识到这不是一个特别有用的答案,但它确实取决于你的目标是什么。FFT在这里甚至可能不是正确的工具。
Exception in thread "main" org.apache.commons.math3.exception.MathIllegalArgumentException: 31,590,166 is not a power of 2, consider padding for fix