This is a trial example and not the final code. Hence no improvmemt is done in the code. You can assume Jcount initially zero.
int b = ((buffer[Icount+1] << 8 ) | (buffer[Icount] & 0xFF)) & 0xFFFF;
this code will probably not give the result you expect as a byte is signed in java, and is probably the cause of the noise you’re hearing.
I’d advise to use Abuse’s code instead, or if you really want to hang on to the code you posted, update the above line to
int b = (((buffer[Icount+1] & 0xff) << 8 ) | (buffer[Icount] & 0xff)) & 0xffff;
EDIT: Oops, forget what I said. The & 0xffff does the trick, sorry about that :-[. Still, I’d use Abuse’s code…
That code wasn’t intended as a replacement, I was just trying to highlight that the loop may not be doing what you intended it to do.
Do you realy want to be zero’ing every other pair of bytes in the buffer?
Hello,
Do you know when i can make sound silence? I have PCM_SIGNED data. What i can use 0 OR -1 to make sound silence?
Just use 0.