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.

190 lines
6.3KB

  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. #include "sbrdsp.h"
  33. /**
  34. * Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header.
  35. */
  36. typedef struct {
  37. uint8_t bs_start_freq;
  38. uint8_t bs_stop_freq;
  39. uint8_t bs_xover_band;
  40. /**
  41. * @name Variables associated with bs_header_extra_1
  42. * @{
  43. */
  44. uint8_t bs_freq_scale;
  45. uint8_t bs_alter_scale;
  46. uint8_t bs_noise_bands;
  47. /** @} */
  48. } SpectrumParameters;
  49. #define SBR_SYNTHESIS_BUF_SIZE ((1280-128)*2)
  50. /**
  51. * Spectral Band Replication per channel data
  52. */
  53. typedef struct {
  54. /**
  55. * @name Main bitstream data variables
  56. * @{
  57. */
  58. unsigned bs_frame_class;
  59. unsigned bs_add_harmonic_flag;
  60. unsigned bs_num_env;
  61. uint8_t bs_freq_res[7];
  62. unsigned bs_num_noise;
  63. uint8_t bs_df_env[5];
  64. uint8_t bs_df_noise[2];
  65. uint8_t bs_invf_mode[2][5];
  66. uint8_t bs_add_harmonic[48];
  67. unsigned bs_amp_res;
  68. /** @} */
  69. /**
  70. * @name State variables
  71. * @{
  72. */
  73. DECLARE_ALIGNED(32, float, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE];
  74. DECLARE_ALIGNED(32, float, analysis_filterbank_samples) [1312];
  75. int synthesis_filterbank_samples_offset;
  76. ///l_APrev and l_A
  77. int e_a[2];
  78. ///Chirp factors
  79. float bw_array[5];
  80. ///QMF values of the original signal
  81. float W[2][32][32][2];
  82. ///QMF output of the HF adjustor
  83. int Ypos;
  84. DECLARE_ALIGNED(16, float, Y)[2][38][64][2];
  85. DECLARE_ALIGNED(16, float, g_temp)[42][48];
  86. float q_temp[42][48];
  87. uint8_t s_indexmapped[8][48];
  88. ///Envelope scalefactors
  89. float env_facs[6][48];
  90. ///Noise scalefactors
  91. float noise_facs[3][5];
  92. ///Envelope time borders
  93. uint8_t t_env[8];
  94. ///Envelope time border of the last envelope of the previous frame
  95. uint8_t t_env_num_env_old;
  96. ///Noise time borders
  97. uint8_t t_q[3];
  98. unsigned f_indexnoise;
  99. unsigned f_indexsine;
  100. /** @} */
  101. } SBRData;
  102. /**
  103. * Spectral Band Replication
  104. */
  105. typedef struct {
  106. int sample_rate;
  107. int start;
  108. int reset;
  109. SpectrumParameters spectrum_params;
  110. int bs_amp_res_header;
  111. /**
  112. * @name Variables associated with bs_header_extra_2
  113. * @{
  114. */
  115. unsigned bs_limiter_bands;
  116. unsigned bs_limiter_gains;
  117. unsigned bs_interpol_freq;
  118. unsigned bs_smoothing_mode;
  119. /** @} */
  120. unsigned bs_coupling;
  121. unsigned k[5]; ///< k0, k1, k2
  122. ///kx', and kx respectively, kx is the first QMF subband where SBR is used.
  123. ///kx' is its value from the previous frame
  124. unsigned kx[2];
  125. ///M' and M respectively, M is the number of QMF subbands that use SBR.
  126. unsigned m[2];
  127. unsigned kx_and_m_pushed;
  128. ///The number of frequency bands in f_master
  129. unsigned n_master;
  130. SBRData data[2];
  131. PSContext ps;
  132. ///N_Low and N_High respectively, the number of frequency bands for low and high resolution
  133. unsigned n[2];
  134. ///Number of noise floor bands
  135. unsigned n_q;
  136. ///Number of limiter bands
  137. unsigned n_lim;
  138. ///The master QMF frequency grouping
  139. uint16_t f_master[49];
  140. ///Frequency borders for low resolution SBR
  141. uint16_t f_tablelow[25];
  142. ///Frequency borders for high resolution SBR
  143. uint16_t f_tablehigh[49];
  144. ///Frequency borders for noise floors
  145. uint16_t f_tablenoise[6];
  146. ///Frequency borders for the limiter
  147. uint16_t f_tablelim[29];
  148. unsigned num_patches;
  149. uint8_t patch_num_subbands[6];
  150. uint8_t patch_start_subband[6];
  151. ///QMF low frequency input to the HF generator
  152. DECLARE_ALIGNED(16, float, X_low)[32][40][2];
  153. ///QMF output of the HF generator
  154. DECLARE_ALIGNED(16, float, X_high)[64][40][2];
  155. ///QMF values of the reconstructed signal
  156. DECLARE_ALIGNED(16, float, X)[2][2][38][64];
  157. ///Zeroth coefficient used to filter the subband signals
  158. DECLARE_ALIGNED(16, float, alpha0)[64][2];
  159. ///First coefficient used to filter the subband signals
  160. DECLARE_ALIGNED(16, float, alpha1)[64][2];
  161. ///Dequantized envelope scalefactors, remapped
  162. float e_origmapped[7][48];
  163. ///Dequantized noise scalefactors, remapped
  164. float q_mapped[7][48];
  165. ///Sinusoidal presence, remapped
  166. uint8_t s_mapped[7][48];
  167. ///Estimated envelope
  168. float e_curr[7][48];
  169. ///Amplitude adjusted noise scalefactors
  170. float q_m[7][48];
  171. ///Sinusoidal levels
  172. float s_m[7][48];
  173. float gain[7][48];
  174. DECLARE_ALIGNED(32, float, qmf_filter_scratch)[5][64];
  175. FFTContext mdct_ana;
  176. FFTContext mdct;
  177. SBRDSPContext dsp;
  178. } SpectralBandReplication;
  179. #endif /* AVCODEC_SBR_H */