/** * Init IMDCT and windowing tables */ static av_cold int init_mdct_win(TwinVQContext *tctx) { int i, j, ret; const TwinVQModeTab *mtab = tctx->mtab; int size_s = mtab->size / mtab->fmode[TWINVQ_FT_SHORT].sub; int size_m = mtab->size / mtab->fmode[TWINVQ_FT_MEDIUM].sub; int channels = tctx->avctx->channels; float norm = channels == 1 ? 2.0 : 1.0; for (i = 0; i < 3; i++) { int bsize = tctx->mtab->size / tctx->mtab->fmode[i].sub; if ((ret = ff_mdct_init(&tctx->mdct_ctx[i], av_log2(bsize) + 1, 1, -sqrt(norm / bsize) / (1 << 15)))) return ret; } FF_ALLOC_OR_GOTO(tctx->avctx, tctx->tmp_buf, mtab->size * sizeof(*tctx->tmp_buf), alloc_fail); FF_ALLOC_OR_GOTO(tctx->avctx, tctx->spectrum, 2 * mtab->size * channels * sizeof(*tctx->spectrum), alloc_fail); FF_ALLOC_OR_GOTO(tctx->avctx, tctx->curr_frame, 2 * mtab->size * channels * sizeof(*tctx->curr_frame), alloc_fail); FF_ALLOC_OR_GOTO(tctx->avctx, tctx->prev_frame, 2 * mtab->size * channels * sizeof(*tctx->prev_frame), alloc_fail); for (i = 0; i < 3; i++) { int m = 4 * mtab->size / mtab->fmode[i].sub; double freq = 2 * M_PI / m; FF_ALLOC_OR_GOTO(tctx->avctx, tctx->cos_tabs[i], (m / 4) * sizeof(*tctx->cos_tabs[i]), alloc_fail); for (j = 0; j <= m / 8; j++) tctx->cos_tabs[i][j] = cos((2 * j + 1) * freq); for (j = 1; j < m / 8; j++) tctx->cos_tabs[i][m / 4 - j] = tctx->cos_tabs[i][j]; } ff_init_ff_sine_windows(av_log2(size_m)); ff_init_ff_sine_windows(av_log2(size_s / 2)); ff_init_ff_sine_windows(av_log2(mtab->size)); return 0; alloc_fail: return AVERROR(ENOMEM); }
int AC3_NAME(allocate_sample_buffers)(AC3EncodeContext *s) { int ch; FF_ALLOC_OR_GOTO(s->avctx, s->windowed_samples, AC3_WINDOW_SIZE * sizeof(*s->windowed_samples), alloc_fail); FF_ALLOC_OR_GOTO(s->avctx, s->planar_samples, s->channels * sizeof(*s->planar_samples), alloc_fail); for (ch = 0; ch < s->channels; ch++) { FF_ALLOCZ_OR_GOTO(s->avctx, s->planar_samples[ch], (AC3_FRAME_SIZE+AC3_BLOCK_SIZE) * sizeof(**s->planar_samples), alloc_fail); } return 0; alloc_fail: return AVERROR(ENOMEM); }
static av_cold int adpcm_encode_init(AVCodecContext *avctx) { ADPCMEncodeContext *s = avctx->priv_data; uint8_t *extradata; int i; int ret = AVERROR(ENOMEM); if (avctx->channels > 2) { av_log(avctx, AV_LOG_ERROR, "only stereo or mono is supported\n"); return AVERROR(EINVAL); } if (avctx->trellis && (unsigned)avctx->trellis > 16U) { av_log(avctx, AV_LOG_ERROR, "invalid trellis size\n"); return AVERROR(EINVAL); } if (avctx->trellis) { int frontier = 1 << avctx->trellis; int max_paths = frontier * FREEZE_INTERVAL; FF_ALLOC_OR_GOTO(avctx, s->paths, max_paths * sizeof(*s->paths), error); FF_ALLOC_OR_GOTO(avctx, s->node_buf, 2 * frontier * sizeof(*s->node_buf), error); FF_ALLOC_OR_GOTO(avctx, s->nodep_buf, 2 * frontier * sizeof(*s->nodep_buf), error); FF_ALLOC_OR_GOTO(avctx, s->trellis_hash, 65536 * sizeof(*s->trellis_hash), error); } avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id); switch (avctx->codec->id) { case AV_CODEC_ID_ADPCM_IMA_WAV: /* each 16 bits sample gives one nibble and we have 4 bytes per channel overhead */ avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* seems frame_size isn't taken into account... have to buffer the samples :-( */ avctx->block_align = BLKSIZE; break; case AV_CODEC_ID_ADPCM_IMA_QT: avctx->frame_size = 64; avctx->block_align = 34 * avctx->channels; break; case AV_CODEC_ID_ADPCM_MS: /* each 16 bits sample gives one nibble and we have 7 bytes per channel overhead */ avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; avctx->block_align = BLKSIZE; if (!(avctx->extradata = av_malloc(32 + FF_INPUT_BUFFER_PADDING_SIZE))) goto error; avctx->extradata_size = 32; extradata = avctx->extradata; bytestream_put_le16(&extradata, avctx->frame_size); bytestream_put_le16(&extradata, 7); /* wNumCoef */ for (i = 0; i < 7; i++) { bytestream_put_le16(&extradata, ff_adpcm_AdaptCoeff1[i] * 4); bytestream_put_le16(&extradata, ff_adpcm_AdaptCoeff2[i] * 4); } break; case AV_CODEC_ID_ADPCM_YAMAHA: avctx->frame_size = BLKSIZE * 2 / avctx->channels; avctx->block_align = BLKSIZE; break; case AV_CODEC_ID_ADPCM_SWF: if (avctx->sample_rate != 11025 && avctx->sample_rate != 22050 && avctx->sample_rate != 44100) { av_log(avctx, AV_LOG_ERROR, "Sample rate must be 11025, " "22050 or 44100\n"); ret = AVERROR(EINVAL); goto error; } avctx->frame_size = 512 * (avctx->sample_rate / 11025); break; default: ret = AVERROR(EINVAL); goto error; } #if FF_API_OLD_ENCODE_AUDIO if (!(avctx->coded_frame = avcodec_alloc_frame())) goto error; #endif return 0; error: av_freep(&s->paths); av_freep(&s->node_buf); av_freep(&s->nodep_buf); av_freep(&s->trellis_hash); return ret; }