mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
simplify AC-3 bit allocation
Originally committed as revision 8302 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
3a8bf52983
commit
abfe5a4a75
@ -83,13 +83,12 @@ static inline int16_t fix15(float a)
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int calc_lowcomp1(int a, int b0, int b1)
|
static inline int calc_lowcomp1(int a, int b0, int b1, int c)
|
||||||
{
|
{
|
||||||
if ((b0 + 256) == b1) {
|
if ((b0 + 256) == b1) {
|
||||||
a = 384;
|
a = c;
|
||||||
} else if (b0 > b1) {
|
} else if (b0 > b1) {
|
||||||
a = a - 64;
|
a = FFMAX(a - 64, 0);
|
||||||
if (a < 0) a=0;
|
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@ -97,24 +96,12 @@ static inline int calc_lowcomp1(int a, int b0, int b1)
|
|||||||
static inline int calc_lowcomp(int a, int b0, int b1, int bin)
|
static inline int calc_lowcomp(int a, int b0, int b1, int bin)
|
||||||
{
|
{
|
||||||
if (bin < 7) {
|
if (bin < 7) {
|
||||||
if ((b0 + 256) == b1) {
|
return calc_lowcomp1(a, b0, b1, 384);
|
||||||
a = 384;
|
|
||||||
} else if (b0 > b1) {
|
|
||||||
a = a - 64;
|
|
||||||
if (a < 0) a=0;
|
|
||||||
}
|
|
||||||
} else if (bin < 20) {
|
} else if (bin < 20) {
|
||||||
if ((b0 + 256) == b1) {
|
return calc_lowcomp1(a, b0, b1, 320);
|
||||||
a = 320;
|
|
||||||
} else if (b0 > b1) {
|
|
||||||
a= a - 64;
|
|
||||||
if (a < 0) a=0;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
a = a - 128;
|
return FFMAX(a - 128, 0);
|
||||||
if (a < 0) a=0;
|
|
||||||
}
|
}
|
||||||
return a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* AC3 bit allocation. The algorithm is the one described in the AC3
|
/* AC3 bit allocation. The algorithm is the one described in the AC3
|
||||||
@ -125,7 +112,7 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
|
|||||||
int deltbae,int deltnseg,
|
int deltbae,int deltnseg,
|
||||||
uint8_t *deltoffst, uint8_t *deltlen, uint8_t *deltba)
|
uint8_t *deltoffst, uint8_t *deltlen, uint8_t *deltba)
|
||||||
{
|
{
|
||||||
int bin,i,j,k,end1,v,v1,bndstrt,bndend,lowcomp,begin;
|
int bin,i,j,k,end1,v,bndstrt,bndend,lowcomp,begin;
|
||||||
int fastleak,slowleak,address,tmp;
|
int fastleak,slowleak,address,tmp;
|
||||||
int16_t psd[256]; /* scaled exponents */
|
int16_t psd[256]; /* scaled exponents */
|
||||||
int16_t bndpsd[50]; /* interpolated exponents */
|
int16_t bndpsd[50]; /* interpolated exponents */
|
||||||
@ -143,22 +130,11 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
|
|||||||
do {
|
do {
|
||||||
v=psd[j];
|
v=psd[j];
|
||||||
j++;
|
j++;
|
||||||
end1=bndtab[k+1];
|
end1 = FFMIN(bndtab[k+1], end);
|
||||||
if (end1 > end) end1=end;
|
|
||||||
for(i=j;i<end1;i++) {
|
for(i=j;i<end1;i++) {
|
||||||
int c,adr;
|
|
||||||
/* logadd */
|
/* logadd */
|
||||||
v1=psd[j];
|
int adr = FFMIN(FFABS(v - psd[j]) >> 1, 255);
|
||||||
c=v-v1;
|
v = FFMAX(v, psd[j]) + latab[adr];
|
||||||
if (c >= 0) {
|
|
||||||
adr=c >> 1;
|
|
||||||
if (adr > 255) adr=255;
|
|
||||||
v=v + latab[adr];
|
|
||||||
} else {
|
|
||||||
adr=(-c) >> 1;
|
|
||||||
if (adr > 255) adr=255;
|
|
||||||
v=v1 + latab[adr];
|
|
||||||
}
|
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
bndpsd[k]=v;
|
bndpsd[k]=v;
|
||||||
@ -171,14 +147,14 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
|
|||||||
|
|
||||||
if (bndstrt == 0) {
|
if (bndstrt == 0) {
|
||||||
lowcomp = 0;
|
lowcomp = 0;
|
||||||
lowcomp = calc_lowcomp1(lowcomp, bndpsd[0], bndpsd[1]);
|
lowcomp = calc_lowcomp1(lowcomp, bndpsd[0], bndpsd[1], 384);
|
||||||
excite[0] = bndpsd[0] - fgain - lowcomp;
|
excite[0] = bndpsd[0] - fgain - lowcomp;
|
||||||
lowcomp = calc_lowcomp1(lowcomp, bndpsd[1], bndpsd[2]);
|
lowcomp = calc_lowcomp1(lowcomp, bndpsd[1], bndpsd[2], 384);
|
||||||
excite[1] = bndpsd[1] - fgain - lowcomp;
|
excite[1] = bndpsd[1] - fgain - lowcomp;
|
||||||
begin = 7;
|
begin = 7;
|
||||||
for (bin = 2; bin < 7; bin++) {
|
for (bin = 2; bin < 7; bin++) {
|
||||||
if (!(is_lfe && bin == 6))
|
if (!(is_lfe && bin == 6))
|
||||||
lowcomp = calc_lowcomp1(lowcomp, bndpsd[bin], bndpsd[bin+1]);
|
lowcomp = calc_lowcomp1(lowcomp, bndpsd[bin], bndpsd[bin+1], 384);
|
||||||
fastleak = bndpsd[bin] - fgain;
|
fastleak = bndpsd[bin] - fgain;
|
||||||
slowleak = bndpsd[bin] - s->sgain;
|
slowleak = bndpsd[bin] - s->sgain;
|
||||||
excite[bin] = fastleak - lowcomp;
|
excite[bin] = fastleak - lowcomp;
|
||||||
@ -197,18 +173,9 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
|
|||||||
if (!(is_lfe && bin == 6))
|
if (!(is_lfe && bin == 6))
|
||||||
lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin);
|
lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin);
|
||||||
|
|
||||||
fastleak -= s->fdecay;
|
fastleak = FFMAX(fastleak - s->fdecay, bndpsd[bin] - fgain);
|
||||||
v = bndpsd[bin] - fgain;
|
slowleak = FFMAX(slowleak - s->sdecay, bndpsd[bin] - s->sgain);
|
||||||
if (fastleak < v) fastleak = v;
|
excite[bin] = FFMAX(fastleak - lowcomp, slowleak);
|
||||||
|
|
||||||
slowleak -= s->sdecay;
|
|
||||||
v = bndpsd[bin] - s->sgain;
|
|
||||||
if (slowleak < v) slowleak = v;
|
|
||||||
|
|
||||||
v=fastleak - lowcomp;
|
|
||||||
if (slowleak > v) v=slowleak;
|
|
||||||
|
|
||||||
excite[bin] = v;
|
|
||||||
}
|
}
|
||||||
begin = 22;
|
begin = 22;
|
||||||
} else {
|
} else {
|
||||||
@ -220,29 +187,19 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (bin = begin; bin < bndend; bin++) {
|
for (bin = begin; bin < bndend; bin++) {
|
||||||
fastleak -= s->fdecay;
|
fastleak = FFMAX(fastleak - s->fdecay, bndpsd[bin] - fgain);
|
||||||
v = bndpsd[bin] - fgain;
|
slowleak = FFMAX(slowleak - s->sdecay, bndpsd[bin] - s->sgain);
|
||||||
if (fastleak < v) fastleak = v;
|
excite[bin] = FFMAX(fastleak, slowleak);
|
||||||
slowleak -= s->sdecay;
|
|
||||||
v = bndpsd[bin] - s->sgain;
|
|
||||||
if (slowleak < v) slowleak = v;
|
|
||||||
|
|
||||||
v=fastleak;
|
|
||||||
if (slowleak > v) v = slowleak;
|
|
||||||
excite[bin] = v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compute masking curve */
|
/* compute masking curve */
|
||||||
|
|
||||||
for (bin = bndstrt; bin < bndend; bin++) {
|
for (bin = bndstrt; bin < bndend; bin++) {
|
||||||
v1 = excite[bin];
|
|
||||||
tmp = s->dbknee - bndpsd[bin];
|
tmp = s->dbknee - bndpsd[bin];
|
||||||
if (tmp > 0) {
|
if (tmp > 0) {
|
||||||
v1 += tmp >> 2;
|
excite[bin] += tmp >> 2;
|
||||||
}
|
}
|
||||||
v=hth[bin >> s->halfratecod][s->fscod];
|
mask[bin] = FFMAX(hth[bin >> s->halfratecod][s->fscod], excite[bin]);
|
||||||
if (v1 > v) v=v1;
|
|
||||||
mask[bin] = v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* delta bit allocation */
|
/* delta bit allocation */
|
||||||
@ -269,20 +226,10 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
|
|||||||
i = start;
|
i = start;
|
||||||
j = masktab[start];
|
j = masktab[start];
|
||||||
do {
|
do {
|
||||||
v=mask[j];
|
v = (FFMAX(mask[j] - snroffset - s->floor, 0) & 0x1FE0) + s->floor;
|
||||||
v -= snroffset;
|
end1 = FFMIN(bndtab[j] + bndsz[j], end);
|
||||||
v -= s->floor;
|
|
||||||
if (v < 0) v = 0;
|
|
||||||
v &= 0x1fe0;
|
|
||||||
v += s->floor;
|
|
||||||
|
|
||||||
end1=bndtab[j] + bndsz[j];
|
|
||||||
if (end1 > end) end1=end;
|
|
||||||
|
|
||||||
for (k = i; k < end1; k++) {
|
for (k = i; k < end1; k++) {
|
||||||
address = (psd[i] - v) >> 5;
|
address = av_clip((psd[i] - v) >> 5, 0, 63);
|
||||||
if (address < 0) address=0;
|
|
||||||
else if (address > 63) address=63;
|
|
||||||
bap[i] = baptab[address];
|
bap[i] = baptab[address];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user