title: Swap endian in pcm audio
body: <p>I've made simply program to swap endian in PCM audio (2 channels, 48kHz, 24 bit), but only one channel is swapped correctly, second one is still little Endian (i've checked generated output in CoolEdit 2000). Could anybody give me some guidance what's wrong in my code?</p>
  
  <pre><code>inline int endian_swap(unsigned int x)
  {
  unsigned char c1, c2, c3, c4;
  
      c1 = x &amp; 255;
      c2 = (x &gt;&gt; 8) &amp; 255;
      c3 = (x &gt;&gt; 16) &amp; 255;
      c4 = (x &gt;&gt; 24) &amp; 255;
  
      return ((int)c1 &lt;&lt; 24) + ((int)c2 &lt;&lt; 16) + ((int)c3 &lt;&lt; 8) + c4;
  }
  
  int main()
  {
  
  FILE *fpIn, *fpOut;
  short x;
  
  fpIn = fopen("audio.pcm", "rb");
  fpOut = fopen("out.pcm", "wb");
  int test = sizeof(short);
  
  int count = 0;
  int swaped = 0;
  
  while( fread(&amp;x, sizeof(int), 1, fpIn) == 1 )
      {
      swaped = endian_swap(x);
  
      fwrite(&amp;swaped, sizeof(int), 1, fpOut);
      }
  
  system("pause");
  return 0;
  }
  </code></pre>
  
  <p>Best regards!</p>