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.

184 lines
6.1KB

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