Changeset 1076

Show
Ignore:
Timestamp:
06/13/09 22:31:28 (15 months ago)
Author:
gbooker
Message:

Create channel interleaver for DTS (We need to add layouts for other codecs).
Fixes #404

Location:
trunk/FFissionCodec
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/FFissionCodec/FFissionDecoder.cpp

    r1055 r1076  
    102102        } 
    103103        else 
    104                 dtsPassthrough = 0;      
     104                dtsPassthrough = 0; 
     105         
     106        int initialMap[6] = {0, 1, 2, 3, 4, 5}; 
     107        memcpy(fullChannelMap, initialMap, sizeof(initialMap)); 
    105108} 
    106109 
     
    327330        if(mInputFormat.mFormatID != kAudioFormatDTS) 
    328331                dtsPassthrough = 0; 
     332        else 
     333        { 
     334                switch (mInputFormat.mChannelsPerFrame) { 
     335                        case 3: 
     336                        case 6: 
     337                        { 
     338                                int chanMap[6] = {1, 2, 0, 5, 3, 4};//L R C -> C L R  and  L R C LFE Ls Rs -> C L R Ls Rs LFE 
     339                                memcpy(fullChannelMap, chanMap, sizeof(chanMap)); 
     340                                break; 
     341                        } 
     342                        case 4: 
     343                        case 5: 
     344                        { 
     345                                int chanMap[6] = {1, 2, 0, 3, 4, 5};//L R C Cs -> C L R Cs  and  L R C Ls Rs -> C L R Ls Rs 
     346                                memcpy(fullChannelMap, chanMap, sizeof(chanMap)); 
     347                                break; 
     348                        } 
     349                        default: 
     350                                break; 
     351                } 
     352        } 
    329353} 
    330354 
     
    492516} 
    493517 
     518UInt32 FFissionDecoder::InterleaveSamples(void *outputDataUntyped, Byte *inputDataUntyped, int amountToCopy) 
     519{ 
     520        SInt16 *outputData = (SInt16 *)outputDataUntyped; 
     521        SInt16 *inputData = (SInt16 *)inputDataUntyped; 
     522        int channelCount = avContext->channels; 
     523        int framesToCopy = amountToCopy / channelCount / 2; 
     524        for(int i=0; i<framesToCopy; i++) 
     525        { 
     526                for(int j=0; j<channelCount; j++) 
     527                { 
     528                        outputData[fullChannelMap[j]] = inputData[j]; 
     529                } 
     530                outputData += channelCount; 
     531                inputData += channelCount; 
     532        } 
     533         
     534        return framesToCopy * channelCount * 2; 
     535} 
     536 
    494537UInt32 FFissionDecoder::ProduceOutputPackets(void* outOutputData, 
    495538                                                                                         UInt32& ioOutputDataByteSize,  // number of bytes written to outOutputData 
     
    511554        if (outBufUsed > 0) { 
    512555                int amountToCopy = FFMIN(outBufUsed, ioOutputDataByteSize); 
    513                 memcpy(outData, outputBuffer, amountToCopy); 
     556                amountToCopy = InterleaveSamples(outData, outputBuffer, amountToCopy); 
    514557                outBufUsed -= amountToCopy; 
    515558                written += amountToCopy; 
     
    550593                // copy up to the amount requested 
    551594                int amountToCopy = FFMIN(outBufUsed, ioOutputDataByteSize - written); 
    552                 memcpy(outData + written, outputBuffer, amountToCopy); 
     595                amountToCopy = InterleaveSamples(outData + written, outputBuffer, amountToCopy); 
    553596                outBufUsed -= amountToCopy; 
    554597                written += amountToCopy; 
  • trunk/FFissionCodec/FFissionDecoder.h

    r1044 r1076  
    4444 
    4545        virtual void AppendInputData(const void* inInputData, UInt32& ioInputDataByteSize, UInt32& ioNumberPackets, const AudioStreamPacketDescription* inPacketDescription); 
     46        virtual UInt32 InterleaveSamples(void *outputDataUntyped, Byte *inputDataUntyped, int amountToCopy); 
    4647        virtual UInt32 ProduceOutputPackets(void* outOutputData, UInt32& ioOutputDataByteSize, UInt32& ioNumberPackets, AudioStreamPacketDescription* outPacketDescription); 
    4748         
     
    6061        int outBufUsed; 
    6162        bool dtsPassthrough; 
     63        int fullChannelMap[6]; 
    6264}; 
    6365