QuintoViento
QuintoViento

Reputation: 198

Why Use Both Little and Big Endian in WAV Header

Over the years, or at least what I have heard, there has been many debates over whether to use big or little endian. However, I've wondered when do you see both? Odd question, right?

Upon having to decode WAV files, I noticed the header was composed of different segments which could be either big or little endian. https://ccrma.stanford.edu/courses/422/projects/WaveFormat/

In the forum specified here, it specifies the reason for using little-endian for a large percentage of the file ( Why are an integers bytes stored backwards? Does this apply to headers only?)
'WAV files are little-endian (least significant bytes first) because the format originated for operating systems running on intel processor based machines which use the little endian format to store numbers.'

However, I have yet to find why is big-endian used as well?

Thanks in advance

Upvotes: 2

Views: 2980

Answers (1)

jaket
jaket

Reputation: 9341

It's a bit of a stretch to say the chunk ID's are big endian. In practice the IDs are 4 character ASCII strings (unterminated), e.g. 'RIFF', 'fmt ' and 'data'. If you restrict yourself to string comparisons then you can avoid the need to concern yourself with the byte ordering. As such, the waveformat structures are typically defined like the following in c:

typedef struct WAVHEADER
{
    char riff[4];
    int  chunkSize;
    etc...
}

Upvotes: 6

Related Questions