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.

186 lines
6.2KB

  1. /*
  2. * Spectral Band Replication definitions and structures
  3. * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
  4. * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * Spectral Band Replication definitions and structures
  25. * @author Robert Swain ( rob opendot cl )
  26. */
  27. #ifndef AVCODEC_SBR_H
  28. #define AVCODEC_SBR_H
  29. #include <stdint.h>
  30. #include "fft.h"
  31. #include "aacps.h"
  32. /**
  33. * Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header.
  34. */
  35. typedef struct {
  36. uint8_t bs_start_freq;
  37. uint8_t bs_stop_freq;
  38. uint8_t bs_xover_band;
  39. /**
  40. * @defgroup bs_header_extra_1 Variables associated with bs_header_extra_1
  41. * @{
  42. */
  43. uint8_t bs_freq_scale;
  44. uint8_t bs_alter_scale;
  45. uint8_t bs_noise_bands;
  46. /** @} */
  47. } SpectrumParameters;
  48. #define SBR_SYNTHESIS_BUF_SIZE ((1280-128)*2)
  49. /**
  50. * Spectral Band Replication per channel data
  51. */
  52. typedef struct {
  53. /**
  54. * @defgroup bitstream Main bitstream data variables
  55. * @{
  56. */
  57. unsigned bs_frame_class;
  58. unsigned bs_add_harmonic_flag;
  59. unsigned bs_num_env;
  60. uint8_t bs_freq_res[7];
  61. unsigned bs_num_noise;
  62. uint8_t bs_df_env[5];
  63. uint8_t bs_df_noise[2];
  64. uint8_t bs_invf_mode[2][5];
  65. uint8_t bs_add_harmonic[48];
  66. unsigned bs_amp_res;
  67. /** @} */
  68. /**
  69. * @defgroup state State variables
  70. * @{
  71. */
  72. DECLARE_ALIGNED(16, float, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE];
  73. DECLARE_ALIGNED(16, float, analysis_filterbank_samples) [1312];
  74. int synthesis_filterbank_samples_offset;
  75. ///l_APrev and l_A
  76. int e_a[2];
  77. ///Chirp factors
  78. float bw_array[5];
  79. ///QMF values of the original signal
  80. float W[2][32][32][2];
  81. ///QMF output of the HF adjustor
  82. float Y[2][38][64][2];
  83. float g_temp[42][48];
  84. float q_temp[42][48];
  85. uint8_t s_indexmapped[8][48];
  86. ///Envelope scalefactors
  87. float env_facs[6][48];
  88. ///Noise scalefactors
  89. float noise_facs[3][5];
  90. ///Envelope time borders
  91. uint8_t t_env[8];
  92. ///Envelope time border of the last envelope of the previous frame
  93. uint8_t t_env_num_env_old;
  94. ///Noise time borders
  95. uint8_t t_q[3];
  96. unsigned f_indexnoise;
  97. unsigned f_indexsine;
  98. /** @} */
  99. } SBRData;
  100. /**
  101. * Spectral Band Replication
  102. */
  103. typedef struct {
  104. int sample_rate;
  105. int start;
  106. int reset;
  107. SpectrumParameters spectrum_params;
  108. int bs_amp_res_header;
  109. /**
  110. * @defgroup bs_header_extra_2 variables associated with bs_header_extra_2
  111. * @{
  112. */
  113. unsigned bs_limiter_bands;
  114. unsigned bs_limiter_gains;
  115. unsigned bs_interpol_freq;
  116. unsigned bs_smoothing_mode;
  117. /** @} */
  118. unsigned bs_coupling;
  119. unsigned k[5]; ///< k0, k1, k2
  120. ///kx', and kx respectively, kx is the first QMF subband where SBR is used.
  121. ///kx' is its value from the previous frame
  122. unsigned kx[2];
  123. ///M' and M respectively, M is the number of QMF subbands that use SBR.
  124. unsigned m[2];
  125. ///The number of frequency bands in f_master
  126. unsigned n_master;
  127. SBRData data[2];
  128. PSContext ps;
  129. ///N_Low and N_High respectively, the number of frequency bands for low and high resolution
  130. unsigned n[2];
  131. ///Number of noise floor bands
  132. unsigned n_q;
  133. ///Number of limiter bands
  134. unsigned n_lim;
  135. ///The master QMF frequency grouping
  136. uint16_t f_master[49];
  137. ///Frequency borders for low resolution SBR
  138. uint16_t f_tablelow[25];
  139. ///Frequency borders for high resolution SBR
  140. uint16_t f_tablehigh[49];
  141. ///Frequency borders for noise floors
  142. uint16_t f_tablenoise[6];
  143. ///Frequency borders for the limiter
  144. uint16_t f_tablelim[29];
  145. unsigned num_patches;
  146. uint8_t patch_num_subbands[6];
  147. uint8_t patch_start_subband[6];
  148. ///QMF low frequency input to the HF generator
  149. float X_low[32][40][2];
  150. ///QMF output of the HF generator
  151. float X_high[64][40][2];
  152. ///QMF values of the reconstructed signal
  153. DECLARE_ALIGNED(16, float, X)[2][2][38][64];
  154. ///Zeroth coefficient used to filter the subband signals
  155. float alpha0[64][2];
  156. ///First coefficient used to filter the subband signals
  157. float alpha1[64][2];
  158. ///Dequantized envelope scalefactors, remapped
  159. float e_origmapped[7][48];
  160. ///Dequantized noise scalefactors, remapped
  161. float q_mapped[7][48];
  162. ///Sinusoidal presence, remapped
  163. uint8_t s_mapped[7][48];
  164. ///Estimated envelope
  165. float e_curr[7][48];
  166. ///Amplitude adjusted noise scalefactors
  167. float q_m[7][48];
  168. ///Sinusoidal levels
  169. float s_m[7][48];
  170. float gain[7][48];
  171. DECLARE_ALIGNED(16, float, qmf_filter_scratch)[5][64];
  172. FFTContext mdct_ana;
  173. FFTContext mdct;
  174. } SpectralBandReplication;
  175. #endif /* AVCODEC_SBR_H */