Revision a0d763fc
libavcodec/ac3enc.c  

923  923 
int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS], 
924  924 
int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS], 
925  925 
uint8_t bap[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS], 
926 
int coarse_snr_offset, int fine_snr_offset)


926 
int snr_offset) 

927  927 
{ 
928  928 
int blk, ch; 
929 
int snr_offset, mantissa_bits;


929 
int mantissa_bits; 

930  930  
931 
snr_offset = (((coarse_snr_offset  15) << 4) + fine_snr_offset) << 2;


931 
snr_offset = (snr_offset  240) << 2;


932  932  
933  933 
mantissa_bits = 0; 
934  934 
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { 
...  ...  
947  947 
} 
948  948  
949  949  
950 
#define SNR_INC1 4 

951  
952  950 
/** 
953  951 
* Perform bit allocation search. 
954  952 
* Finds the SNR offset value that maximizes quality and fits in the specified 
...  ...  
962  960 
{ 
963  961 
int ch; 
964  962 
int bits_left; 
965 
int coarse_snr_offset, fine_snr_offset;


963 
int snr_offset; 

966  964 
uint8_t bap1[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS]; 
967  965 
int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS]; 
968  966 
int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]; 
...  ...  
977  975 
offset until we can pack everything in the requested frame size */ 
978  976  
979  977 
bits_left = 8 * s>frame_size  (s>frame_bits + s>exponent_bits); 
980 
coarse_snr_offset = s>coarse_snr_offset;


981 
while (coarse_snr_offset >= 0 &&


982 
bit_alloc(s, mask, psd, bap, coarse_snr_offset, 0) > bits_left)


983 
coarse_snr_offset = SNR_INC1;


984 
if (coarse_snr_offset < 0) {


978 
snr_offset = s>coarse_snr_offset << 4;


979 
while (snr_offset >= 0 && 

980 
bit_alloc(s, mask, psd, bap, snr_offset) > bits_left)


981 
snr_offset = 64;


982 
if (snr_offset < 0) { 

985  983 
return AVERROR(EINVAL); 
986  984 
} 
987 
while (coarse_snr_offset + SNR_INC1 <= 63 &&


985 
while (snr_offset + 64 <= 1023 &&


988  986 
bit_alloc(s, mask, psd, bap1, 
989 
coarse_snr_offset + SNR_INC1, 0) <= bits_left) {


990 
coarse_snr_offset += SNR_INC1;


987 
snr_offset + 64) <= bits_left) {


988 
snr_offset += 64;


991  989 
memcpy(bap, bap1, sizeof(bap1)); 
992  990 
} 
993 
while (coarse_snr_offset + 1 <= 63 &&


994 
bit_alloc(s, mask, psd, bap1, coarse_snr_offset + 1, 0) <= bits_left) {


995 
coarse_snr_offset++;


991 
while (snr_offset + 16 <= 1023 &&


992 
bit_alloc(s, mask, psd, bap1, snr_offset + 16) <= bits_left) {


993 
snr_offset += 16;


996  994 
memcpy(bap, bap1, sizeof(bap1)); 
997  995 
} 
998  
999 
fine_snr_offset = 0; 

1000 
while (fine_snr_offset + SNR_INC1 <= 15 && 

996 
while (snr_offset + 4 <= 1023 && 

1001  997 
bit_alloc(s, mask, psd, bap1, 
1002 
coarse_snr_offset, fine_snr_offset + SNR_INC1) <= bits_left) {


1003 
fine_snr_offset += SNR_INC1;


998 
snr_offset + 4) <= bits_left) {


999 
snr_offset += 4;


1004  1000 
memcpy(bap, bap1, sizeof(bap1)); 
1005  1001 
} 
1006 
while (fine_snr_offset + 1 <= 15 &&


1002 
while (snr_offset + 1 <= 1023 &&


1007  1003 
bit_alloc(s, mask, psd, bap1, 
1008 
coarse_snr_offset, fine_snr_offset + 1) <= bits_left) {


1009 
fine_snr_offset++;


1004 
snr_offset + 1) <= bits_left) { 

1005 
snr_offset++; 

1010  1006 
memcpy(bap, bap1, sizeof(bap1)); 
1011  1007 
} 
1012  1008  
1013 
s>coarse_snr_offset = coarse_snr_offset;


1009 
s>coarse_snr_offset = snr_offset >> 4;


1014  1010 
for (ch = 0; ch < s>channels; ch++) 
1015 
s>fine_snr_offset[ch] = fine_snr_offset;


1011 
s>fine_snr_offset[ch] = snr_offset & 0xF;


1016  1012  
1017  1013 
return 0; 
1018  1014 
} 
Also available in: Unified diff