You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.3KB

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