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