opusenc_psy.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #ifndef AVCODEC_OPUSENC_PSY_H
  22. #define AVCODEC_OPUSENC_PSY_H
  23. #include "opusenc.h"
  24. #include "opusenc_utils.h"
  25. #include "libavfilter/window_func.h"
  26. /* Each step is 2.5ms */
  27. typedef struct OpusPsyStep {
  28. int index; /* Current index */
  29. int silence;
  30. float energy[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]; /* Masking effects included */
  31. float tone[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]; /* Tonality */
  32. float stereo[CELT_MAX_BANDS]; /* IS/MS compatibility */
  33. float change_amp[OPUS_MAX_CHANNELS][CELT_MAX_BANDS]; /* Jump over last frame */
  34. float total_change; /* Total change */
  35. float *bands[OPUS_MAX_CHANNELS][CELT_MAX_BANDS];
  36. float coeffs[OPUS_MAX_CHANNELS][OPUS_BLOCK_SIZE(CELT_BLOCK_960)];
  37. } OpusPsyStep;
  38. typedef struct OpusBandExcitation {
  39. float excitation;
  40. float excitation_dist;
  41. float excitation_init;
  42. } OpusBandExcitation;
  43. typedef struct PsyChain {
  44. int start;
  45. int end;
  46. } PsyChain;
  47. typedef struct OpusPsyContext {
  48. AVCodecContext *avctx;
  49. AVFloatDSPContext *dsp;
  50. struct FFBufQueue *bufqueue;
  51. OpusEncOptions *options;
  52. PsyChain cs[128];
  53. int cs_num;
  54. OpusBandExcitation ex[OPUS_MAX_CHANNELS][CELT_MAX_BANDS];
  55. FFBesselFilter bfilter_lo[OPUS_MAX_CHANNELS][CELT_MAX_BANDS];
  56. FFBesselFilter bfilter_hi[OPUS_MAX_CHANNELS][CELT_MAX_BANDS];
  57. OpusPsyStep *steps[FF_BUFQUEUE_SIZE + 1];
  58. int max_steps;
  59. float *window[CELT_BLOCK_NB];
  60. MDCT15Context *mdct[CELT_BLOCK_NB];
  61. int bsize_analysis;
  62. DECLARE_ALIGNED(32, float, scratch)[2048];
  63. /* Stats */
  64. float rc_waste;
  65. float avg_is_band;
  66. int64_t dual_stereo_used;
  67. int64_t total_packets_out;
  68. /* State */
  69. FFBesselFilter lambda_lp;
  70. OpusPacketInfo p;
  71. int redo_analysis;
  72. int buffered_steps;
  73. int steps_to_process;
  74. int eof;
  75. float lambda;
  76. int *inflection_points;
  77. int inflection_points_count;
  78. } OpusPsyContext;
  79. int ff_opus_psy_process (OpusPsyContext *s, OpusPacketInfo *p);
  80. void ff_opus_psy_celt_frame_init (OpusPsyContext *s, CeltFrame *f, int index);
  81. int ff_opus_psy_celt_frame_process(OpusPsyContext *s, CeltFrame *f, int index);
  82. void ff_opus_psy_postencode_update (OpusPsyContext *s, CeltFrame *f, OpusRangeCoder *rc);
  83. int ff_opus_psy_init(OpusPsyContext *s, AVCodecContext *avctx,
  84. struct FFBufQueue *bufqueue, OpusEncOptions *options);
  85. void ff_opus_psy_signal_eof(OpusPsyContext *s);
  86. int ff_opus_psy_end(OpusPsyContext *s);
  87. #endif /* AVCODEC_OPUSENC_PSY_H */