summaryrefslogtreecommitdiffstats
path: root/libSBRdec/src/lpp_tran.h
blob: dcaadd946fd24477955dff933c86cc6d2201da3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/****************************************************************************

                     (C) Copyright Fraunhofer IIS (2004)
                               All Rights Reserved

    Please be advised that this software and/or program delivery is
    Confidential Information of Fraunhofer and subject to and covered by the

    Fraunhofer IIS Software Evaluation Agreement
    between Google Inc. and  Fraunhofer
    effective and in full force since March 1, 2012.

    You may use this software and/or program only under the terms and
    conditions described in the above mentioned Fraunhofer IIS Software
    Evaluation Agreement. Any other and/or further use requires a separate agreement.


   This software and/or program is protected by copyright law and international
   treaties. Any reproduction or distribution of this software and/or program,
   or any portion of it, may result in severe civil and criminal penalties, and
   will be prosecuted to the maximum extent possible under law.

 $Id$

*******************************************************************************/
/*!
  \file
  \brief  Low Power Profile Transposer, $Revision: 36841 $
*/

#ifndef _LPP_TRANS_H
#define _LPP_TRANS_H

#include "sbrdecoder.h"
#include "qmf.h"

/*
  Common
*/
#define QMF_OUT_SCALE            8

/*
  Env-Adjust
*/
#define MAX_NOISE_ENVELOPES      2
#define MAX_NOISE_COEFFS         5
#define MAX_NUM_NOISE_VALUES     (MAX_NOISE_ENVELOPES * MAX_NOISE_COEFFS)
#define MAX_NUM_LIMITERS         12

/* Set MAX_ENVELOPES to the largest value of all supported BSFORMATs
   by overriding MAX_ENVELOPES in the correct order: */
#define MAX_ENVELOPES_HEAAC      5
#define MAX_ENVELOPES            MAX_ENVELOPES_HEAAC

#define MAX_FREQ_COEFFS          48
#define MAX_FREQ_COEFFS_FS44100  35
#define MAX_FREQ_COEFFS_FS48000  32


#define MAX_NUM_ENVELOPE_VALUES  (MAX_ENVELOPES * MAX_FREQ_COEFFS)

#define MAX_GAIN_EXP             34
/* Maximum gain will be sqrt(0.5 * 2^MAX_GAIN_EXP)
   example: 34=99dB   */
#define MAX_GAIN_CONCEAL_EXP     1
/* Maximum gain will be sqrt(0.5 * 2^MAX_GAIN_CONCEAL_EXP) in concealment case (0dB) */

/*
  LPP Transposer
*/
#define LPC_ORDER                2

#define MAX_INVF_BANDS           MAX_NOISE_COEFFS

#define MAX_NUM_PATCHES          6
#define SHIFT_START_SB           1              /*!< lowest subband of source range */

typedef enum
{
  INVF_OFF = 0,
  INVF_LOW_LEVEL,
  INVF_MID_LEVEL,
  INVF_HIGH_LEVEL,
  INVF_SWITCHED /* not a real choice but used here to control behaviour */
}
INVF_MODE;


/** parameter set for one single patch */
typedef struct {
  UCHAR  sourceStartBand;   /*!< first band in lowbands where to take the samples from */
  UCHAR  sourceStopBand;    /*!< first band in lowbands which is not included in the patch anymore */
  UCHAR  guardStartBand;    /*!< first band in highbands to be filled with zeros in order to
                                         reduce interferences between patches */
  UCHAR  targetStartBand;   /*!< first band in highbands to be filled with whitened lowband signal */
  UCHAR  targetBandOffs;    /*!< difference between 'startTargetBand' and 'startSourceBand' */
  UCHAR  numBandsInPatch;   /*!< number of consecutive bands in this one patch */
} PATCH_PARAM;


/** whitening factors for different levels of whitening
    need to be initialized corresponding to crossover frequency */
typedef struct {
  FIXP_DBL  off;                       /*!< bw factor for signal OFF */
  FIXP_DBL  transitionLevel;
  FIXP_DBL  lowLevel;                  /*!< bw factor for signal LOW_LEVEL */
  FIXP_DBL  midLevel;                  /*!< bw factor for signal MID_LEVEL */
  FIXP_DBL  highLevel;                 /*!< bw factor for signal HIGH_LEVEL */
} WHITENING_FACTORS;


/*! The transposer settings are calculated on a header reset and are shared by both channels. */
typedef struct {
  UCHAR  nCols;                       /*!< number subsamples of a codec frame */
  UCHAR  noOfPatches;                 /*!< number of patches */
  UCHAR  lbStartPatching;             /*!< first band of lowbands that will be patched */
  UCHAR  lbStopPatching;              /*!< first band that won't be patched anymore*/
  UCHAR  bwBorders[MAX_NUM_NOISE_VALUES]; /*!< spectral bands with different inverse filtering levels */

  PATCH_PARAM    patchParam[MAX_NUM_PATCHES]; /*!< new parameter set for patching */
  WHITENING_FACTORS whFactors;                /*!< the pole moving factors for certain whitening levels as indicated
                                                   in the bitstream depending on the crossover frequency */
  UCHAR  overlap;                             /*!< Overlap size */
} TRANSPOSER_SETTINGS;


typedef struct
{
  TRANSPOSER_SETTINGS *pSettings;                /*!< Common settings for both channels */
  FIXP_DBL  bwVectorOld[MAX_NUM_PATCHES];        /*!< pole moving factors of past frame */
  FIXP_DBL  lpcFilterStatesReal[LPC_ORDER][(32)];     /*!< pointer array to save filter states */
  FIXP_DBL  lpcFilterStatesImag[LPC_ORDER][(32)];     /*!< pointer array to save filter states */
}
SBR_LPP_TRANS;

typedef SBR_LPP_TRANS *HANDLE_SBR_LPP_TRANS;


void lppTransposer (HANDLE_SBR_LPP_TRANS hLppTrans,
                    QMF_SCALE_FACTOR  *sbrScaleFactor,
                    FIXP_DBL **qmfBufferReal,

                    FIXP_DBL *degreeAlias,
                    FIXP_DBL **qmfBufferImag,
                    const int useLP,
                    const int timeStep,
                    const int firstSlotOffset,
                    const int lastSlotOffset,
                    const int nInvfBands,
                    INVF_MODE *sbr_invf_mode,
                    INVF_MODE *sbr_invf_mode_prev
                    );


SBR_ERROR
createLppTransposer (HANDLE_SBR_LPP_TRANS hLppTrans,
                     TRANSPOSER_SETTINGS *pSettings,
                     const int  highBandStartSb,
                     UCHAR *v_k_master,
                     const int  numMaster,
                     const int  usb,
                     const int  timeSlots,
                     const int  nCols,
                     UCHAR *noiseBandTable,
                     const int  noNoiseBands,
                     UINT   fs,
                     const int  chan,
                     const int overlap);


SBR_ERROR
resetLppTransposer (HANDLE_SBR_LPP_TRANS hLppTrans,
                    UCHAR  highBandStartSb,
                    UCHAR *v_k_master,
                    UCHAR  numMaster,
                    UCHAR *noiseBandTable,
                    UCHAR  noNoiseBands,
                    UCHAR  usb,
                    UINT   fs);



#endif /* _LPP_TRANS_H */