I've found here on stackoverflow.com a great example that actually works for playing sounds. Everything works smoothly but I'd like to know what happen in PCM generation. Here is the code:
int idx = 0;
for (final double dVal : sample) {
final short val = (short) ((dVal * 32767));
generatedSnd[idx++] = (byte) (val & 0x00ff);
generatedSnd[idx++] = (byte) ((val & 0xff00) >>> 8);
}
where sample is a double array that holds a sine computed with all required parameters in this case (frequency, hertz, so on and so forth), and generatedSnd is a byte array. Everything I know is that val & 0xff translates an int into a byte, but here what is precisely done? Why do there is the shift >>> 8?