Revision 282255bb
libavcodec/ac3enc.c | ||
---|---|---|
1295 | 1295 |
|
1296 | 1296 |
|
1297 | 1297 |
/** |
1298 |
* Set bandwidth for all channels. |
|
1299 |
* The user can optionally supply a cutoff frequency. Otherwise an appropriate |
|
1300 |
* default value will be used. |
|
1301 |
*/ |
|
1302 |
static av_cold void set_bandwidth(AC3EncodeContext *s, int cutoff) |
|
1303 |
{ |
|
1304 |
int ch, bw_code; |
|
1305 |
|
|
1306 |
if (cutoff) { |
|
1307 |
/* calculate bandwidth based on user-specified cutoff frequency */ |
|
1308 |
int fbw_coeffs; |
|
1309 |
cutoff = av_clip(cutoff, 1, s->sample_rate >> 1); |
|
1310 |
fbw_coeffs = cutoff * 2 * AC3_MAX_COEFS / s->sample_rate; |
|
1311 |
bw_code = av_clip((fbw_coeffs - 73) / 3, 0, 60); |
|
1312 |
} else { |
|
1313 |
/* use default bandwidth setting */ |
|
1314 |
/* XXX: should compute the bandwidth according to the frame |
|
1315 |
size, so that we avoid annoying high frequency artifacts */ |
|
1316 |
bw_code = 50; |
|
1317 |
} |
|
1318 |
|
|
1319 |
/* set number of coefficients for each channel */ |
|
1320 |
for (ch = 0; ch < s->fbw_channels; ch++) { |
|
1321 |
s->bandwidth_code[ch] = bw_code; |
|
1322 |
s->nb_coefs[ch] = bw_code * 3 + 73; |
|
1323 |
} |
|
1324 |
if (s->lfe_on) |
|
1325 |
s->nb_coefs[s->lfe_channel] = 7; /* LFE channel always has 7 coefs */ |
|
1326 |
} |
|
1327 |
|
|
1328 |
|
|
1329 |
/** |
|
1298 | 1330 |
* Initialize the encoder. |
1299 | 1331 |
*/ |
1300 | 1332 |
static av_cold int ac3_encode_init(AVCodecContext *avctx) |
1301 | 1333 |
{ |
1302 | 1334 |
AC3EncodeContext *s = avctx->priv_data; |
1303 |
int ch, bw_code, ret;
|
|
1335 |
int ret; |
|
1304 | 1336 |
|
1305 | 1337 |
avctx->frame_size = AC3_FRAME_SIZE; |
1306 | 1338 |
|
... | ... | |
1318 | 1350 |
s->samples_written = 0; |
1319 | 1351 |
s->frame_size = s->frame_size_min; |
1320 | 1352 |
|
1321 |
/* set bandwidth */ |
|
1322 |
if (avctx->cutoff) { |
|
1323 |
/* calculate bandwidth based on user-specified cutoff frequency */ |
|
1324 |
int cutoff = av_clip(avctx->cutoff, 1, s->sample_rate >> 1); |
|
1325 |
int fbw_coeffs = cutoff * 2 * AC3_MAX_COEFS / s->sample_rate; |
|
1326 |
bw_code = av_clip((fbw_coeffs - 73) / 3, 0, 60); |
|
1327 |
} else { |
|
1328 |
/* use default bandwidth setting */ |
|
1329 |
/* XXX: should compute the bandwidth according to the frame |
|
1330 |
size, so that we avoid annoying high frequency artifacts */ |
|
1331 |
bw_code = 50; |
|
1332 |
} |
|
1333 |
for (ch = 0; ch < s->fbw_channels; ch++) { |
|
1334 |
/* bandwidth for each channel */ |
|
1335 |
s->bandwidth_code[ch] = bw_code; |
|
1336 |
s->nb_coefs[ch] = bw_code * 3 + 73; |
|
1337 |
} |
|
1338 |
if (s->lfe_on) |
|
1339 |
s->nb_coefs[s->lfe_channel] = 7; /* LFE channel always has 7 coefs */ |
|
1353 |
set_bandwidth(s, avctx->cutoff); |
|
1340 | 1354 |
|
1341 | 1355 |
/* initial snr offset */ |
1342 | 1356 |
s->coarse_snr_offset = 40; |
Also available in: Unified diff