I have a wave file in 16 bit PCM form. I have the source data in byte[] and the method for extracting samples, and I need them in float format, i.e. A float[] for the Fourier transform. Here is my code, does it look right? I am working on Android, so javax.sound.sampled etc. Not available.
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; }
source share