Bug in aiff code


there is a off by 1 error that shows up in the aiff code when a chunk is an odd number of bytes in length.

From the apple docs:

[code]typedef struct {

ID ckID; /* chunk ID /
long ckSize; /
chunk Size */

char ckData[]; /* data */

} Chunk;

ckID describes the format of the data portion a chunk. A program can determine how to interpret the chunk data by examining ckID.

ckSize is the size of the data portion of the chunk, in bytes. It does not include the 8 bytes used by ckID and ckSize.

ckData contains the data stored in the chunk. The format of this data is determined by ckID. If the data is an odd number of bytes in length, a zero pad byte must be added at the end. The pad byte is not included in ckSize . [/code]

the code need to be changed to:


jeez, that’s subtle. How about these two mods:

int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8); audioBytes += (audioBytes & 1);


[code] ~AiffAudioFormatWriter()
if ((bytesWritten & 1) != 0)
output->writeByte (0);



looks good, thanks