Menu

#80 AIFC codec calculates wrong data length

open
nobody
None
5
2004-03-19
2004-03-19
John Emmas
No

CAAFAIFCCodec.cpp contains a function which finishes
off an AIFC stream, after the essence data has been
added (this only applies to essence added via the codec
and not by any other method).
Function ‘CAAFAIFCCodec::CreateAudioDataEnd(void)’
contains the following two statements:-

CHECK(ComputeWriteChunkSize(4, curOffset));
CHECK(ComputeWriteChunkSize(_dataSizeOffset,
curOffset));

Each statement seeks the AIFC stream to a position
determined by the first parameter. A value is then
computed by deducting the first parameter from the
second one. The resulting value is a length, from which
a further 4 bytes are deducted (because the length
itself requires 4 bytes storage). This final value is
written at the “seeked” position on the stream.
CreateAudioDataEnd() should be called immediately after
writing the data samples, while the current stream
position (curOffset) is END_OF_DATA.

In the case of the second statement, the intention is to
write the total size of the SSND data (i.e. numChannels
x numSamples x bytesPerSample). However, 12 bytes
are reserved immediately following an SSND chunk
marker. Four of these are the length (which is catered
for, as described above) plus there are four bytes for
ssndOffset and four for ssndBlockSize. However, these
ones are not being taken into account which results in
the calculated length being 8 bytes too large. This is
easily remedied by changing the second statement to:-

CHECK(ComputeWriteChunkSize(_dataSizeOffset,
curOffset-8));

Discussion