我有一个16位PCM格式的波形文件。我得到了byte[]
中的原始数据和提取样本的方法,我需要它们的浮点格式,即float[]
做傅里叶变换。这是我的代码,这是否正确?我正在开发Android,因此javax.sound.sampled
等无法使用。将16位PCM波形数据转换为浮点数的正确方法
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;
}
看到它减去256乘以首先它之前也:http://stackoverflow.com/questions/15087668/how -to-convert-pcm-samples-in-byte-array-as-floating-point-numbers-in-the-range – Brad 2013-12-27 05:03:56