AudioFormatWriter::WriteHelper


#1

Hi

As writing an AAC reader/writer I have to deinterleave (resp. interleave) data in read (resp. write) methods.
The helpers are very useful but I had to slightly modify the WriteHelper to be able to use an offset on the source uninterleaved buffer as follows (note the additional int sourceOffset parameter):

[code] /** Used by AudioFormatWriter subclasses to copy data to different formats. */
template <class DestSampleType, class SourceSampleType, class DestEndianness>
struct WriteHelper
{
typedef AudioData::Pointer <DestSampleType, DestEndianness, AudioData::Interleaved, AudioData::NonConst> DestType;
typedef AudioData::Pointer <SourceSampleType, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::Const> SourceType;

    static void write (void* destData, int numDestChannels, const int** source, int numSamples, int sourceOffset = 0) throw()
    {
        for (int i = 0; i < numDestChannels; ++i)
        {
            const DestType dest (addBytesToPointer (destData, i * DestType::getBytesPerSample()), numDestChannels);

            if (*source != 0)
            {
                dest.convertSamples (SourceType (*source + sourceOffset), numSamples);
                ++source;
            }
            else
            {
                dest.clearSamples (numSamples);
            }
        }
    }
};

[/code]

Jules, would you mind committing this update (existing code does not get affected as parameter has default value)? ReadHelper already provides an offset parameter for destination.

Thanks


#2

Ok, sounds like a good idea, thanks!


#3

Great,
Thanks