29 float *
bits,
float lambda)
34 float buf[176 * 2], lowband_scratch[176], norm1[176], norm2[176];
35 float dist, cost, err_x = 0.0f, err_y = 0.0f;
42 memcpy(X, X_orig, band_size*
sizeof(
float));
44 memcpy(Y, Y_orig, band_size*
sizeof(
float));
47 if (band <= f->coded_bands - 1) {
53 pvq->
quant_band(pvq, f, rc, band, X,
NULL, band_size, b / 2, f->
blocks,
NULL,
54 f->
size, norm1, 0, 1.0f, lowband_scratch, cm[0]);
56 pvq->
quant_band(pvq, f, rc, band, Y,
NULL, band_size, b / 2, f->
blocks,
NULL,
57 f->
size, norm2, 0, 1.0f, lowband_scratch, cm[1]);
59 pvq->
quant_band(pvq, f, rc, band, X, Y, band_size, b, f->
blocks,
NULL, f->
size,
60 norm1, 0, 1.0f, lowband_scratch, cm[0] | cm[1]);
63 for (i = 0; i < band_size; i++) {
64 err_x += (X[
i] - X_orig[
i])*(X[i] - X_orig[i]);
66 err_y += (Y[
i] - Y_orig[
i])*(Y[i] - Y_orig[i]);
69 dist = sqrtf(err_x) + sqrtf(err_y);
75 return lambda*dist*cost;
81 int silence = 0, ch,
i, j;
88 for (i = 1; i <=
FFMIN(lap_size, index); i++) {
93 for (i = 0; i < lap_size; i++) {
94 const int offset = i*120 + lap_size;
110 float avg_c_s, energy = 0.0f, dist_dev = 0.0f;
112 const float *coeffs = st->
bands[ch][
i];
113 for (j = 0; j < range; j++)
114 energy += coeffs[j]*coeffs[j];
116 st->
energy[ch][
i] += sqrtf(energy);
117 silence |= !!st->
energy[ch][
i];
118 avg_c_s = energy / range;
120 for (j = 0; j < range; j++) {
121 const float c_s = coeffs[j]*coeffs[j];
122 dist_dev += (avg_c_s - c_s)*(avg_c_s - c_s);
125 st->
tone[ch][
i] += sqrtf(dist_dev);
133 float incompat = 0.0f;
134 const float *coeffs1 = st->
bands[0][
i];
135 const float *coeffs2 = st->
bands[1][
i];
137 for (j = 0; j < range; j++)
138 incompat += (coeffs1[j] - coeffs2[j])*(coeffs1[j] - coeffs2[j]);
139 st->
stereo[
i] = sqrtf(incompat);
169 float c_change = 0.0f;
170 if ((offset_e - offset_s) <= resolution)
172 for (i = offset_s; i < offset_e; i++) {
174 if (c_change > tgt_change)
186 int fsize, silent_frames;
188 for (silent_frames = 0; silent_frames < s->
buffered_steps; silent_frames++)
191 if (--silent_frames < 0)
195 if ((1 << fsize) > silent_frames)
197 s->
p.
frames =
FFMIN(silent_frames / (1 << fsize), 48 >> fsize);
226 float total_energy_change = 0.0f;
256 int i, neighbouring_points = 0, start_offset = 0;
257 int radius = (1 << s->
p.
framesize), step_offset = radius*index;
265 for (i = 0; i < (1 << f->
size); i++)
283 neighbouring_points++;
307 memset(f->
alloc_boost, 0,
sizeof(
int)*CELT_MAX_BANDS);
315 float rate, frame_bits = 0;
322 float max_score = 1.0f;
327 float tonal_contrib = 0.0f;
332 tonal_contrib += start[
f]->
tone[ch][
i];
335 tonal += tonal_contrib;
339 tonal /= (float)CELT_MAX_BANDS;
342 if (band_score[i] > max_score)
343 max_score = band_score[
i];
348 frame_bits += band_score[
i]*8.0f;
354 rate = ((float)s->
avctx->
bit_rate) + frame_bits*frame_size*16;
401 float dist, best_dist = FLT_MAX;
408 for (i = f->
end_band; i >= end_band; i--) {
411 if (best_dist > dist) {
424 float score[2] = { 0 };
426 for (cway = 0; cway < 2; cway++) {
430 for (i = 0; i < 2; i++) {
432 mag[
i] = c < 0 ? base >>
FFABS(c) : base <<
FFABS(c);
436 float iscore0 = 0.0f;
437 float iscore1 = 0.0f;
438 for (j = 0; j < (1 << f->
size); j++) {
444 config[cway][
i] =
FFABS(iscore0 - 1.0f) <
FFABS(iscore1 - 1.0f);
445 score[cway] += config[cway][
i] ? iscore1 : iscore0;
468 if (f->
transient != start_transient_flag) {
482 int steps_out = s->
p.
frames*(frame_size/120);
486 for (i = 0; i < steps_out; i++)
490 tmp[i] = s->
steps[i];
493 const int i_new = i - steps_out;
502 for (i = 0; i < s->
p.
frames; i++) {
MDCT15Context * mdct[CELT_BLOCK_NB]
void ff_opus_psy_celt_frame_init(OpusPsyContext *s, CeltFrame *f, int index)
static int flush_silent_frames(OpusPsyContext *s)
#define OPUS_SAMPLES_TO_BLOCK_SIZE(x)
int64_t total_packets_out
enum OpusBandwidth bandwidth
struct FFBufQueue * bufqueue
#define OPUS_RC_CHECKPOINT_SPAWN(rc)
This structure describes decoded (raw) audio or video data.
float * window[CELT_BLOCK_NB]
void ff_opus_rc_enc_init(OpusRangeCoder *rc)
float coeffs[CELT_MAX_FRAME_SIZE]
int64_t bit_rate
the average bitrate
OpusPsyStep * steps[FF_BUFQUEUE_SIZE+1]
FFBesselFilter bfilter_hi[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]
FFBesselFilter bfilter_lo[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]
const uint8_t ff_celt_freq_bands[]
static __device__ float ceilf(float a)
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define OPUS_MAX_PACKET_SIZE
Structure holding the queue.
const uint8_t ff_celt_band_end[]
float coeffs[OPUS_MAX_CHANNELS][OPUS_BLOCK_SIZE(CELT_BLOCK_960)]
static float bessel_filter(FFBesselFilter *s, float x)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
float stereo[CELT_MAX_BANDS]
void(* mdct)(struct MDCT15Context *s, float *dst, const float *src, ptrdiff_t stride)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats and store the result in a vector of floats...
int ff_opus_psy_process(OpusPsyContext *s, OpusPacketInfo *p)
av_cold int ff_mdct15_init(MDCT15Context **ps, int inverse, int N, double scale)
int ff_opus_psy_celt_frame_process(OpusPsyContext *s, CeltFrame *f, int index)
int alloc_boost[CELT_MAX_BANDS]
static int bands_dist(OpusPsyContext *s, CeltFrame *f, float *total_dist)
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
#define OPUS_BLOCK_SIZE(x)
static float pvq_band_cost(CeltPVQ *pvq, CeltFrame *f, OpusRangeCoder *rc, int band, float *bits, float lambda)
#define OPUS_RC_CHECKPOINT_ROLLBACK(rc)
int flags
AV_CODEC_FLAG_*.
av_cold int ff_opus_psy_init(OpusPsyContext *s, AVCodecContext *avctx, struct FFBufQueue *bufqueue, OpusEncOptions *options)
int tf_change[CELT_MAX_BANDS]
int pulses[CELT_MAX_BANDS]
static void celt_search_for_dual_stereo(OpusPsyContext *s, CeltFrame *f)
float * bands[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]
const int8_t ff_celt_tf_select[4][2][2][2]
static void celt_gauge_psy_weight(OpusPsyContext *s, OpusPsyStep **start, CeltFrame *f_out)
static int celt_search_for_tf(OpusPsyContext *s, OpusPsyStep **start, CeltFrame *f)
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
float tone[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]
float change_amp[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]
#define OPUS_RC_CHECKPOINT_BITS(rc)
static void psy_output_groups(OpusPsyContext *s)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int inflection_points_count
const uint8_t ff_celt_freq_range[]
#define AV_LOG_INFO
Standard information.
int sample_rate
samples per second
main external API structure.
static int bessel_init(FFBesselFilter *s, float n, float f0, float fs, int highpass)
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted then it is pulled from the input slice through the input converter and horizontal scaler The result is also stored in the ring buffer to serve future vertical scaler requests When no more output can be generated because lines from a future slice would be then all remaining lines in the current slice are horizontally scaled and put in the ring buffer[This is done for luma and chroma, each with possibly different numbers of lines per picture.] Input to YUV Converter When the input to the main path is not planar bits per component YUV or bit it is converted to planar bit YUV Two sets of converters exist for this the other leaves the full chroma resolution
void ff_opus_psy_signal_eof(OpusPsyContext *s)
static void celt_search_for_intensity(OpusPsyContext *s, CeltFrame *f)
void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode)
av_cold int ff_opus_psy_end(OpusPsyContext *s)
void ff_opus_psy_postencode_update(OpusPsyContext *s, CeltFrame *f, OpusRangeCoder *rc)
static int weight(int i, int blen, int offset)
const OptionDef options[]
av_cold void ff_mdct15_uninit(MDCT15Context **ps)
static void step_collect_psy_metrics(OpusPsyContext *s, int index)
int channels
number of audio channels
float energy[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]
static int64_t fsize(FILE *f)
static void search_for_change_points(OpusPsyContext *s, float tgt_change, int offset_s, int offset_e, int resolution, int level)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
uint8_t ** extended_data
pointers to the data planes/channels.
int nb_samples
number of audio samples (per channel) described by this frame
OpusBandExcitation ex[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]
static av_always_inline uint32_t opus_rc_tell_frac(const OpusRangeCoder *rc)
static AVFrame * ff_bufqueue_peek(struct FFBufQueue *queue, unsigned index)
Get a buffer from the queue without altering it.