Changeset 43

Show
Ignore:
Timestamp:
04/07/07 17:33:17 (2 years ago)
Author:
gbooker
Message:

Pro Logic II support.
Closes #29

Files:

Legend:

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

    r40 r43  
    7373                dynamicRangeCompression = 1;  //no compression 
    7474         
     75        int useStereoOverDolby = 0; 
    7576        CFTypeRef stereo = CFPreferencesCopyAppValue(CFSTR("useStereoOverDolby"), CFSTR("com.cod3r.a52codec")); 
    7677        if(stereo != NULL) 
     
    8182                else if(type == CFNumberGetTypeID()) 
    8283                        CFNumberGetValue((CFNumberRef)stereo, kCFNumberIntType, &useStereoOverDolby); 
    83                 else 
    84                         useStereoOverDolby = 0
     84                else if(type == CFBooleanGetTypeID()) 
     85                        useStereoOverDolby = CFBooleanGetValue((CFBooleanRef)stereo)
    8586                CFRelease(stereo); 
    8687        } 
     88 
     89        int useDPL2 = 0; 
     90        CFTypeRef dpl2 = CFPreferencesCopyAppValue(CFSTR("useDolbyProLogicII"), CFSTR("com.cod3r.a52codec")); 
     91        if(dpl2 != NULL) 
     92        { 
     93                CFTypeID type = CFGetTypeID(dpl2); 
     94                if(type == CFStringGetTypeID()) 
     95                        useDPL2 = CFStringGetIntValue((CFStringRef)dpl2); 
     96                else if(type == CFNumberGetTypeID()) 
     97                        CFNumberGetValue((CFNumberRef)dpl2, kCFNumberIntType, &useDPL2); 
     98                else if(type == CFBooleanGetTypeID()) 
     99                        useDPL2 = CFBooleanGetValue((CFBooleanRef)dpl2); 
     100                CFRelease(dpl2); 
     101        } 
     102         
     103        if(useStereoOverDolby) 
     104                TwoChannelMode = A52_STEREO; 
     105        else if(useDPL2) 
     106                TwoChannelMode = A52_DOLBY | A52_USE_DPLII; 
    87107        else 
    88                 useStereoOverDolby = 0
     108                TwoChannelMode = A52_DOLBY
    89109         
    90110        CFTypeRef pass = CFPreferencesCopyAppValue(CFSTR("attemptPassthrough"), CFSTR("com.cod3r.a52codec")); 
     
    564584                                case 2: 
    565585                                        // All we really need is stereophonic, baby 
    566                                         if(useStereoOverDolby) 
    567                                                 a52_flags = A52_STEREO | A52_ADJUST_LEVEL; 
    568                                         else 
    569                                                 a52_flags = A52_DOLBY | A52_ADJUST_LEVEL; 
     586                                        a52_flags = TwoChannelMode; 
    570587                                        break; 
    571588                                         
  • trunk/A52/ACShepA52Decoder.h

    r38 r43  
    8080         
    8181        //Prefs 
    82         bool   useStereoOverDolby
     82        int            TwoChannelMode
    8383        double  dynamicRangeCompression; 
    8484        bool    passthrough; 
  • trunk/A52Preferences/A52Preferences.h

    r40 r43  
    55@interface A52Preferences : NSObject 
    66{ 
     7        IBOutlet NSWindow                                       *window_mainWindow; 
     8        IBOutlet NSPopUpButton                          *popup_ac3DynamicRangeType; 
     9        IBOutlet NSPopUpButton                          *popup_2ChannelMode; 
     10         
     11        IBOutlet NSWindow                                       *window_dynRangeSheet; 
    712    IBOutlet NSTextField                *textField_ac3DynamicRangeValue; 
    813    IBOutlet NSSlider                   *slider_ac3DynamicRangeSlider; 
    9     IBOutlet NSButton                                   *button_stereo; 
    1014         
    1115        NSUserDefaults                                          *defaults; 
    1216        float                                                           dynValue; 
     17        float                                                           savedDynValue; 
     18        BOOL                                                            useStereo; 
     19        BOOL                                                            useDPL2; 
    1320} 
     21 
     22- (IBAction)setAC3DynamicRangePopup:(id)sender; 
     23- (IBAction)set2ChannelModePopup:(id)sender; 
    1424 
    1525- (IBAction)setAC3DynamicRangeValue:(id)sender; 
    1626- (IBAction)setAC3DynamicRangeSlider:(id)sender; 
     27- (IBAction)cancelDynRangeSheet:(id)sender; 
     28- (IBAction)saveDynRangeSheet:(id)sender; 
    1729 
    1830- (IBAction)cancel:(id)sender; 
  • trunk/A52Preferences/A52Preferences.m

    r40 r43  
    2424                [self setAC3DynamicRange:1.0]; 
    2525        if([defaults boolForKey:@"useStereoOverDolby"]) 
    26                 [button_stereo setIntValue:1]; 
     26        { 
     27                useStereo = YES; 
     28                useDPL2 = NO; 
     29                [popup_2ChannelMode selectItemAtIndex:0]; 
     30        } 
     31        else if([defaults boolForKey:@"useDolbyProLogicII"]) 
     32        { 
     33                useStereo = NO; 
     34                useDPL2 = YES; 
     35                [popup_2ChannelMode selectItemAtIndex:2]; 
     36        } 
    2737        else 
    28                 [button_stereo setIntValue:0]; 
     38        { 
     39                useStereo = NO; 
     40                useDPL2 = NO; 
     41                [popup_2ChannelMode selectItemAtIndex:1];                
     42        } 
    2943} 
    3044 
     
    3347        [defaults release]; 
    3448        [super dealloc]; 
     49} 
     50 
     51- (IBAction)setAC3DynamicRangePopup:(id)sender 
     52{ 
     53        int selected = [popup_ac3DynamicRangeType indexOfSelectedItem]; 
     54        switch(selected) 
     55        { 
     56                case 0: 
     57                        [self setAC3DynamicRange:1.0]; 
     58                        break; 
     59                case 1: 
     60                        [self setAC3DynamicRange:2.0]; 
     61                        break; 
     62                case 2: 
     63                        savedDynValue = dynValue; 
     64                        [NSApp beginSheet:window_dynRangeSheet modalForWindow:window_mainWindow modalDelegate:nil didEndSelector:nil contextInfo:NULL]; 
     65                        break; 
     66                default: 
     67                        break; 
     68        } 
     69} 
     70 
     71- (IBAction)set2ChannelModePopup:(id)sender; 
     72{ 
     73        int selected = [popup_2ChannelMode indexOfSelectedItem]; 
     74        switch(selected) 
     75        { 
     76                case 0: 
     77                        useStereo = YES; 
     78                        useDPL2 = NO; 
     79                        break; 
     80                case 1: 
     81                        useStereo = NO; 
     82                        useDPL2 = NO; 
     83                        break; 
     84                case 2: 
     85                        useStereo = NO; 
     86                        useDPL2 = YES; 
     87                        break; 
     88                default: 
     89                        break; 
     90        }        
    3591} 
    3692 
     
    45101    [textField_ac3DynamicRangeValue setFloatValue:newVal]; 
    46102    [slider_ac3DynamicRangeSlider setFloatValue:newVal]; 
     103        if(newVal == 1.0) 
     104                [popup_ac3DynamicRangeType selectItemAtIndex:0]; 
     105        else if(newVal == 2.0) 
     106                [popup_ac3DynamicRangeType selectItemAtIndex:1]; 
     107        else 
     108                [popup_ac3DynamicRangeType selectItemAtIndex:2]; 
    47109} 
    48110 
     
    61123} 
    62124 
     125- (IBAction)cancelDynRangeSheet:(id)sender 
     126{ 
     127        [self setAC3DynamicRange:savedDynValue]; 
     128        [NSApp endSheet:window_dynRangeSheet]; 
     129        [window_dynRangeSheet orderOut:self]; 
     130} 
     131 
     132- (IBAction)saveDynRangeSheet:(id)sender; 
     133{ 
     134        [NSApp endSheet:window_dynRangeSheet]; 
     135        [window_dynRangeSheet orderOut:self]; 
     136} 
     137 
    63138- (IBAction)cancel:(id)sender 
    64139{ 
     
    69144{ 
    70145        [defaults setFloat:dynValue forKey:@"dynamicRange"]; 
    71         if([button_stereo intValue] != 0) 
    72                 [defaults setBool:YES forKey:@"useStereoOverDolby"]; 
    73         else 
    74                 [defaults setBool:NO forKey:@"useStereoOverDolby"]; 
     146        [defaults setBool:useStereo forKey:@"useStereoOverDolby"]; 
     147        [defaults setBool:useDPL2 forKey:@"useDolbyProLogicII"]; 
    75148        [defaults synchronize]; 
    76149        [[NSApplication sharedApplication] terminate:nil]; 
  • trunk/A52Preferences/English.lproj/A52CodecPreferences.nib/classes.nib

    r40 r43  
    44            ACTIONS = { 
    55                cancel = id;  
     6                cancelDynRangeSheet = id;  
    67                save = id;  
     8                saveDynRangeSheet = id;  
     9                set2ChannelModePopup = id;  
     10                setAC3DynamicRangePopup = id;  
    711                setAC3DynamicRangeSlider = id;  
    812                setAC3DynamicRangeValue = id;  
     
    1115            LANGUAGE = ObjC;  
    1216            OUTLETS = { 
    13                 "button_stereo" = NSButton;  
     17                "popup_2ChannelMode" = NSPopUpButton;  
     18                "popup_ac3DynamicRangeType" = NSPopUpButton;  
    1419                "slider_ac3DynamicRangeSlider" = NSSlider;  
    1520                "textField_ac3DynamicRangeValue" = NSTextField;  
     21                "window_dynRangeSheet" = NSWindow;  
     22                "window_mainWindow" = NSWindow;  
    1623            };  
    1724            SUPERCLASS = NSObject;  
  • trunk/A52Preferences/English.lproj/A52CodecPreferences.nib/info.nib

    r40 r43  
    1414        <key>IBOpenObjects</key> 
    1515        <array> 
     16                <integer>29</integer> 
    1617                <integer>21</integer> 
    17                 <integer>29</integer> 
     18                <integer>286</integer> 
    1819        </array> 
    1920        <key>IBSystem Version</key> 
  • trunk/Read Me.rtf

    r41 r43  
    1 {\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf42
     1{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf41
    22{\fonttbl\f0\fswiss\fcharset77 Helvetica;\f1\fswiss\fcharset77 Helvetica-Bold;} 
    33{\colortbl;\red255\green255\blue255;} 
     
    6161 \'a5 Fixed an incorrect assumption about sample rates.\ 
    6262 \'a5 Fixed an error with an incomplete sample at the end of a file\ 
     63 \'a5 Added the ability to output Pro Logic II\ 
    6364\ 
    6465 
  • trunk/liba52/include/a52.h

    r1 r43  
    5353#define A52_ADJUST_LEVEL 32 
    5454 
     55// this next constant can be ORed with A52_DOLBY to tell liba52 to use 5.0 DPLII matrix encoding, 
     56// rather than just 4.0 Dolby Surround matrix encoding 
     57#define A52_USE_DPLII 64 
     58 
    5559a52_state_t * a52_init (uint32_t mm_accel); 
    5660sample_t * a52_samples (a52_state_t * state); 
  • trunk/liba52/liba52/a52_internal.h

    r1 r43  
    9494#define LEVEL_6DB 0.5 
    9595 
     96// these next two constants are used for DPL matrix encoding in downmix.c 
     97#define LEVEL_SQRT_1_2 0.5 
     98#define LEVEL_SQRT_3_4 0.8660254037844386 
     99 
    96100#define EXP_REUSE (0) 
    97101#define EXP_D15   (1) 
  • trunk/liba52/liba52/downmix.c

    r1 r43  
    3535                      sample_t clev, sample_t slev) 
    3636{ 
     37 
    3738    static uint8_t table[11][8] = { 
    3839        {A52_CHANNEL,   A52_DOLBY,      A52_STEREO,     A52_STEREO, 
     
    149150        } 
    150151 
     152        // add the DPLII flag back into the output if it was passed in 
     153        output = output | (flags & A52_USE_DPLII); 
     154 
    151155    return output; 
    152156} 
     
    395399} 
    396400 
    397 static void mix22toS (sample_t * samples, sample_t bias) 
    398 
    399     int i; 
    400     sample_t surround; 
    401  
    402     for (i = 0; i < 256; i++) { 
    403         surround = samples[i + 512] + samples[i + 768]; 
    404         samples[i] += bias - surround; 
    405         samples[i + 256] += bias + surround; 
    406     } 
     401static void mix22toS (sample_t * samples, sample_t bias, int use_dpl2) 
     402
     403        if (use_dpl2 == 1) { 
     404                int i; 
     405                sample_t Lt, Rt, Ls, Rs, Lss, Rss; 
     406                 
     407                for (i = 0; i < 256; i++) { 
     408                         
     409                        Lt = samples[i]; 
     410                        Rt = samples[i + 256]; 
     411                         
     412                        Ls = samples[i + 512]; 
     413                        Rs = samples[i + 768]; 
     414                         
     415                        Lss = (LEVEL_SQRT_3_4 * Ls) - (LEVEL_SQRT_1_2 * Rs); 
     416                        Rss = -(LEVEL_SQRT_1_2 * Ls) + (LEVEL_SQRT_3_4 * Rs); 
     417                         
     418                        samples[i] = Lt + Lss; 
     419                        samples[i + 256] = Rt + Rss; 
     420                } 
     421        } else { 
     422                int i; 
     423                sample_t surround; 
     424 
     425                for (i = 0; i < 256; i++) { 
     426                surround = samples[i + 512] + samples[i + 768]; 
     427                samples[i] += bias - surround; 
     428                samples[i + 256] += bias + surround; 
     429                } 
     430        } 
    407431} 
    408432 
     
    419443} 
    420444 
    421 static void mix32toS (sample_t * samples, sample_t bias) 
    422 
    423     int i; 
    424     sample_t common, surround; 
    425  
    426     for (i = 0; i < 256; i++) { 
    427         common = samples[i + 256] + bias; 
    428         surround = samples[i + 768] + samples[i + 1024]; 
    429         samples[i] += common - surround; 
    430         samples[i + 256] = samples[i + 512] + common + surround; 
    431     } 
     445static void mix32toS (sample_t * samples, sample_t bias, int use_dpl2) 
     446
     447 
     448        if (use_dpl2 == 1) { 
     449 
     450                int i; 
     451                sample_t cc, Lt, Rt, Ls, Rs, Lss, Rss; 
     452         
     453                for (i = 0; i < 256; i++) { 
     454         
     455                        cc = samples[i + 256] * LEVEL_3DB; 
     456                 
     457                        Lt = samples[i] + cc; 
     458                        Rt = samples[i + 512] + cc; 
     459                 
     460                        Ls = samples[i + 768]; 
     461                        Rs = samples[i + 1024]; 
     462                         
     463                        Lss = (LEVEL_SQRT_3_4 * Ls) - (LEVEL_SQRT_1_2 * Rs); 
     464                        Rss = -(LEVEL_SQRT_1_2 * Ls) + (LEVEL_SQRT_3_4 * Rs); 
     465                 
     466                        samples[i] = Lt + Lss; 
     467                        samples[i + 256] = Rt + Rss; 
     468         
     469                } 
     470 
     471        } else { 
     472 
     473                int i; 
     474                sample_t common, surround; 
     475         
     476                for (i = 0; i < 256; i++) { 
     477                common = samples[i + 256] + bias; 
     478                surround = samples[i + 768] + samples[i + 1024]; 
     479                samples[i] += common - surround; 
     480                samples[i + 256] = samples[i + 512] + common + surround; 
     481                } 
     482 
     483        } 
     484 
    432485} 
    433486 
     
    524577 
    525578    case CONVERT (A52_2F2R, A52_DOLBY): 
    526         mix22toS (samples, bias); 
     579        mix22toS (samples, bias, ((output & A52_USE_DPLII) == A52_USE_DPLII)); 
    527580        break; 
    528581 
     
    534587 
    535588    case CONVERT (A52_3F2R, A52_DOLBY): 
    536         mix32toS (samples, bias); 
     589        mix32toS (samples, bias, ((output & A52_USE_DPLII) == A52_USE_DPLII)); 
    537590        break; 
    538591