我有一個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