FFmpeg
opusenc_psy.c
Go to the documentation of this file.
1 /*
2  * Opus encoder
3  * Copyright (c) 2017 Rostislav Pehlivanov <atomnuker@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
20  */
21 
22 #include <float.h>
23 
24 #include "opusenc_psy.h"
25 #include "opus_celt.h"
26 #include "opus_pvq.h"
27 #include "opustab.h"
29 
30 static float pvq_band_cost(CeltPVQ *pvq, CeltFrame *f, OpusRangeCoder *rc, int band,
31  float *bits, float lambda)
32 {
33  int i, b = 0;
34  uint32_t cm[2] = { (1 << f->blocks) - 1, (1 << f->blocks) - 1 };
35  const int band_size = ff_celt_freq_range[band] << f->size;
36  float buf[176 * 2], lowband_scratch[176], norm1[176], norm2[176];
37  float dist, cost, err_x = 0.0f, err_y = 0.0f;
38  float *X = buf;
39  float *X_orig = f->block[0].coeffs + (ff_celt_freq_bands[band] << f->size);
40  float *Y = (f->channels == 2) ? &buf[176] : NULL;
41  float *Y_orig = f->block[1].coeffs + (ff_celt_freq_bands[band] << f->size);
43 
44  memcpy(X, X_orig, band_size*sizeof(float));
45  if (Y)
46  memcpy(Y, Y_orig, band_size*sizeof(float));
47 
48  f->remaining2 = ((f->framebits << 3) - f->anticollapse_needed) - opus_rc_tell_frac(rc) - 1;
49  if (band <= f->coded_bands - 1) {
50  int curr_balance = f->remaining / FFMIN(3, f->coded_bands - band);
51  b = av_clip_uintp2(FFMIN(f->remaining2 + 1, f->pulses[band] + curr_balance), 14);
52  }
53 
54  if (f->dual_stereo) {
55  pvq->quant_band(pvq, f, rc, band, X, NULL, band_size, b / 2, f->blocks, NULL,
56  f->size, norm1, 0, 1.0f, lowband_scratch, cm[0]);
57 
58  pvq->quant_band(pvq, f, rc, band, Y, NULL, band_size, b / 2, f->blocks, NULL,
59  f->size, norm2, 0, 1.0f, lowband_scratch, cm[1]);
60  } else {
61  pvq->quant_band(pvq, f, rc, band, X, Y, band_size, b, f->blocks, NULL, f->size,
62  norm1, 0, 1.0f, lowband_scratch, cm[0] | cm[1]);
63  }
64 
65  for (i = 0; i < band_size; i++) {
66  err_x += (X[i] - X_orig[i])*(X[i] - X_orig[i]);
67  if (Y)
68  err_y += (Y[i] - Y_orig[i])*(Y[i] - Y_orig[i]);
69  }
70 
71  dist = sqrtf(err_x) + sqrtf(err_y);
72  cost = OPUS_RC_CHECKPOINT_BITS(rc)/8.0f;
73  *bits += cost;
74 
76 
77  return lambda*dist*cost;
78 }
79 
80 /* Populate metrics without taking into consideration neighbouring steps */
82 {
83  int silence = 0, ch, i, j;
84  OpusPsyStep *st = s->steps[index];
85 
86  st->index = index;
87 
88  for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
89  const int lap_size = (1 << s->bsize_analysis);
90  for (i = 1; i <= FFMIN(lap_size, index); i++) {
91  const int offset = i*120;
92  AVFrame *cur = ff_bufqueue_peek(s->bufqueue, index - i);
93  memcpy(&s->scratch[offset], cur->extended_data[ch], cur->nb_samples*sizeof(float));
94  }
95  for (i = 0; i < lap_size; i++) {
96  const int offset = i*120 + lap_size;
97  AVFrame *cur = ff_bufqueue_peek(s->bufqueue, index + i);
98  memcpy(&s->scratch[offset], cur->extended_data[ch], cur->nb_samples*sizeof(float));
99  }
100 
101  s->dsp->vector_fmul(s->scratch, s->scratch, s->window[s->bsize_analysis],
102  (OPUS_BLOCK_SIZE(s->bsize_analysis) << 1));
103 
104  s->mdct_fn[s->bsize_analysis](s->mdct[s->bsize_analysis], st->coeffs[ch],
105  s->scratch, sizeof(float));
106 
107  for (i = 0; i < CELT_MAX_BANDS; i++)
108  st->bands[ch][i] = &st->coeffs[ch][ff_celt_freq_bands[i] << s->bsize_analysis];
109  }
110 
111  for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
112  for (i = 0; i < CELT_MAX_BANDS; i++) {
113  float avg_c_s, energy = 0.0f, dist_dev = 0.0f;
114  const int range = ff_celt_freq_range[i] << s->bsize_analysis;
115  const float *coeffs = st->bands[ch][i];
116  for (j = 0; j < range; j++)
117  energy += coeffs[j]*coeffs[j];
118 
119  st->energy[ch][i] += sqrtf(energy);
120  silence |= !!st->energy[ch][i];
121  avg_c_s = energy / range;
122 
123  for (j = 0; j < range; j++) {
124  const float c_s = coeffs[j]*coeffs[j];
125  dist_dev += (avg_c_s - c_s)*(avg_c_s - c_s);
126  }
127 
128  st->tone[ch][i] += sqrtf(dist_dev);
129  }
130  }
131 
132  st->silence = !silence;
133 
134  if (s->avctx->ch_layout.nb_channels > 1) {
135  for (i = 0; i < CELT_MAX_BANDS; i++) {
136  float incompat = 0.0f;
137  const float *coeffs1 = st->bands[0][i];
138  const float *coeffs2 = st->bands[1][i];
139  const int range = ff_celt_freq_range[i] << s->bsize_analysis;
140  for (j = 0; j < range; j++)
141  incompat += (coeffs1[j] - coeffs2[j])*(coeffs1[j] - coeffs2[j]);
142  st->stereo[i] = sqrtf(incompat);
143  }
144  }
145 
146  for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
147  for (i = 0; i < CELT_MAX_BANDS; i++) {
148  OpusBandExcitation *ex = &s->ex[ch][i];
149  float bp_e = bessel_filter(&s->bfilter_lo[ch][i], st->energy[ch][i]);
150  bp_e = bessel_filter(&s->bfilter_hi[ch][i], bp_e);
151  bp_e *= bp_e;
152  if (bp_e > ex->excitation) {
153  st->change_amp[ch][i] = bp_e - ex->excitation;
154  st->total_change += st->change_amp[ch][i];
155  ex->excitation = ex->excitation_init = bp_e;
156  ex->excitation_dist = 0.0f;
157  }
158  if (ex->excitation > 0.0f) {
159  ex->excitation -= av_clipf((1/expf(ex->excitation_dist)), ex->excitation_init/20, ex->excitation_init/1.09);
160  ex->excitation = FFMAX(ex->excitation, 0.0f);
161  ex->excitation_dist += 1.0f;
162  }
163  }
164  }
165 }
166 
167 static void search_for_change_points(OpusPsyContext *s, float tgt_change,
168  int offset_s, int offset_e, int resolution,
169  int level)
170 {
171  int i;
172  float c_change = 0.0f;
173  if ((offset_e - offset_s) <= resolution)
174  return;
175  for (i = offset_s; i < offset_e; i++) {
176  c_change += s->steps[i]->total_change;
177  if (c_change > tgt_change)
178  break;
179  }
180  if (i == offset_e)
181  return;
182  search_for_change_points(s, tgt_change / 2.0f, offset_s, i + 0, resolution, level + 1);
183  s->inflection_points[s->inflection_points_count++] = i;
184  search_for_change_points(s, tgt_change / 2.0f, i + 1, offset_e, resolution, level + 1);
185 }
186 
188 {
189  int fsize, silent_frames;
190 
191  for (silent_frames = 0; silent_frames < s->buffered_steps; silent_frames++)
192  if (!s->steps[silent_frames]->silence)
193  break;
194  if (--silent_frames < 0)
195  return 0;
196 
198  if ((1 << fsize) > silent_frames)
199  continue;
200  s->p.frames = FFMIN(silent_frames / (1 << fsize), 48 >> fsize);
201  s->p.framesize = fsize;
202  return 1;
203  }
204 
205  return 0;
206 }
207 
208 /* Main function which decides frame size and frames per current packet */
210 {
211  int max_delay_samples = (s->options->max_delay_ms*s->avctx->sample_rate)/1000;
212  int max_bsize = FFMIN(OPUS_SAMPLES_TO_BLOCK_SIZE(max_delay_samples), CELT_BLOCK_960);
213 
214  /* These don't change for now */
215  s->p.mode = OPUS_MODE_CELT;
216  s->p.bandwidth = OPUS_BANDWIDTH_FULLBAND;
217 
218  /* Flush silent frames ASAP */
219  if (s->steps[0]->silence && flush_silent_frames(s))
220  return;
221 
222  s->p.framesize = FFMIN(max_bsize, CELT_BLOCK_960);
223  s->p.frames = 1;
224 }
225 
227 {
228  int i;
229  float total_energy_change = 0.0f;
230 
231  if (s->buffered_steps < s->max_steps && !s->eof) {
232  const int awin = (1 << s->bsize_analysis);
233  if (++s->steps_to_process >= awin) {
234  step_collect_psy_metrics(s, s->buffered_steps - awin + 1);
235  s->steps_to_process = 0;
236  }
237  if ((++s->buffered_steps) < s->max_steps)
238  return 1;
239  }
240 
241  for (i = 0; i < s->buffered_steps; i++)
242  total_energy_change += s->steps[i]->total_change;
243 
244  search_for_change_points(s, total_energy_change / 2.0f, 0,
245  s->buffered_steps, 1, 0);
246 
248 
249  p->frames = s->p.frames;
250  p->framesize = s->p.framesize;
251  p->mode = s->p.mode;
252  p->bandwidth = s->p.bandwidth;
253 
254  return 0;
255 }
256 
258 {
259  int i, neighbouring_points = 0, start_offset = 0;
260  int radius = (1 << s->p.framesize), step_offset = radius*index;
261  int silence = 1;
262 
263  f->start_band = (s->p.mode == OPUS_MODE_HYBRID) ? 17 : 0;
264  f->end_band = ff_celt_band_end[s->p.bandwidth];
265  f->channels = s->avctx->ch_layout.nb_channels;
266  f->size = s->p.framesize;
267 
268  for (i = 0; i < (1 << f->size); i++)
269  silence &= s->steps[index*(1 << f->size) + i]->silence;
270 
271  f->silence = silence;
272  if (f->silence) {
273  f->framebits = 0; /* Otherwise the silence flag eats up 16(!) bits */
274  return;
275  }
276 
277  for (i = 0; i < s->inflection_points_count; i++) {
278  if (s->inflection_points[i] >= step_offset) {
279  start_offset = i;
280  break;
281  }
282  }
283 
284  for (i = start_offset; i < FFMIN(radius, s->inflection_points_count - start_offset); i++) {
285  if (s->inflection_points[i] < (step_offset + radius)) {
286  neighbouring_points++;
287  }
288  }
289 
290  /* Transient flagging */
291  f->transient = neighbouring_points > 0;
292  f->blocks = f->transient ? OPUS_BLOCK_SIZE(s->p.framesize)/CELT_OVERLAP : 1;
293 
294  /* Some sane defaults */
295  f->pfilter = 0;
296  f->pf_gain = 0.5f;
297  f->pf_octave = 2;
298  f->pf_period = 1;
299  f->pf_tapset = 2;
300 
301  /* More sane defaults */
302  f->tf_select = 0;
303  f->anticollapse = 1;
304  f->alloc_trim = 5;
305  f->skip_band_floor = f->end_band;
306  f->intensity_stereo = f->end_band;
307  f->dual_stereo = 0;
308  f->spread = CELT_SPREAD_NORMAL;
309  memset(f->tf_change, 0, sizeof(int)*CELT_MAX_BANDS);
310  memset(f->alloc_boost, 0, sizeof(int)*CELT_MAX_BANDS);
311 }
312 
314  CeltFrame *f_out)
315 {
316  int i, f, ch;
317  int frame_size = OPUS_BLOCK_SIZE(s->p.framesize);
318  float rate, frame_bits = 0;
319 
320  /* Used for the global ROTATE flag */
321  float tonal = 0.0f;
322 
323  /* Pseudo-weights */
324  float band_score[CELT_MAX_BANDS] = { 0 };
325  float max_score = 1.0f;
326 
327  /* Pass one - one loop around each band, computing unquant stuff */
328  for (i = 0; i < CELT_MAX_BANDS; i++) {
329  float weight = 0.0f;
330  float tonal_contrib = 0.0f;
331  for (f = 0; f < (1 << s->p.framesize); f++) {
332  weight = start[f]->stereo[i];
333  for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
334  weight += start[f]->change_amp[ch][i] + start[f]->tone[ch][i] + start[f]->energy[ch][i];
335  tonal_contrib += start[f]->tone[ch][i];
336  }
337  }
338  tonal += tonal_contrib;
339  band_score[i] = weight;
340  }
341 
342  tonal /= (float)CELT_MAX_BANDS;
343 
344  for (i = 0; i < CELT_MAX_BANDS; i++) {
345  if (band_score[i] > max_score)
346  max_score = band_score[i];
347  }
348 
349  for (i = 0; i < CELT_MAX_BANDS; i++) {
350  f_out->alloc_boost[i] = (int)((band_score[i]/max_score)*3.0f);
351  frame_bits += band_score[i]*8.0f;
352  }
353 
354  tonal /= 1333136.0f;
355  f_out->spread = av_clip_uintp2(lrintf(tonal), 2);
356 
357  rate = ((float)s->avctx->bit_rate) + frame_bits*frame_size*16;
358  rate *= s->lambda;
359  rate /= s->avctx->sample_rate/frame_size;
360 
361  f_out->framebits = lrintf(rate);
362  f_out->framebits = FFMIN(f_out->framebits, OPUS_MAX_FRAME_SIZE * 8);
363  f_out->framebits = FFALIGN(f_out->framebits, 8);
364 }
365 
366 static int bands_dist(OpusPsyContext *s, CeltFrame *f, float *total_dist)
367 {
368  int i, tdist = 0.0f;
369  OpusRangeCoder dump;
370 
371  ff_opus_rc_enc_init(&dump);
372  ff_celt_bitalloc(f, &dump, 1);
373 
374  for (i = 0; i < CELT_MAX_BANDS; i++) {
375  float bits = 0.0f;
376  float dist = pvq_band_cost(f->pvq, f, &dump, i, &bits, s->lambda);
377  tdist += dist;
378  }
379 
380  *total_dist = tdist;
381 
382  return 0;
383 }
384 
386 {
387  float td1, td2;
388  f->dual_stereo = 0;
389 
390  if (s->avctx->ch_layout.nb_channels < 2)
391  return;
392 
393  bands_dist(s, f, &td1);
394  f->dual_stereo = 1;
395  bands_dist(s, f, &td2);
396 
397  f->dual_stereo = td2 < td1;
398  s->dual_stereo_used += td2 < td1;
399 }
400 
402 {
403  int i, best_band = CELT_MAX_BANDS - 1;
404  float dist, best_dist = FLT_MAX;
405  /* TODO: fix, make some heuristic up here using the lambda value */
406  float end_band = 0;
407 
408  if (s->avctx->ch_layout.nb_channels < 2)
409  return;
410 
411  for (i = f->end_band; i >= end_band; i--) {
412  f->intensity_stereo = i;
413  bands_dist(s, f, &dist);
414  if (best_dist > dist) {
415  best_dist = dist;
416  best_band = i;
417  }
418  }
419 
420  f->intensity_stereo = best_band;
421  s->avg_is_band = (s->avg_is_band + f->intensity_stereo)/2.0f;
422 }
423 
425 {
426  int i, j, k, cway, config[2][CELT_MAX_BANDS] = { { 0 } };
427  float score[2] = { 0 };
428 
429  for (cway = 0; cway < 2; cway++) {
430  int mag[2];
431  int base = f->transient ? 120 : 960;
432 
433  for (i = 0; i < 2; i++) {
434  int c = ff_celt_tf_select[f->size][f->transient][cway][i];
435  mag[i] = c < 0 ? base >> FFABS(c) : base << FFABS(c);
436  }
437 
438  for (i = 0; i < CELT_MAX_BANDS; i++) {
439  float iscore0 = 0.0f;
440  float iscore1 = 0.0f;
441  for (j = 0; j < (1 << f->size); j++) {
442  for (k = 0; k < s->avctx->ch_layout.nb_channels; k++) {
443  iscore0 += start[j]->tone[k][i]*start[j]->change_amp[k][i]/mag[0];
444  iscore1 += start[j]->tone[k][i]*start[j]->change_amp[k][i]/mag[1];
445  }
446  }
447  config[cway][i] = FFABS(iscore0 - 1.0f) < FFABS(iscore1 - 1.0f);
448  score[cway] += config[cway][i] ? iscore1 : iscore0;
449  }
450  }
451 
452  f->tf_select = score[0] < score[1];
453  memcpy(f->tf_change, config[f->tf_select], sizeof(int)*CELT_MAX_BANDS);
454 
455  return 0;
456 }
457 
459 {
460  int start_transient_flag = f->transient;
461  OpusPsyStep **start = &s->steps[index * (1 << s->p.framesize)];
462 
463  if (f->silence)
464  return 0;
465 
466  celt_gauge_psy_weight(s, start, f);
469  celt_search_for_tf(s, start, f);
470 
471  if (f->transient != start_transient_flag) {
472  f->blocks = f->transient ? OPUS_BLOCK_SIZE(s->p.framesize)/CELT_OVERLAP : 1;
473  return 1;
474  }
475 
476  return 0;
477 }
478 
480 {
481  int i, frame_size = OPUS_BLOCK_SIZE(s->p.framesize);
482  int steps_out = s->p.frames*(frame_size/120);
483  void *tmp[FF_BUFQUEUE_SIZE];
484  float ideal_fbits;
485 
486  for (i = 0; i < steps_out; i++)
487  memset(s->steps[i], 0, sizeof(OpusPsyStep));
488 
489  for (i = 0; i < s->max_steps; i++)
490  tmp[i] = s->steps[i];
491 
492  for (i = 0; i < s->max_steps; i++) {
493  const int i_new = i - steps_out;
494  s->steps[i_new < 0 ? s->max_steps + i_new : i_new] = tmp[i];
495  }
496 
497  for (i = steps_out; i < s->buffered_steps; i++)
498  s->steps[i]->index -= steps_out;
499 
500  ideal_fbits = s->avctx->bit_rate/(s->avctx->sample_rate/frame_size);
501 
502  for (i = 0; i < s->p.frames; i++) {
503  s->avg_is_band += f[i].intensity_stereo;
504  s->lambda *= ideal_fbits / f[i].framebits;
505  }
506 
507  s->avg_is_band /= (s->p.frames + 1);
508 
509  s->steps_to_process = 0;
510  s->buffered_steps -= steps_out;
511  s->total_packets_out += s->p.frames;
512  s->inflection_points_count = 0;
513 }
514 
516  struct FFBufQueue *bufqueue, OpusEncOptions *options)
517 {
518  int i, ch, ret;
519 
520  s->lambda = 1.0f;
521  s->options = options;
522  s->avctx = avctx;
523  s->bufqueue = bufqueue;
524  s->max_steps = ceilf(s->options->max_delay_ms/2.5f);
525  s->bsize_analysis = CELT_BLOCK_960;
526  s->avg_is_band = CELT_MAX_BANDS - 1;
527  s->inflection_points_count = 0;
528 
529  s->inflection_points = av_mallocz(sizeof(*s->inflection_points)*s->max_steps);
530  if (!s->inflection_points) {
531  ret = AVERROR(ENOMEM);
532  goto fail;
533  }
534 
536  if (!s->dsp) {
537  ret = AVERROR(ENOMEM);
538  goto fail;
539  }
540 
541  for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
542  for (i = 0; i < CELT_MAX_BANDS; i++) {
543  bessel_init(&s->bfilter_hi[ch][i], 1.0f, 19.0f, 100.0f, 1);
544  bessel_init(&s->bfilter_lo[ch][i], 1.0f, 20.0f, 100.0f, 0);
545  }
546  }
547 
548  for (i = 0; i < s->max_steps; i++) {
549  s->steps[i] = av_mallocz(sizeof(OpusPsyStep));
550  if (!s->steps[i]) {
551  ret = AVERROR(ENOMEM);
552  goto fail;
553  }
554  }
555 
556  for (i = 0; i < CELT_BLOCK_NB; i++) {
557  float tmp;
558  const int len = OPUS_BLOCK_SIZE(i);
559  const float scale = 68 << (CELT_BLOCK_NB - 1 - i);
560  s->window[i] = av_malloc(2*len*sizeof(float));
561  if (!s->window[i]) {
562  ret = AVERROR(ENOMEM);
563  goto fail;
564  }
565  generate_window_func(s->window[i], 2*len, WFUNC_SINE, &tmp);
566  ret = av_tx_init(&s->mdct[i], &s->mdct_fn[i], AV_TX_FLOAT_MDCT,
567  0, 15 << (i + 3), &scale, 0);
568  if (ret < 0)
569  goto fail;
570  }
571 
572  return 0;
573 
574 fail:
575  av_freep(&s->inflection_points);
576  av_freep(&s->dsp);
577 
578  for (i = 0; i < CELT_BLOCK_NB; i++) {
579  av_tx_uninit(&s->mdct[i]);
580  av_freep(&s->window[i]);
581  }
582 
583  for (i = 0; i < s->max_steps; i++)
584  av_freep(&s->steps[i]);
585 
586  return ret;
587 }
588 
590 {
591  s->eof = 1;
592 }
593 
595 {
596  int i;
597 
598  av_freep(&s->inflection_points);
599  av_freep(&s->dsp);
600 
601  for (i = 0; i < CELT_BLOCK_NB; i++) {
602  av_tx_uninit(&s->mdct[i]);
603  av_freep(&s->window[i]);
604  }
605 
606  for (i = 0; i < s->max_steps; i++)
607  av_freep(&s->steps[i]);
608 
609  av_log(s->avctx, AV_LOG_INFO, "Average Intensity Stereo band: %0.1f\n", s->avg_is_band);
610  av_log(s->avctx, AV_LOG_INFO, "Dual Stereo used: %0.2f%%\n", ((float)s->dual_stereo_used/s->total_packets_out)*100.0f);
611 
612  return 0;
613 }
OpusPsyStep::stereo
float stereo[CELT_MAX_BANDS]
Definition: opusenc_psy.h:38
ff_opus_psy_process
int ff_opus_psy_process(OpusPsyContext *s, OpusPacketInfo *p)
Definition: opusenc_psy.c:226
level
uint8_t level
Definition: svq3.c:204
AVERROR
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
ff_celt_freq_bands
const uint8_t ff_celt_freq_bands[]
Definition: opustab.c:768
OpusBandExcitation::excitation
float excitation
Definition: opusenc_psy.h:47
ff_opus_psy_celt_frame_init
void ff_opus_psy_celt_frame_init(OpusPsyContext *s, CeltFrame *f, int index)
Definition: opusenc_psy.c:257
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:120
OPUS_MAX_FRAME_SIZE
#define OPUS_MAX_FRAME_SIZE
Definition: opus.h:28
celt_search_for_dual_stereo
static void celt_search_for_dual_stereo(OpusPsyContext *s, CeltFrame *f)
Definition: opusenc_psy.c:385
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
OpusBandExcitation::excitation_init
float excitation_init
Definition: opusenc_psy.h:49
FF_BUFQUEUE_SIZE
#define FF_BUFQUEUE_SIZE
Definition: audiotoolboxenc.c:25
CeltFrame::spread
enum CeltSpread spread
Definition: opus_celt.h:129
OpusPacketInfo::frames
int frames
Definition: opusenc.h:52
OpusPacketInfo::bandwidth
enum OpusBandwidth bandwidth
Definition: opusenc.h:50
b
#define b
Definition: input.c:41
OPUS_RC_CHECKPOINT_SPAWN
#define OPUS_RC_CHECKPOINT_SPAWN(rc)
Definition: opus_rc.h:115
expf
#define expf(x)
Definition: libm.h:283
base
uint8_t base
Definition: vp3data.h:128
float.h
OpusPsyStep::silence
int silence
Definition: opusenc_psy.h:35
OPUS_BANDWIDTH_FULLBAND
@ OPUS_BANDWIDTH_FULLBAND
Definition: opus.h:54
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
CeltFrame::framebits
int framebits
Definition: opus_celt.h:138
CELT_BLOCK_960
@ CELT_BLOCK_960
Definition: opus_celt.h:65
OpusPsyStep::coeffs
float coeffs[OPUS_MAX_CHANNELS][OPUS_BLOCK_SIZE(CELT_BLOCK_960)]
Definition: opusenc_psy.h:43
tf_sess_config.config
config
Definition: tf_sess_config.py:33
ceilf
static __device__ float ceilf(float a)
Definition: cuda_runtime.h:175
av_tx_init
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:901
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
CeltPVQ
Definition: opus_pvq.h:37
celt_search_for_tf
static int celt_search_for_tf(OpusPsyContext *s, OpusPsyStep **start, CeltFrame *f)
Definition: opusenc_psy.c:424
fail
#define fail()
Definition: checkasm.h:138
resolution
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
Definition: swscale.txt:54
OpusPsyStep::change_amp
float change_amp[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]
Definition: opusenc_psy.h:39
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:521
ff_opus_psy_end
av_cold int ff_opus_psy_end(OpusPsyContext *s)
Definition: opusenc_psy.c:594
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
CELT_BLOCK_120
@ CELT_BLOCK_120
Definition: opus_celt.h:62
bessel_init
static int bessel_init(FFBesselFilter *s, float n, float f0, float fs, int highpass)
Definition: opusenc_utils.h:72
psy_output_groups
static void psy_output_groups(OpusPsyContext *s)
Definition: opusenc_psy.c:209
OpusPacketInfo::mode
enum OpusMode mode
Definition: opusenc.h:49
av_cold
#define av_cold
Definition: attributes.h:90
OPUS_BLOCK_SIZE
#define OPUS_BLOCK_SIZE(x)
Definition: opusenc.h:39
CeltPVQ::quant_band
QUANT_FN * quant_band
Definition: opus_pvq.h:42
float
float
Definition: af_crystalizer.c:121
ff_celt_band_end
const uint8_t ff_celt_band_end[]
Definition: opustab.c:29
AV_TX_FLOAT_MDCT
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respecively.
Definition: tx.h:68
OpusPsyStep
Definition: opusenc_psy.h:33
X
@ X
Definition: vf_addroi.c:27
s
#define s(width, name)
Definition: cbs_vp9.c:198
frame_size
int frame_size
Definition: mxfenc.c:2311
CELT_SPREAD_NORMAL
@ CELT_SPREAD_NORMAL
Definition: opus_celt.h:57
ff_opus_psy_celt_frame_process
int ff_opus_psy_celt_frame_process(OpusPsyContext *s, CeltFrame *f, int index)
Definition: opusenc_psy.c:458
bits
uint8_t bits
Definition: vp3data.h:128
CeltFrame::alloc_boost
int alloc_boost[CELT_MAX_BANDS]
Definition: opus_celt.h:119
fsize
static int64_t fsize(FILE *f)
Definition: audiomatch.c:29
OpusPsyContext
Definition: opusenc_psy.h:52
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:65
OpusBandExcitation::excitation_dist
float excitation_dist
Definition: opusenc_psy.h:48
OpusPacketInfo
Definition: opusenc.h:48
OPUS_MODE_CELT
@ OPUS_MODE_CELT
Definition: opus.h:44
bands_dist
static int bands_dist(OpusPsyContext *s, CeltFrame *f, float *total_dist)
Definition: opusenc_psy.c:366
NULL
#define NULL
Definition: coverity.c:32
OpusPsyStep::total_change
float total_change
Definition: opusenc_psy.h:40
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
generate_window_func
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
Definition: window_func.h:63
av_clipf
av_clipf
Definition: af_crystalizer.c:121
ff_celt_freq_range
const uint8_t ff_celt_freq_range[]
Definition: opustab.c:772
celt_gauge_psy_weight
static void celt_gauge_psy_weight(OpusPsyContext *s, OpusPsyStep **start, CeltFrame *f_out)
Definition: opusenc_psy.c:313
index
int index
Definition: gxfenc.c:89
c
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
Definition: undefined.txt:32
weight
static int weight(int i, int blen, int offset)
Definition: diracdec.c:1562
ff_opus_psy_postencode_update
void ff_opus_psy_postencode_update(OpusPsyContext *s, CeltFrame *f)
Definition: opusenc_psy.c:479
options
const OptionDef options[]
CELT_OVERLAP
#define CELT_OVERLAP
Definition: opus_celt.h:39
OpusPsyStep::bands
float * bands[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]
Definition: opusenc_psy.h:42
opustab.h
OpusPsyStep::index
int index
Definition: opusenc_psy.h:34
CELT_MAX_BANDS
#define CELT_MAX_BANDS
Definition: opus_celt.h:42
f
f
Definition: af_crystalizer.c:121
ff_opus_rc_enc_init
void ff_opus_rc_enc_init(OpusRangeCoder *rc)
Definition: opus_rc.c:402
opus_pvq.h
opusenc_psy.h
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
OpusPsyStep::tone
float tone[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]
Definition: opusenc_psy.h:37
OpusRangeCoder
Definition: opus_rc.h:39
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2646
ff_celt_tf_select
const int8_t ff_celt_tf_select[4][2][2][2]
Definition: opustab.c:782
offset
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
Definition: writing_filters.txt:86
Y
#define Y
Definition: boxblur.h:37
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:294
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
pvq_band_cost
static float pvq_band_cost(CeltPVQ *pvq, CeltFrame *f, OpusRangeCoder *rc, int band, float *bits, float lambda)
Definition: opusenc_psy.c:30
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
ff_bufqueue_peek
static AVFrame * ff_bufqueue_peek(struct FFBufQueue *queue, unsigned index)
Get a buffer from the queue without altering it.
Definition: bufferqueue.h:87
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
FFBufQueue
Structure holding the queue.
Definition: bufferqueue.h:49
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:401
opus_celt.h
OPUS_MODE_HYBRID
@ OPUS_MODE_HYBRID
Definition: opus.h:43
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_opus_psy_signal_eof
void ff_opus_psy_signal_eof(OpusPsyContext *s)
Definition: opusenc_psy.c:589
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
OpusPsyStep::energy
float energy[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]
Definition: opusenc_psy.h:36
len
int len
Definition: vorbis_enc_data.h:426
opus_rc_tell_frac
static av_always_inline uint32_t opus_rc_tell_frac(const OpusRangeCoder *rc)
Definition: opus_rc.h:65
ff_celt_bitalloc
void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode)
Definition: opus_celt.c:137
ret
ret
Definition: filter_design.txt:187
window_func.h
AVCodecContext
main external API structure.
Definition: avcodec.h:441
WFUNC_SINE
@ WFUNC_SINE
Definition: window_func.h:31
OpusPacketInfo::framesize
int framesize
Definition: opusenc.h:51
bessel_filter
static float bessel_filter(FFBesselFilter *s, float x)
Definition: opusenc_utils.h:79
cm
#define cm
Definition: dvbsubdec.c:39
OpusBandExcitation
Definition: opusenc_psy.h:46
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:338
search_for_change_points
static void search_for_change_points(OpusPsyContext *s, float tgt_change, int offset_s, int offset_e, int resolution, int level)
Definition: opusenc_psy.c:167
ff_opus_psy_init
av_cold int ff_opus_psy_init(OpusPsyContext *s, AVCodecContext *avctx, struct FFBufQueue *bufqueue, OpusEncOptions *options)
Definition: opusenc_psy.c:515
OpusEncOptions
Definition: opusenc.h:43
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
step_collect_psy_metrics
static void step_collect_psy_metrics(OpusPsyContext *s, int index)
Definition: opusenc_psy.c:81
CELT_BLOCK_NB
@ CELT_BLOCK_NB
Definition: opus_celt.h:67
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
celt_search_for_intensity
static void celt_search_for_intensity(OpusPsyContext *s, CeltFrame *f)
Definition: opusenc_psy.c:401
flush_silent_frames
static int flush_silent_frames(OpusPsyContext *s)
Definition: opusenc_psy.c:187
OPUS_RC_CHECKPOINT_BITS
#define OPUS_RC_CHECKPOINT_BITS(rc)
Definition: opus_rc.h:119
OPUS_RC_CHECKPOINT_ROLLBACK
#define OPUS_RC_CHECKPOINT_ROLLBACK(rc)
Definition: opus_rc.h:122
int
int
Definition: ffmpeg_filter.c:368
OPUS_SAMPLES_TO_BLOCK_SIZE
#define OPUS_SAMPLES_TO_BLOCK_SIZE(x)
Definition: opusenc.h:41
CeltFrame
Definition: opus_celt.h:97