问题
Is the endianness of format params guaranteed in RIFF WAV files? I have heard conflicting answers to this including references to a RIFX file format.
回答1:
Yes.
If the file starts with RIFF, then it's little endian. If it starts with FFIR or RIFX, then it's probably not. Generally, supporting the WAV format means supporting RIFF files, although adding RIFX support should not prove difficult.
The AES31 specification for BWF (Broadcast Wave Format) references this specification for RIFF: http://www.tactilemedia.com/info/MCI_Control_Info.html
From this:
RIFF has a counterpart, RIFX, that is used to define RIFF file formats that use the Motorola integer byte-ordering format rather than the Intel format. A RIFX file is the same as a RIFF file, except that the first four bytes are 'RIFX' instead of 'RIFF', and integer byte ordering is represented in Motorola format.
The KVR article you reference refers to the author's incorrect usage of int* on big-endian systems (Motorola PPC), which will retrieve byte-swapped values. Care is always necessary to handle byte-swapping correctly when writing cross-endian code.
If the zeroth byte of the file on disk is 'R', and the 3rd is 'F', you can be certain that the rest of the contents will be stored little endian.
RIFX is not widely used. Most big-endian RIFF implementations swap bytes to disk, and generate correct RIFF files.
来源:https://stackoverflow.com/questions/1111539/is-the-endianness-of-format-params-guaranteed-in-riff-wav-files