dca_lbr.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 2016 foo86
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_DCA_LBR_H
  21. #define AVCODEC_DCA_LBR_H
  22. #include "libavutil/common.h"
  23. #include "libavutil/float_dsp.h"
  24. #include "libavutil/mem.h"
  25. #include "avcodec.h"
  26. #include "internal.h"
  27. #include "get_bits.h"
  28. #include "dca.h"
  29. #include "dca_exss.h"
  30. #include "dcadsp.h"
  31. #include "fft.h"
  32. #define DCA_LBR_CHANNELS 6
  33. #define DCA_LBR_CHANNELS_TOTAL 32
  34. #define DCA_LBR_SUBBANDS 32
  35. #define DCA_LBR_TONES 512
  36. #define DCA_LBR_TIME_SAMPLES 128
  37. #define DCA_LBR_TIME_HISTORY 8
  38. enum DCALBRHeader {
  39. DCA_LBR_HEADER_SYNC_ONLY = 1,
  40. DCA_LBR_HEADER_DECODER_INIT = 2
  41. };
  42. typedef struct DCALbrTone {
  43. uint8_t x_freq; ///< Spectral line offset
  44. uint8_t f_delt; ///< Difference between original and center frequency
  45. uint8_t ph_rot; ///< Phase rotation
  46. uint8_t pad; ///< Padding field
  47. uint8_t amp[DCA_LBR_CHANNELS]; ///< Per-channel amplitude
  48. uint8_t phs[DCA_LBR_CHANNELS]; ///< Per-channel phase
  49. } DCALbrTone;
  50. typedef struct DCALbrDecoder {
  51. AVCodecContext *avctx;
  52. GetBitContext gb;
  53. int sample_rate; ///< Sample rate of LBR audio
  54. int ch_mask; ///< LBR speaker mask
  55. int flags; ///< Flags for LBR decoder initialization
  56. int bit_rate_orig; ///< Original bit rate
  57. int bit_rate_scaled; ///< Scaled bit rate
  58. int nchannels; ///< Number of fullband channels to decode
  59. int nchannels_total; ///< Total number of fullband channels
  60. int freq_range; ///< Frequency range of LBR audio
  61. int band_limit; ///< Band limit factor
  62. int limited_rate; ///< Band limited sample rate
  63. int limited_range; ///< Band limited frequency range
  64. int res_profile; ///< Resolution profile
  65. int nsubbands; ///< Number of encoded subbands
  66. int g3_avg_only_start_sb; ///< Subband index where grid 3 scale factors end
  67. int min_mono_subband; ///< Subband index where mono encoding starts
  68. int max_mono_subband; ///< Subband index where mono encoding ends
  69. int framenum; ///< Lower 5 bits of current frame number
  70. int lbr_rand; ///< Seed for subband randomization
  71. int warned; ///< Flags for warning suppression
  72. uint8_t quant_levels[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Quantization levels
  73. uint8_t sb_indices[DCA_LBR_SUBBANDS]; ///< Subband reordering indices
  74. uint8_t sec_ch_sbms[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Right channel inversion or mid/side decoding flags
  75. uint8_t sec_ch_lrms[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Flags indicating if left/right channel are swapped
  76. uint32_t ch_pres[DCA_LBR_CHANNELS]; ///< Subband allocation flags
  77. uint8_t grid_1_scf[DCA_LBR_CHANNELS][12][8]; ///< Grid 1 scale factors
  78. uint8_t grid_2_scf[DCA_LBR_CHANNELS][3][64]; ///< Grid 2 scale factors
  79. int8_t grid_3_avg[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS - 4]; ///< Grid 3 average values
  80. int8_t grid_3_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS - 4][8]; ///< Grid 3 scale factors
  81. uint32_t grid_3_pres[DCA_LBR_CHANNELS]; ///< Grid 3 scale factors presence flags
  82. uint8_t high_res_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS][8]; ///< High-frequency resolution scale factors
  83. uint8_t part_stereo[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS / 4][5]; ///< Partial stereo coefficients
  84. uint8_t part_stereo_pres; ///< Partial stereo coefficients presence flags
  85. float lpc_coeff[2][DCA_LBR_CHANNELS][3][2][8]; ///< Predictor coefficients
  86. float sb_scf[DCA_LBR_SUBBANDS]; ///< Subband randomization scale factors
  87. float *time_samples[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS]; ///< Time samples
  88. float *ts_buffer; ///< Time sample buffer base
  89. unsigned int ts_size; ///< Time sample buffer size
  90. DECLARE_ALIGNED(32, float, history)[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS * 4]; ///< IMDCT history
  91. DECLARE_ALIGNED(32, float, window)[DCA_LBR_SUBBANDS * 4]; ///< Long window for IMDCT
  92. DECLARE_ALIGNED(32, float, lfe_data)[64]; ///< Decimated LFE samples
  93. DECLARE_ALIGNED(32, float, lfe_history)[5][2]; ///< LFE IIR filter history
  94. float lfe_scale; ///< Scale factor of LFE samples before IIR filter
  95. uint8_t tonal_scf[6]; ///< Tonal scale factors
  96. uint16_t tonal_bounds[5][32][2]; ///< Per-group per-subframe start/end positions of tones
  97. DCALbrTone tones[DCA_LBR_TONES]; ///< Circular buffer of tones
  98. int ntones; ///< Circular buffer head position
  99. FFTContext imdct;
  100. AVFloatDSPContext *fdsp;
  101. DCADSPContext *dcadsp;
  102. } DCALbrDecoder;
  103. int ff_dca_lbr_parse(DCALbrDecoder *s, uint8_t *data, DCAExssAsset *asset);
  104. int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame);
  105. av_cold void ff_dca_lbr_flush(DCALbrDecoder *s);
  106. av_cold int ff_dca_lbr_init(DCALbrDecoder *s);
  107. av_cold void ff_dca_lbr_close(DCALbrDecoder *s);
  108. #endif