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.

215 lines
7.4KB

  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. AAC_SIGNE bs_num_env;
  62. uint8_t bs_freq_res[7];
  63. AAC_SIGNE 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, INTFLOAT, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE];
  75. DECLARE_ALIGNED(32, INTFLOAT, 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. INTFLOAT bw_array[5];
  81. ///QMF values of the original signal
  82. INTFLOAT W[2][32][32][2];
  83. ///QMF output of the HF adjustor
  84. int Ypos;
  85. DECLARE_ALIGNED(16, INTFLOAT, Y)[2][38][64][2];
  86. DECLARE_ALIGNED(16, AAC_FLOAT, g_temp)[42][48];
  87. AAC_FLOAT q_temp[42][48];
  88. uint8_t s_indexmapped[8][48];
  89. ///Envelope scalefactors
  90. AAC_FLOAT env_facs[6][48];
  91. ///Noise scalefactors
  92. AAC_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. INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2],
  110. int buf_idx);
  111. void (*sbr_hf_assemble)(INTFLOAT Y1[38][64][2],
  112. const INTFLOAT X_high[64][40][2],
  113. SpectralBandReplication *sbr, SBRData *ch_data,
  114. const int e_a[2]);
  115. int (*sbr_x_gen)(SpectralBandReplication *sbr, INTFLOAT X[2][38][64],
  116. const INTFLOAT Y0[38][64][2], const INTFLOAT Y1[38][64][2],
  117. const INTFLOAT X_low[32][40][2], int ch);
  118. void (*sbr_hf_inverse_filter)(SBRDSPContext *dsp,
  119. INTFLOAT (*alpha0)[2], INTFLOAT (*alpha1)[2],
  120. const INTFLOAT 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 id_aac;
  129. int reset;
  130. SpectrumParameters spectrum_params;
  131. int bs_amp_res_header;
  132. /**
  133. * @name Variables associated with bs_header_extra_2
  134. * @{
  135. */
  136. unsigned bs_limiter_bands;
  137. unsigned bs_limiter_gains;
  138. unsigned bs_interpol_freq;
  139. unsigned bs_smoothing_mode;
  140. /** @} */
  141. unsigned bs_coupling;
  142. AAC_SIGNE k[5]; ///< k0, k1, k2
  143. ///kx', and kx respectively, kx is the first QMF subband where SBR is used.
  144. ///kx' is its value from the previous frame
  145. AAC_SIGNE kx[2];
  146. ///M' and M respectively, M is the number of QMF subbands that use SBR.
  147. AAC_SIGNE m[2];
  148. unsigned kx_and_m_pushed;
  149. ///The number of frequency bands in f_master
  150. AAC_SIGNE n_master;
  151. SBRData data[2];
  152. PSContext ps;
  153. ///N_Low and N_High respectively, the number of frequency bands for low and high resolution
  154. AAC_SIGNE n[2];
  155. ///Number of noise floor bands
  156. AAC_SIGNE n_q;
  157. ///Number of limiter bands
  158. AAC_SIGNE n_lim;
  159. ///The master QMF frequency grouping
  160. uint16_t f_master[49];
  161. ///Frequency borders for low resolution SBR
  162. uint16_t f_tablelow[25];
  163. ///Frequency borders for high resolution SBR
  164. uint16_t f_tablehigh[49];
  165. ///Frequency borders for noise floors
  166. uint16_t f_tablenoise[6];
  167. ///Frequency borders for the limiter
  168. uint16_t f_tablelim[30];
  169. AAC_SIGNE num_patches;
  170. uint8_t patch_num_subbands[6];
  171. uint8_t patch_start_subband[6];
  172. ///QMF low frequency input to the HF generator
  173. DECLARE_ALIGNED(16, INTFLOAT, X_low)[32][40][2];
  174. ///QMF output of the HF generator
  175. DECLARE_ALIGNED(16, INTFLOAT, X_high)[64][40][2];
  176. ///QMF values of the reconstructed signal
  177. DECLARE_ALIGNED(16, INTFLOAT, X)[2][2][38][64];
  178. ///Zeroth coefficient used to filter the subband signals
  179. DECLARE_ALIGNED(16, INTFLOAT, alpha0)[64][2];
  180. ///First coefficient used to filter the subband signals
  181. DECLARE_ALIGNED(16, INTFLOAT, alpha1)[64][2];
  182. ///Dequantized envelope scalefactors, remapped
  183. AAC_FLOAT e_origmapped[7][48];
  184. ///Dequantized noise scalefactors, remapped
  185. AAC_FLOAT q_mapped[7][48];
  186. ///Sinusoidal presence, remapped
  187. uint8_t s_mapped[7][48];
  188. ///Estimated envelope
  189. AAC_FLOAT e_curr[7][48];
  190. ///Amplitude adjusted noise scalefactors
  191. AAC_FLOAT q_m[7][48];
  192. ///Sinusoidal levels
  193. AAC_FLOAT s_m[7][48];
  194. AAC_FLOAT gain[7][48];
  195. DECLARE_ALIGNED(32, INTFLOAT, qmf_filter_scratch)[5][64];
  196. FFTContext mdct_ana;
  197. FFTContext mdct;
  198. SBRDSPContext dsp;
  199. AACSBRContext c;
  200. };
  201. #endif /* AVCODEC_SBR_H */