我有一个 16 位 PCM 格式的波形文件。我在 a 中获得了原始数据byte[]
和一个提取样本的方法,我需要它们以浮点格式,即 afloat[]
来进行傅立叶变换。这是我的代码,这看起来对吗?我正在使用 Android,所以javax.sound.sampled
等不可用。
private static short getSample(byte[] buffer, int position) {
return (short) (((buffer[position + 1] & 0xff) << 8) | (buffer[position] & 0xff));
}
...
float[] samples = new float[samplesLength];
for (int i = 0;i<input.length/2;i+=2){
samples[i/2] = (float)getSample(input,i) / (float)Short.MAX_VALUE;
}