static av_cold int aac_encode_init(AVCodecContext *avctx) { AACEncContext *s = avctx->priv_data; int i; const uint8_t *sizes[2]; int lengths[2]; avctx->frame_size = 1024; for (i = 0; i < 16; i++) if (avctx->sample_rate == ff_mpeg4audio_sample_rates[i]) break; if (i == 16) { av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", avctx->sample_rate); return -1; } if (avctx->channels > AAC_MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\n", avctx->channels); return -1; } if (avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile != FF_PROFILE_AAC_LOW) { av_log(avctx, AV_LOG_ERROR, "Unsupported profile %d\n", avctx->profile); return -1; } if (1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * avctx->channels) { av_log(avctx, AV_LOG_ERROR, "Too many bits per frame requested\n"); return -1; } s->samplerate_index = i; dsputil_init(&s->dsp, avctx); ff_mdct_init(&s->mdct1024, 11, 0, 1.0); ff_mdct_init(&s->mdct128, 8, 0, 1.0); // window init ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); ff_init_ff_sine_windows(10); ff_init_ff_sine_windows(7); s->chan_map = aac_chan_configs[avctx->channels-1]; s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0])); s->cpe = av_mallocz(sizeof(ChannelElement) * s->chan_map[0]); avctx->extradata = av_mallocz(5 + FF_INPUT_BUFFER_PADDING_SIZE); avctx->extradata_size = 5; put_audio_specific_config(avctx); sizes[0] = swb_size_1024[i]; sizes[1] = swb_size_128[i]; lengths[0] = ff_aac_num_swb_1024[i]; lengths[1] = ff_aac_num_swb_128[i]; ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], &s->chan_map[1]); s->psypp = ff_psy_preprocess_init(avctx); s->coder = &ff_aac_coders[2]; s->lambda = avctx->global_quality ? avctx->global_quality : 120; ff_aac_tableinit(); return 0; }
av_cold void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx) { ff_init_ff_sine_windows(7); ff_init_ff_sine_windows(6); /* Initialize the MDCT transform. */ ff_mdct_init(mdct_ctx, 8, 1, -1.0); }
/** * 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); }
static av_cold int decode_init(AVCodecContext * avctx) { NellyMoserDecodeContext *s = avctx->priv_data; s->avctx = avctx; s->imdct_out = s->imdct_buf[0]; s->imdct_prev = s->imdct_buf[1]; av_lfg_init(&s->random_state, 0); ff_mdct_init(&s->imdct_ctx, 8, 1, 1.0); avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); s->scale_bias = 1.0/(32768*8); avctx->sample_fmt = AV_SAMPLE_FMT_FLT; /* Generate overlap window */ if (!ff_sine_128[127]) ff_init_ff_sine_windows(7); avctx->channels = 1; avctx->channel_layout = AV_CH_LAYOUT_MONO; avcodec_get_frame_defaults(&s->frame); avctx->coded_frame = &s->frame; return 0; }
static av_cold int decode_init(AVCodecContext * avctx) { NellyMoserDecodeContext *s = avctx->priv_data; s->avctx = avctx; av_lfg_init(&s->random_state, 0); ff_mdct_init(&s->imdct_ctx, 8, 1, 1.0); dsputil_init(&s->dsp, avctx); if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) { s->scale_bias = 1.0/(32768*8); avctx->sample_fmt = AV_SAMPLE_FMT_FLT; } else { s->scale_bias = 1.0/(1*8); avctx->sample_fmt = AV_SAMPLE_FMT_S16; ff_fmt_convert_init(&s->fmt_conv, avctx); s->float_buf = av_mallocz(NELLY_SAMPLES * sizeof(*s->float_buf)); if (!s->float_buf) { av_log(avctx, AV_LOG_ERROR, "error allocating float buffer\n"); return AVERROR(ENOMEM); } } /* Generate overlap window */ if (!ff_sine_128[127]) ff_init_ff_sine_windows(7); avctx->channel_layout = AV_CH_LAYOUT_MONO; avcodec_get_frame_defaults(&s->frame); avctx->coded_frame = &s->frame; return 0; }
static av_cold int decode_init(AVCodecContext * avctx) { NellyMoserDecodeContext *s = avctx->priv_data; s->avctx = avctx; av_lfg_init(&s->random_state, 0); ff_mdct_init(&s->imdct_ctx, 8, 1, 1.0); dsputil_init(&s->dsp, avctx); if(s->dsp.float_to_int16 == ff_float_to_int16_c) { s->add_bias = 385; s->scale_bias = 1.0/(8*32768); } else { s->add_bias = 0; s->scale_bias = 1.0/(1*8); } /* Generate overlap window */ if (!ff_sine_128[127]) ff_init_ff_sine_windows(7); avctx->sample_fmt = SAMPLE_FMT_S16; avctx->channel_layout = CH_LAYOUT_MONO; return 0; }
static av_cold int dsp_init(AVCodecContext *avctx, AACEncContext *s) { int ret = 0; avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); // window init ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); ff_init_ff_sine_windows(10); ff_init_ff_sine_windows(7); if (ret = ff_mdct_init(&s->mdct1024, 11, 0, 32768.0)) return ret; if (ret = ff_mdct_init(&s->mdct128, 8, 0, 32768.0)) return ret; return 0; }
static av_cold int dsp_init(AVCodecContext *avctx, AACEncContext *s) { int ret = 0; ff_dsputil_init(&s->dsp, avctx); // window init ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); ff_init_ff_sine_windows(10); ff_init_ff_sine_windows(7); if (ret = ff_mdct_init(&s->mdct1024, 11, 0, 32768.0)) return ret; if (ret = ff_mdct_init(&s->mdct128, 8, 0, 32768.0)) return ret; return 0; }
int main(void) { int i; write_fileheader(); for (i = 5; i <= 12; i++) { ff_init_ff_sine_windows(i); printf("SINETABLE(%4i) = {\n", 1 << i); write_float_array(ff_sine_windows[i], 1 << i); printf("};\n"); } return 0; }
static av_cold int decode_init(AVCodecContext * avctx) { NellyMoserDecodeContext *s = avctx->priv_data; s->avctx = avctx; av_lfg_init(&s->random_state, 0); ff_mdct_init(&s->imdct_ctx, 8, 1, 1.0); dsputil_init(&s->dsp, avctx); ff_fmt_convert_init(&s->fmt_conv, avctx); s->scale_bias = 1.0/(1*8); /* Generate overlap window */ if (!ff_sine_128[127]) ff_init_ff_sine_windows(7); avctx->sample_fmt = AV_SAMPLE_FMT_S16; avctx->channel_layout = AV_CH_LAYOUT_MONO; return 0; }
static av_cold int aac_encode_init(AVCodecContext *avctx) { AACEncContext *s = avctx->priv_data; int i; const uint8_t *sizes[2]; int lengths[2]; avctx->frame_size = 1024; for (i = 0; i < 16; i++) if (avctx->sample_rate == ff_mpeg4audio_sample_rates[i]) break; if (i == 16) { av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", avctx->sample_rate); return -1; } if (avctx->channels > 6) { av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\n", avctx->channels); return -1; } if (avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile != FF_PROFILE_AAC_LOW) { av_log(avctx, AV_LOG_ERROR, "Unsupported profile %d\n", avctx->profile); return -1; } if (1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * avctx->channels) { av_log(avctx, AV_LOG_ERROR, "Too many bits per frame requested\n"); return -1; } s->samplerate_index = i; dsputil_init(&s->dsp, avctx); ff_mdct_init(&s->mdct1024, 11, 0, 1.0); ff_mdct_init(&s->mdct128, 8, 0, 1.0); // window init ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); ff_init_ff_sine_windows(10); ff_init_ff_sine_windows(7); s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0])); s->cpe = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]); avctx->extradata = av_malloc(2); avctx->extradata_size = 2; put_audio_specific_config(avctx); sizes[0] = swb_size_1024[i]; sizes[1] = swb_size_128[i]; lengths[0] = ff_aac_num_swb_1024[i]; lengths[1] = ff_aac_num_swb_128[i]; ff_psy_init(&s->psy, avctx, 2, sizes, lengths); s->psypp = ff_psy_preprocess_init(avctx); s->coder = &ff_aac_coders[0]; s->lambda = avctx->global_quality ? avctx->global_quality : 120; #if !CONFIG_HARDCODED_TABLES for (i = 0; i < 428; i++) ff_aac_pow2sf_tab[i] = pow(2, (i - 200)/4.); #endif /* CONFIG_HARDCODED_TABLES */ if (avctx->channels > 5) av_log(avctx, AV_LOG_ERROR, "This encoder does not yet enforce the restrictions on LFEs. " "The output will most likely be an illegal bitstream.\n"); return 0; }
static av_cold int aac_decode_init(AVCodecContext *avctx) { AACContext *ac = avctx->priv_data; ac->avctx = avctx; ac->m4ac.sample_rate = avctx->sample_rate; if (avctx->extradata_size > 0) { if (decode_audio_specific_config(ac, avctx->extradata, avctx->extradata_size)) return -1; } avctx->sample_fmt = SAMPLE_FMT_S16; AAC_INIT_VLC_STATIC( 0, 304); AAC_INIT_VLC_STATIC( 1, 270); AAC_INIT_VLC_STATIC( 2, 550); AAC_INIT_VLC_STATIC( 3, 300); AAC_INIT_VLC_STATIC( 4, 328); AAC_INIT_VLC_STATIC( 5, 294); AAC_INIT_VLC_STATIC( 6, 306); AAC_INIT_VLC_STATIC( 7, 268); AAC_INIT_VLC_STATIC( 8, 510); AAC_INIT_VLC_STATIC( 9, 366); AAC_INIT_VLC_STATIC(10, 462); ff_aac_sbr_init(); dsputil_init(&ac->dsp, avctx); ac->random_state = 0x1f2e3d4c; // -1024 - Compensate wrong IMDCT method. // 32768 - Required to scale values to the correct range for the bias method // for float to int16 conversion. if (ac->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { ac->add_bias = 385.0f; ac->sf_scale = 1. / (-1024. * 32768.); ac->sf_offset = 0; } else { ac->add_bias = 0.0f; ac->sf_scale = 1. / -1024.; ac->sf_offset = 60; } ff_aac_tableinit(); INIT_VLC_STATIC(&vlc_scalefactors,7,FF_ARRAY_ELEMS(ff_aac_scalefactor_code), ff_aac_scalefactor_bits, sizeof(ff_aac_scalefactor_bits[0]), sizeof(ff_aac_scalefactor_bits[0]), ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]), 352); ff_mdct_init(&ac->mdct, 11, 1, 1.0); ff_mdct_init(&ac->mdct_small, 8, 1, 1.0); // window initialization ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); ff_init_ff_sine_windows(10); ff_init_ff_sine_windows( 7); cbrt_tableinit(); return 0; }