Revision 8999944e
libavcodec/ac3enc.c  

745  745  
746  746  
747  747 
/** 
748 
* Count the bits used to encode the frame, minus exponents and mantissas. 

749 
* @return bit count 

750 
*/ 

751 
static int count_frame_bits(AC3EncodeContext *s, 

752 
uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS]) 

753 
{ 

754 
static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 }; 

755 
int blk, ch; 

756 
int frame_bits; 

757  
758 
/* header size */ 

759 
frame_bits = 65; 

760 
frame_bits += frame_bits_inc[s>channel_mode]; 

761  
762 
/* audio blocks */ 

763 
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { 

764 
frame_bits += s>fbw_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */ 

765 
if (s>channel_mode == AC3_CHMODE_STEREO) { 

766 
frame_bits++; /* rematstr */ 

767 
if (!blk) 

768 
frame_bits += 4; 

769 
} 

770 
frame_bits += 2 * s>fbw_channels; /* chexpstr[2] * c */ 

771 
if (s>lfe_on) 

772 
frame_bits++; /* lfeexpstr */ 

773 
for (ch = 0; ch < s>fbw_channels; ch++) { 

774 
if (exp_strategy[blk][ch] != EXP_REUSE) 

775 
frame_bits += 6 + 2; /* chbwcod[6], gainrng[2] */ 

776 
} 

777 
frame_bits++; /* baie */ 

778 
frame_bits++; /* snr */ 

779 
frame_bits += 2; /* delta / skip */ 

780 
} 

781 
frame_bits++; /* cplinu for block 0 */ 

782 
/* bit alloc info */ 

783 
/* sdcycod[2], fdcycod[2], sgaincod[2], dbpbcod[2], floorcod[3] */ 

784 
/* csnroffset[6] */ 

785 
/* (fsnoffset[4] + fgaincod[4]) * c */ 

786 
frame_bits += 2*4 + 3 + 6 + s>channels * (4 + 3); 

787  
788 
/* auxdatae, crcrsv */ 

789 
frame_bits += 2; 

790  
791 
/* CRC */ 

792 
frame_bits += 16; 

793  
794 
return frame_bits; 

795 
} 

796  
797  
798 
/** 

748  799 
* Calculate the number of bits needed to encode a set of mantissas. 
749  800 
*/ 
750  801 
static int compute_mantissa_size(AC3EncodeContext *s, uint8_t *m, int nb_coefs) 
...  ...  
879  930 
uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS], 
880  931 
int frame_bits) 
881  932 
{ 
882 
int blk, ch;


933 
int ch; 

883  934 
int coarse_snr_offset, fine_snr_offset; 
884  935 
uint8_t bap1[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS]; 
885  936 
int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS]; 
886  937 
int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]; 
887 
static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 }; 

888  938  
889  939 
/* init default parameters */ 
890  940 
s>slow_decay_code = 2; 
...  ...  
902  952 
s>bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s>db_per_bit_code]; 
903  953 
s>bit_alloc.floor = ff_ac3_floor_tab[s>floor_code]; 
904  954  
905 
/* header size */ 

906 
frame_bits += 65; 

907 
// if (s>channel_mode == 2) 

908 
// frame_bits += 2; 

909 
frame_bits += frame_bits_inc[s>channel_mode]; 

910  
911 
/* audio blocks */ 

912 
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { 

913 
frame_bits += s>fbw_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */ 

914 
if (s>channel_mode == AC3_CHMODE_STEREO) { 

915 
frame_bits++; /* rematstr */ 

916 
if (!blk) 

917 
frame_bits += 4; 

918 
} 

919 
frame_bits += 2 * s>fbw_channels; /* chexpstr[2] * c */ 

920 
if (s>lfe_on) 

921 
frame_bits++; /* lfeexpstr */ 

922 
for (ch = 0; ch < s>fbw_channels; ch++) { 

923 
if (exp_strategy[blk][ch] != EXP_REUSE) 

924 
frame_bits += 6 + 2; /* chbwcod[6], gainrng[2] */ 

925 
} 

926 
frame_bits++; /* baie */ 

927 
frame_bits++; /* snr */ 

928 
frame_bits += 2; /* delta / skip */ 

929 
} 

930 
frame_bits++; /* cplinu for block 0 */ 

931 
/* bit alloc info */ 

932 
/* sdcycod[2], fdcycod[2], sgaincod[2], dbpbcod[2], floorcod[3] */ 

933 
/* csnroffset[6] */ 

934 
/* (fsnoffset[4] + fgaincod[4]) * c */ 

935 
frame_bits += 2*4 + 3 + 6 + s>channels * (4 + 3); 

936  
937 
/* auxdatae, crcrsv */ 

938 
frame_bits += 2; 

939  
940 
/* CRC */ 

941 
frame_bits += 16; 

955 
/* count frame bits other than exponents and mantissas */ 

956 
frame_bits += count_frame_bits(s, exp_strategy); 

942  957  
943  958 
/* calculate psd and masking curve before doing bit allocation */ 
944  959 
bit_alloc_masking(s, encoded_exp, exp_strategy, psd, mask); 
Also available in: Unified diff