sbr.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. uint8_t env_facs_q[6][48];
  91. AAC_FLOAT env_facs[6][48];
  92. ///Noise scalefactors
  93. uint8_t noise_facs_q[3][5];
  94. AAC_FLOAT noise_facs[3][5];
  95. ///Envelope time borders
  96. uint8_t t_env[8];
  97. ///Envelope time border of the last envelope of the previous frame
  98. uint8_t t_env_num_env_old;
  99. ///Noise time borders
  100. uint8_t t_q[3];
  101. unsigned f_indexnoise;
  102. unsigned f_indexsine;
  103. /** @} */
  104. } SBRData;
  105. typedef struct SpectralBandReplication SpectralBandReplication;
  106. /**
  107. * aacsbr functions pointers
  108. */
  109. typedef struct AACSBRContext {
  110. int (*sbr_lf_gen)(AACContext *ac, SpectralBandReplication *sbr,
  111. INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2],
  112. int buf_idx);
  113. void (*sbr_hf_assemble)(INTFLOAT Y1[38][64][2],
  114. const INTFLOAT X_high[64][40][2],
  115. SpectralBandReplication *sbr, SBRData *ch_data,
  116. const int e_a[2]);
  117. int (*sbr_x_gen)(SpectralBandReplication *sbr, INTFLOAT X[2][38][64],
  118. const INTFLOAT Y0[38][64][2], const INTFLOAT Y1[38][64][2],
  119. const INTFLOAT X_low[32][40][2], int ch);
  120. void (*sbr_hf_inverse_filter)(SBRDSPContext *dsp,
  121. INTFLOAT (*alpha0)[2], INTFLOAT (*alpha1)[2],
  122. const INTFLOAT X_low[32][40][2], int k0);
  123. } AACSBRContext;
  124. /**
  125. * Spectral Band Replication
  126. */
  127. struct SpectralBandReplication {
  128. int sample_rate;
  129. int start;
  130. int ready_for_dequant;
  131. int id_aac;
  132. int reset;
  133. SpectrumParameters spectrum_params;
  134. int bs_amp_res_header;
  135. /**
  136. * @name Variables associated with bs_header_extra_2
  137. * @{
  138. */
  139. unsigned bs_limiter_bands;
  140. unsigned bs_limiter_gains;
  141. unsigned bs_interpol_freq;
  142. unsigned bs_smoothing_mode;
  143. /** @} */
  144. unsigned bs_coupling;
  145. AAC_SIGNE k[5]; ///< k0, k1, k2
  146. ///kx', and kx respectively, kx is the first QMF subband where SBR is used.
  147. ///kx' is its value from the previous frame
  148. AAC_SIGNE kx[2];
  149. ///M' and M respectively, M is the number of QMF subbands that use SBR.
  150. AAC_SIGNE m[2];
  151. unsigned kx_and_m_pushed;
  152. ///The number of frequency bands in f_master
  153. AAC_SIGNE n_master;
  154. SBRData data[2];
  155. PSContext ps;
  156. ///N_Low and N_High respectively, the number of frequency bands for low and high resolution
  157. AAC_SIGNE n[2];
  158. ///Number of noise floor bands
  159. AAC_SIGNE n_q;
  160. ///Number of limiter bands
  161. AAC_SIGNE n_lim;
  162. ///The master QMF frequency grouping
  163. uint16_t f_master[49];
  164. ///Frequency borders for low resolution SBR
  165. uint16_t f_tablelow[25];
  166. ///Frequency borders for high resolution SBR
  167. uint16_t f_tablehigh[49];
  168. ///Frequency borders for noise floors
  169. uint16_t f_tablenoise[6];
  170. ///Frequency borders for the limiter
  171. uint16_t f_tablelim[30];
  172. AAC_SIGNE num_patches;
  173. uint8_t patch_num_subbands[6];
  174. uint8_t patch_start_subband[6];
  175. ///QMF low frequency input to the HF generator
  176. DECLARE_ALIGNED(16, INTFLOAT, X_low)[32][40][2];
  177. ///QMF output of the HF generator
  178. DECLARE_ALIGNED(16, INTFLOAT, X_high)[64][40][2];
  179. ///QMF values of the reconstructed signal
  180. DECLARE_ALIGNED(16, INTFLOAT, X)[2][2][38][64];
  181. ///Zeroth coefficient used to filter the subband signals
  182. DECLARE_ALIGNED(16, INTFLOAT, alpha0)[64][2];
  183. ///First coefficient used to filter the subband signals
  184. DECLARE_ALIGNED(16, INTFLOAT, alpha1)[64][2];
  185. ///Dequantized envelope scalefactors, remapped
  186. AAC_FLOAT e_origmapped[7][48];
  187. ///Dequantized noise scalefactors, remapped
  188. AAC_FLOAT q_mapped[7][48];
  189. ///Sinusoidal presence, remapped
  190. uint8_t s_mapped[7][48];
  191. ///Estimated envelope
  192. AAC_FLOAT e_curr[7][48];
  193. ///Amplitude adjusted noise scalefactors
  194. AAC_FLOAT q_m[7][48];
  195. ///Sinusoidal levels
  196. AAC_FLOAT s_m[7][48];
  197. AAC_FLOAT gain[7][48];
  198. DECLARE_ALIGNED(32, INTFLOAT, qmf_filter_scratch)[5][64];
  199. FFTContext mdct_ana;
  200. FFTContext mdct;
  201. SBRDSPContext dsp;
  202. AACSBRContext c;
  203. };
  204. #endif /* AVCODEC_SBR_H */