Left and right channels reversed when playing .WAV files

@tapeworm wrote:

 

However, even as this error message was displaying, the L_REV_2.WAV file would play; and the voice came out of the left speaker. Funny thing though, the time listed for the file (in WMP) was over 4 minutes and in actuality it is only like 17 seconds long (if I’m remembering correctly). The L_REV_1.WAV file wouldn’t play at all.

 

The file is truncated, so the header indicates its much larger.  A lot of software will ignore this (since the length of a WAV file is trivially calculated from the sample rate, bitdepth and file size) so its not usually a problem.  

The real problem is probably that the file has a lot of metadata in the header in various info chunks.  These are not widely supported, so the Sandisk firmware may not expect them.  By chance the metadata in the header of the first file extends the header so that its length is divisible by 2, but not divisiable by 4.  A PCM sample is 2 bytes in this file, and 2 are put together to make a 4 byte stereo pair.  Since the left channel starts shifted over by 2 bytes, the very first sample is lost and all subsequent ones are swapped (the first left sample is skipped, first right becomes the first left sample, second left becomes first right, …).

Theres basically two solutions here:

  1. Remove all these weird headers from your WAV files, or at least make sure that each WAV file has an amount of metadata added thats divisible by 4 bytes.  I don’t have my clip handy, but I bet if you just insert two bytes starting at byte 250 in that file it will play correctly in the sandisk software.  

  2. Use rockbox, which understands metadata in WAV files, and thus will not be confused by it.  I’ve verified that our WAV parser correctly handles the example file and does not flip the channels.  Likewise VLC does the same (and also helpfully prints out the file tags).