javax.sound.sampled API - Real - Time Panning

Hi i’m trying to map a mono sound of a character to stero by panning. I have a class that filters a stream of bytes, i can get the sample of the mono sound but i’m having problems in creating the stereo samples. Its hard for me to explain so ill paste some code here its from the class Soundfilter.
This is the method i use to get the sample from bytes and works fine.

public static short getSample(byte[] buffer, int position) {
return (short)(
((buffer[position+1] & 0xff) << 8) |
(buffer[position] & 0xff));
}

But if i want to put it back with a new left and right sample in new byte array of samples i have this method:

public static void setSample(byte[] buffer, int pos, short leftSample, short rightSample) {

buffer[pos]= (byte)(leftSample & 0xff);
buffer[pos + 1] = (byte)((leftSample >> 8) & 0xff);

buffer[pos + 2] = (byte)(rightSample & 0xff);
buffer[pos + 3] = (byte)((rightSample >> 8) & 0xff);
}

Is the left and right sample in the correct position? In a 16bit sample of stereo sound does the first 2 bytes represent left sample and the next 2 bytes represent right sample?

I’m not that familiar with java sound APIs, but can’t you just do this by controlling the mixer instead of manipulating the audio sample data directly?

The Control classes are not good at it in real time, it produces alot of hishes and clicks because its not gradually changing the samples overtime. I would use joal and jogl for my project but the requirements of my project are to get the game running on my uni’s computers which 1) i doubt OpenAL will be installed on them and i wont be allowed to do it myself. 2) i did some tests and jogl doesn’t display correctly. So i’m pretty much stuck with using almost pure java libs which isn’t 2 bad not doing some mad 3D game here lol.

Can you get around it by doing the gradual changes with your java code? Set a target for the value and move toward it in steps each frame. Adjust the max step size to avoid pops.