Seeming issue in AudioFormatWriter...?

Hello, Jucey people. I’m stepping through code in the debugger and noticed an anomaly…

Let us look at AudioFormatWriter::writeFromAudioReader, on or about line 407…

maxChans is defined a few lines up as const int 128 (it should probably be a static const int to help the compiler optimize it out, but it probably does anyway…) and the signature of read() is:

bool AudioFormatReader::read (int** destSamples, int numDestChannels, int64 startSampleInSource, int numSamplesToRead, const bool fillLeftoverChannelsWithCopies)

So numDestChannels is 128 every time this line is called. This doesn’t seem right! I seem to be clearing 128 channels each time - but my source and target are two channels.

My theory is that line 407 should be:

Yes, you do seem to have spotted a mistake there… I’ll take a proper look, but I think you’re right that it ought to read numChannels instead.

Slightly surprised by you mentioning the const - do you have any reason to think that compilers are more likely to optimise a static const than a local const?

Just making that change resulted in another error, but I’m not sure if that’s my code or not, am investigating.

On the const ints, well, I think on second thought it’s an aberration in my mind. The compiler can detect that you never take the address of these items and optimize 'em out either way. Just habit to make constants static ints in classes…

(So ignore that part. :-D)

OK, there doesn’t seem any reason from my code not to make that change. There’s a min elsewhere that prevents anything bad from happening but still ends up doing a lot of copying…