title: Convert 32 bit signed int to 24 bit signed for audio data
body: <p>I'm trying to convert my audio data which is 32 bit signed int, into 24 bit signed.
  The goal is to write a Wave file. I already managed to write correct Wave files with 8, 16 and 32 bit depths, but for some reason I struggle with 24 bit. The sound output sounds like 8 bits (lots of noise), which seems to mean only the MSB is correctly interpreted, the second and third bytes of the 24-bit value seems not working.</p>
  
  <p>The code:</p>
  
  <pre><code>int buffer_32[1024];
  unsigned char buffer_24[1024*3];
  
  for (unsigned i = 0; i &lt; 1024; i++)
  {
      buffer_24[i*3] = (unsigned char)((buffer_32[i] &amp; 0xff0000) &gt;&gt; 16);
      buffer_24[i*3+1] = (unsigned char)((buffer_32[i] &amp; 0xff00) &gt;&gt; 8);
      buffer_24[i*3+2] = (unsigned char)(buffer_32[i] &amp; 0xff);
  }
  </code></pre>
  
  <p>Basically, I manipulate bytes to create a 24-bit stream ('24bit packed').</p>
  
  <p>I don't know whats wrong in my conversion algorithm: can you help me?</p>
  
  <p>EDIT : I forgot to say, my int values are already correctly scaled into -8388608,8388607 (24-bit signed integer) range before going into this conversion loop.</p>