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