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.

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