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.

188 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 Libav.
  7. *
  8. * Libav 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. * Libav 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 Libav; 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(16, float, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE];
  74. DECLARE_ALIGNED(16, 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. DECLARE_ALIGNED(16, float, Y)[2][38][64][2];
  84. DECLARE_ALIGNED(16, float, g_temp)[42][48];
  85. float q_temp[42][48];
  86. uint8_t s_indexmapped[8][48];
  87. ///Envelope scalefactors
  88. float env_facs[6][48];
  89. ///Noise scalefactors
  90. float noise_facs[3][5];
  91. ///Envelope time borders
  92. uint8_t t_env[8];
  93. ///Envelope time border of the last envelope of the previous frame
  94. uint8_t t_env_num_env_old;
  95. ///Noise time borders
  96. uint8_t t_q[3];
  97. unsigned f_indexnoise;
  98. unsigned f_indexsine;
  99. /** @} */
  100. } SBRData;
  101. /**
  102. * Spectral Band Replication
  103. */
  104. typedef struct {
  105. int sample_rate;
  106. int start;
  107. int reset;
  108. SpectrumParameters spectrum_params;
  109. int bs_amp_res_header;
  110. /**
  111. * @name Variables associated with bs_header_extra_2
  112. * @{
  113. */
  114. unsigned bs_limiter_bands;
  115. unsigned bs_limiter_gains;
  116. unsigned bs_interpol_freq;
  117. unsigned bs_smoothing_mode;
  118. /** @} */
  119. unsigned bs_coupling;
  120. unsigned k[5]; ///< k0, k1, k2
  121. ///kx', and kx respectively, kx is the first QMF subband where SBR is used.
  122. ///kx' is its value from the previous frame
  123. unsigned kx[2];
  124. ///M' and M respectively, M is the number of QMF subbands that use SBR.
  125. unsigned m[2];
  126. ///The number of frequency bands in f_master
  127. unsigned n_master;
  128. SBRData data[2];
  129. PSContext ps;
  130. ///N_Low and N_High respectively, the number of frequency bands for low and high resolution
  131. unsigned n[2];
  132. ///Number of noise floor bands
  133. unsigned n_q;
  134. ///Number of limiter bands
  135. unsigned n_lim;
  136. ///The master QMF frequency grouping
  137. uint16_t f_master[49];
  138. ///Frequency borders for low resolution SBR
  139. uint16_t f_tablelow[25];
  140. ///Frequency borders for high resolution SBR
  141. uint16_t f_tablehigh[49];
  142. ///Frequency borders for noise floors
  143. uint16_t f_tablenoise[6];
  144. ///Frequency borders for the limiter
  145. uint16_t f_tablelim[29];
  146. unsigned num_patches;
  147. uint8_t patch_num_subbands[6];
  148. uint8_t patch_start_subband[6];
  149. ///QMF low frequency input to the HF generator
  150. DECLARE_ALIGNED(16, float, X_low)[32][40][2];
  151. ///QMF output of the HF generator
  152. DECLARE_ALIGNED(16, float, X_high)[64][40][2];
  153. ///QMF values of the reconstructed signal
  154. DECLARE_ALIGNED(16, float, X)[2][2][38][64];
  155. ///Zeroth coefficient used to filter the subband signals
  156. DECLARE_ALIGNED(16, float, alpha0)[64][2];
  157. ///First coefficient used to filter the subband signals
  158. DECLARE_ALIGNED(16, float, alpha1)[64][2];
  159. ///Dequantized envelope scalefactors, remapped
  160. float e_origmapped[7][48];
  161. ///Dequantized noise scalefactors, remapped
  162. float q_mapped[7][48];
  163. ///Sinusoidal presence, remapped
  164. uint8_t s_mapped[7][48];
  165. ///Estimated envelope
  166. float e_curr[7][48];
  167. ///Amplitude adjusted noise scalefactors
  168. float q_m[7][48];
  169. ///Sinusoidal levels
  170. float s_m[7][48];
  171. float gain[7][48];
  172. DECLARE_ALIGNED(16, float, qmf_filter_scratch)[5][64];
  173. FFTContext mdct_ana;
  174. FFTContext mdct;
  175. SBRDSPContext dsp;
  176. } SpectralBandReplication;
  177. #endif /* AVCODEC_SBR_H */