Changeset 57

Show
Ignore:
Timestamp:
07/27/07 17:50:03 (1 year ago)
Author:
gbooker
Message:

A much better passthrough method. Doesn't require 2 channel output only anymore (although, I expect it fails with mono AC3 :( ).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/A52/ACShepA52Decoder.cpp

    r50 r57  
    165165        CFPreferencesSetAppValue(USE_DPLII_KEY, NULL, myApp); 
    166166 
    167         if(passthrough || TwoChannelMode) 
     167        static int sample_rates[] = {48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 6000, 5512, 4000}; 
     168        for (int sample_index = 0; sample_index < 12; sample_index ++) 
    168169        { 
    169                 //begin our passthrough hack 
    170                 static int sample_rates[] = {48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 6000, 5512, 4000}; 
    171                 for (int sample_index = 0; sample_index < 12; sample_index ++) 
    172                 { 
    173                         CAStreamBasicDescription theOutputFormat(sample_rates[sample_index], kAudioFormatLinearPCM, 0, 1, 0, 2, 16, kIntPCMOutFormatFlag); 
    174                         AddOutputFormat(theOutputFormat); 
     170                for (int channels = 1; channels <= 6; channels++) { 
     171                        //      This decoder only takes an A/52 or AC-3 stream as it's input 
     172                        CAStreamBasicDescription theInputFormat1(sample_rates[sample_index], kAudioFormatAC3, 0, 256*6, 0, channels, 0, 0); 
     173                        AddInputFormat(theInputFormat1); 
     174                        CAStreamBasicDescription theInputFormat2(sample_rates[sample_index], kAudioFormatAVIAC3, 0, 256*6, 0, channels, 0, 0); 
     175                        AddInputFormat(theInputFormat2); 
     176                         
     177                        // if two channel mode is engaged and we are not passing through, only set output for 2 channels 
     178                        if(!passthrough && TwoChannelMode && channels != 2) 
     179                                continue; 
     180                        // Output 16-Bit Ints 
     181                        CAStreamBasicDescription theOutputFormat1(sample_rates[sample_index], kAudioFormatLinearPCM, 0, 1, 0, channels, 16, kIntPCMOutFormatFlag); 
     182                        AddOutputFormat(theOutputFormat1); 
     183                         
    175184                        if(!passthrough) 
    176185                        { 
    177                                 // 32 bit int 
    178                                 CAStreamBasicDescription theOutputFormat1(sample_rates[sample_index], kAudioFormatLinearPCM, 0, 1, 0, 2, 32, kIntPCMOutFormatFlag); 
    179                                 AddOutputFormat(theOutputFormat1); 
    180                                 // 32 bit float 
    181                                 CAStreamBasicDescription theOutputFormat2(sample_rates[sample_index], kAudioFormatLinearPCM, 0, 1, 0, 2, 32, kFloatPCMOutFormatFlag); 
    182                                 AddOutputFormat(theOutputFormat2); 
    183                         } 
    184                         for (int channels = 1; channels <= 6; channels++) { 
    185                                 //      This decoder only takes an A/52 or AC-3 stream as it's input 
    186                                 CAStreamBasicDescription theInputFormat1(sample_rates[sample_index], kAudioFormatAC3, 0, 256*6, 0, channels, 0, 0); 
    187                                 AddInputFormat(theInputFormat1); 
    188                                 CAStreamBasicDescription theInputFormat2(sample_rates[sample_index], kAudioFormatAVIAC3, 0, 256*6, 0, channels, 0, 0); 
    189                                 AddInputFormat(theInputFormat2); 
    190                         } 
    191                 } 
    192         } 
    193         else 
    194         { 
    195                 static int sample_rates[] = {48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 6000, 5512, 4000}; 
    196                 for (int sample_index = 0; sample_index < 12; sample_index ++) 
    197                 { 
    198                         for (int channels = 1; channels <= 6; channels++) { 
    199                                 //      This decoder only takes an A/52 or AC-3 stream as it's input 
    200                                 CAStreamBasicDescription theInputFormat1(sample_rates[sample_index], kAudioFormatAC3, 0, 256*6, 0, channels, 0, 0); 
    201                                 AddInputFormat(theInputFormat1); 
    202                                 CAStreamBasicDescription theInputFormat2(sample_rates[sample_index], kAudioFormatAVIAC3, 0, 256*6, 0, channels, 0, 0); 
    203                                 AddInputFormat(theInputFormat2); 
    204                                  
    205                                 // Output 16-Bit Ints 
    206                                 CAStreamBasicDescription theOutputFormat1(sample_rates[sample_index], kAudioFormatLinearPCM, 0, 1, 0, channels, 16, kIntPCMOutFormatFlag); 
    207                                 AddOutputFormat(theOutputFormat1); 
    208                                  
    209186                                // And 32-Bit 
    210187                                CAStreamBasicDescription theOutputFormat2(sample_rates[sample_index], kAudioFormatLinearPCM, 0, 1, 0, channels, 32, kIntPCMOutFormatFlag); 
     
    598575                        myOutputData += output_offset * output_sample_size;  //output_offset is in 16-bit ints 
    599576                         
    600                         memset(myOutputData, 0, 2 * 2 * 256 * 6); 
     577                        int frameSize = mOutputFormat.mChannelsPerFrame * 2; 
     578                        memset(myOutputData, 0, frameSize * 256 * 6); 
    601579                        input_data = GetBytes(bytes_to_read); 
    602580                         
    603581                        if (mOutputFormat.mFormatFlags & kLinearPCMFormatFlagIsBigEndian) 
    604582                        { 
    605                                 memcpy(myOutputData, p_sync_be, 6); 
     583                                memcpy(myOutputData, p_sync_be, 4); 
     584                                myOutputData[frameSize] = input_data[5] & 0x7; 
     585                                myOutputData[frameSize+1] = p_sync_be[5]; 
     586                                myOutputData[frameSize+2] = (bytes_to_read >> 4) & 0xff; 
     587                                myOutputData[frameSize+3] = (bytes_to_read << 4) & 0xff; 
     588                                unsigned int i; 
     589                                int frameNumber; 
     590                                for(i=0, frameNumber = 2; i<bytes_to_read; i+=4, frameNumber++) 
     591                                { 
     592                                        int offset = frameNumber * frameSize; 
     593                                        memcpy(&myOutputData[offset], input_data, 4); 
     594                                } 
     595                                 
     596                                memcpy(myOutputData, p_sync_be, 4); 
    606597                                myOutputData[4] = input_data[5] & 0x7; 
    607598                                myOutputData[6] = (bytes_to_read >> 4) & 0xff; 
     
    611602                        else 
    612603                        { 
    613                                 memcpy(myOutputData, p_sync_le, 6); 
    614                                 myOutputData[5] = input_data[5] & 0x7; 
    615                                 myOutputData[6] = (bytes_to_read << 4) & 0xff; 
    616                                 myOutputData[7] = (bytes_to_read >> 4) & 0xff; 
     604                                memcpy(myOutputData, p_sync_le, 4); 
     605                                myOutputData[frameSize] = p_sync_le[4]; 
     606                                myOutputData[frameSize+1] = input_data[5] & 0x7; 
     607                                myOutputData[frameSize+2] = (bytes_to_read << 4) & 0xff; 
     608                                myOutputData[frameSize+3] = (bytes_to_read >> 4) & 0xff; 
    617609                                unsigned int i; 
    618                                 for(i=0; i<bytes_to_read; i+=2) 
     610                                int frameNumber; 
     611                                for(i=0, frameNumber = 2; i<bytes_to_read; i+=4, frameNumber++) 
    619612                                { 
    620                                         myOutputData[i+8] = input_data[i+1]; 
    621                                         myOutputData[i+9] = input_data[i]; 
     613                                        int offset = frameNumber * frameSize; 
     614                                        myOutputData[offset] = input_data[i+1]; 
     615                                        myOutputData[offset+1] = input_data[i]; 
     616                                        myOutputData[offset+2] = input_data[i+3]; 
     617                                        myOutputData[offset+3] = input_data[i+2]; 
    622618                                } 
    623619                        }