3 * Copyright (c) 2017 Rostislav Pehlivanov <atomnuker@gmail.com>
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef AVCODEC_OPUSENC_PSY_H
23 #define AVCODEC_OPUSENC_PSY_H
25 #include "libavutil/mem_internal.h"
28 #include "opusenc_utils.h"
29 #include "libavfilter/window_func.h"
31 /* Each step is 2.5ms */
32 typedef struct OpusPsyStep {
33 int index; /* Current index */
35 float energy[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]; /* Masking effects included */
36 float tone[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]; /* Tonality */
37 float stereo[CELT_MAX_BANDS]; /* IS/MS compatibility */
38 float change_amp[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]; /* Jump over last frame */
39 float total_change; /* Total change */
41 float *bands[OPUS_MAX_CHANNELS][CELT_MAX_BANDS];
42 float coeffs[OPUS_MAX_CHANNELS][OPUS_BLOCK_SIZE(CELT_BLOCK_960)];
45 typedef struct OpusBandExcitation {
47 float excitation_dist;
48 float excitation_init;
51 typedef struct PsyChain {
56 typedef struct OpusPsyContext {
57 AVCodecContext *avctx;
58 AVFloatDSPContext *dsp;
59 struct FFBufQueue *bufqueue;
60 OpusEncOptions *options;
65 OpusBandExcitation ex[OPUS_MAX_CHANNELS][CELT_MAX_BANDS];
66 FFBesselFilter bfilter_lo[OPUS_MAX_CHANNELS][CELT_MAX_BANDS];
67 FFBesselFilter bfilter_hi[OPUS_MAX_CHANNELS][CELT_MAX_BANDS];
69 OpusPsyStep *steps[FF_BUFQUEUE_SIZE + 1];
72 float *window[CELT_BLOCK_NB];
73 MDCT15Context *mdct[CELT_BLOCK_NB];
76 DECLARE_ALIGNED(32, float, scratch)[2048];
81 int64_t dual_stereo_used;
82 int64_t total_packets_out;
85 FFBesselFilter lambda_lp;
92 int *inflection_points;
93 int inflection_points_count;
96 int ff_opus_psy_process (OpusPsyContext *s, OpusPacketInfo *p);
97 void ff_opus_psy_celt_frame_init (OpusPsyContext *s, CeltFrame *f, int index);
98 int ff_opus_psy_celt_frame_process(OpusPsyContext *s, CeltFrame *f, int index);
99 void ff_opus_psy_postencode_update (OpusPsyContext *s, CeltFrame *f, OpusRangeCoder *rc);
101 int ff_opus_psy_init(OpusPsyContext *s, AVCodecContext *avctx,
102 struct FFBufQueue *bufqueue, OpusEncOptions *options);
103 void ff_opus_psy_signal_eof(OpusPsyContext *s);
104 int ff_opus_psy_end(OpusPsyContext *s);
106 #endif /* AVCODEC_OPUSENC_PSY_H */