title: From audio PCM 16 bit to 8 bit - getting noise
body: <p>I implemented the following algorithm to convert PCM 16 bit audio data to 8 bit:</p>
  
  <pre><code>if(encoding == AudioFormat.ENCODING_PCM_8BIT){
      int len = data.length;          
      data1 = new byte[len/2];
      int tempint;
  
      for (int k = 0, i=1; i &lt; len; i+=2, k++) {
          tempint = ((int)data[i]) ^ 0x00000080; 
          data1[k] = (byte)tempint;
      }
      data=null;
  }
  </code></pre>
  
  <p>where <code>data is byte[]</code>. After running this code, the output <code>contains a lot of noise</code> and suggest me that I'm doing something wrong here. <code>What should I do besides dropping the lower byte?</code></p>
  
  <p>[EDIT]: modified the code:</p>
  
  <pre><code>if(encoding == AudioFormat.ENCODING_PCM_8BIT){
  
              int len = data.length;          
              data1 = new byte[len/2];
              for (int i = 0; i &lt; len/2; i++) {                   
                      data1[i] = data[i*2+1];     
              }
  
    }
  </code></pre>
  
  <p><code>the input/output looks like:</code></p>
  
  <pre><code> Original data(counter:0) = 4
      Original data(counter:1) = -1
      Original data(counter:2) = 75
      Original data(counter:3) = -1
      Original data(counter:4) = 16
      Original data(counter:5) = -1
      Original data(counter:6) = 44
      Original data(counter:7) = -1
      Original data(counter:8) = 7
      Original data(counter:9) = -1
      Original data(counter:10) = 22
      Original data(counter:11) = -1
      Original data(counter:12) = 22
      Original data(counter:13) = -1
      Original data(counter:14) = 12
      Original data(counter:15) = -1
  
  Output data:(counter:0) = -1
  Output data:(counter:1) = -1
  Output data:(counter:2) = -1
  Output data:(counter:3) = -1
  Output data:(counter:4) = -1
  Output data:(counter:5) = -1
  Output data:(counter:6) = -1
  Output data:(counter:7) = -1
  Output data:(counter:8) = -1
  Output data:(counter:9) = -1
  Output data:(counter:10) = -1
  Output data:(counter:11) = -1
  Output data:(counter:12) = -1
  Output data:(counter:13) = -1
  Output data:(counter:14) = -1
  Output data:(counter:15) = -1
  </code></pre>
  
  <p>It does not matter if I drop first or second byte, the noise still remain. Here I dropped first byte(instead of second)</p>