blob: b4d2bd8999290766b78a7a5d2506a2a93743755d (
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
/*
* structs.h
*
* This header file contains all the structs used in the ISAC codec
*
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_SOURCE_STRUCTS_H_
#define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_SOURCE_STRUCTS_H_
#include "common_audio/signal_processing/include/signal_processing_library.h"
#include "modules/audio_coding/codecs/isac/fix/source/settings.h"
#include "typedefs.h"
/* Bitstream struct for decoder */
typedef struct Bitstreamstruct_dec {
uint16_t *stream; /* Pointer to bytestream to decode */
uint32_t W_upper; /* Upper boundary of interval W */
uint32_t streamval;
uint16_t stream_index; /* Index to the current position in bytestream */
int16_t full; /* 0 - first byte in memory filled, second empty*/
/* 1 - both bytes are empty (we just filled the previous memory */
int stream_size; /* The size of stream. */
} Bitstr_dec;
/* Bitstream struct for encoder */
typedef struct Bitstreamstruct_enc {
uint16_t stream[STREAM_MAXW16_60MS]; /* Vector for adding encoded bytestream */
uint32_t W_upper; /* Upper boundary of interval W */
uint32_t streamval;
uint16_t stream_index; /* Index to the current position in bytestream */
int16_t full; /* 0 - first byte in memory filled, second empty*/
/* 1 - both bytes are empty (we just filled the previous memory */
} Bitstr_enc;
typedef struct {
int16_t DataBufferLoQ0[WINLEN];
int16_t DataBufferHiQ0[WINLEN];
int32_t CorrBufLoQQ[ORDERLO+1];
int32_t CorrBufHiQQ[ORDERHI+1];
int16_t CorrBufLoQdom[ORDERLO+1];
int16_t CorrBufHiQdom[ORDERHI+1];
int32_t PreStateLoGQ15[ORDERLO+1];
int32_t PreStateHiGQ15[ORDERHI+1];
uint32_t OldEnergy;
} MaskFiltstr_enc;
typedef struct {
int16_t PostStateLoGQ0[ORDERLO+1];
int16_t PostStateHiGQ0[ORDERHI+1];
uint32_t OldEnergy;
} MaskFiltstr_dec;
typedef struct {
//state vectors for each of the two analysis filters
int32_t INSTAT1_fix[2*(QORDER-1)];
int32_t INSTAT2_fix[2*(QORDER-1)];
int16_t INLABUF1_fix[QLOOKAHEAD];
int16_t INLABUF2_fix[QLOOKAHEAD];
/* High pass filter */
int32_t HPstates_fix[HPORDER];
} PreFiltBankstr;
typedef struct {
//state vectors for each of the two analysis filters
int32_t STATE_0_LOWER_fix[2*POSTQORDER];
int32_t STATE_0_UPPER_fix[2*POSTQORDER];
/* High pass filter */
int32_t HPstates1_fix[HPORDER];
int32_t HPstates2_fix[HPORDER];
} PostFiltBankstr;
typedef struct {
/* data buffer for pitch filter */
int16_t ubufQQ[PITCH_BUFFSIZE];
/* low pass state vector */
int16_t ystateQQ[PITCH_DAMPORDER];
/* old lag and gain */
int16_t oldlagQ7;
int16_t oldgainQ12;
} PitchFiltstr;
typedef struct {
//for inital estimator
int16_t dec_buffer16[PITCH_CORR_LEN2+PITCH_CORR_STEP2+PITCH_MAX_LAG/2-PITCH_FRAME_LEN/2+2];
int32_t decimator_state32[2*ALLPASSSECTIONS+1];
int16_t inbuf[QLOOKAHEAD];
PitchFiltstr PFstr_wght;
PitchFiltstr PFstr;
} PitchAnalysisStruct;
typedef struct {
/* Parameters used in PLC to avoid re-computation */
/* --- residual signals --- */
int16_t prevPitchInvIn[FRAMESAMPLES/2];
int16_t prevPitchInvOut[PITCH_MAX_LAG + 10]; // [FRAMESAMPLES/2]; save 90
int32_t prevHP[PITCH_MAX_LAG + 10]; // [FRAMESAMPLES/2]; save 90
int16_t decayCoeffPriodic; /* how much to supress a sample */
int16_t decayCoeffNoise;
int16_t used; /* if PLC is used */
int16_t *lastPitchLP; // [FRAMESAMPLES/2]; saved 240;
/* --- LPC side info --- */
int16_t lofilt_coefQ15[ ORDERLO ];
int16_t hifilt_coefQ15[ ORDERHI ];
int32_t gain_lo_hiQ17[2];
/* --- LTP side info --- */
int16_t AvgPitchGain_Q12;
int16_t lastPitchGain_Q12;
int16_t lastPitchLag_Q7;
/* --- Add-overlap in recovery packet --- */
int16_t overlapLP[ RECOVERY_OVERLAP ]; // [FRAMESAMPLES/2]; saved 160
int16_t pitchCycles;
int16_t A;
int16_t B;
int16_t pitchIndex;
int16_t stretchLag;
int16_t *prevPitchLP; // [ FRAMESAMPLES/2 ]; saved 240
int16_t seed;
int16_t std;
} PLCstr;
/* Have instance of struct together with other iSAC structs */
typedef struct {
int16_t prevFrameSizeMs; /* Previous frame size (in ms) */
uint16_t prevRtpNumber; /* Previous RTP timestamp from received packet */
/* (in samples relative beginning) */
uint32_t prevSendTime; /* Send time for previous packet, from RTP header */
uint32_t prevArrivalTime; /* Arrival time for previous packet (in ms using timeGetTime()) */
uint16_t prevRtpRate; /* rate of previous packet, derived from RTP timestamps (in bits/s) */
uint32_t lastUpdate; /* Time since the last update of the Bottle Neck estimate (in samples) */
uint32_t lastReduction; /* Time sinse the last reduction (in samples) */
int32_t countUpdates; /* How many times the estimate was update in the beginning */
/* The estimated bottle neck rate from there to here (in bits/s) */
uint32_t recBw;
uint32_t recBwInv;
uint32_t recBwAvg;
uint32_t recBwAvgQ;
uint32_t minBwInv;
uint32_t maxBwInv;
/* The estimated mean absolute jitter value, as seen on this side (in ms) */
int32_t recJitter;
int32_t recJitterShortTerm;
int32_t recJitterShortTermAbs;
int32_t recMaxDelay;
int32_t recMaxDelayAvgQ;
int16_t recHeaderRate; /* (assumed) bitrate for headers (bps) */
uint32_t sendBwAvg; /* The estimated bottle neck rate from here to there (in bits/s) */
int32_t sendMaxDelayAvg; /* The estimated mean absolute jitter value, as seen on the other siee (in ms) */
int16_t countRecPkts; /* number of packets received since last update */
int16_t highSpeedRec; /* flag for marking that a high speed network has been detected downstream */
/* number of consecutive pkts sent during which the bwe estimate has
remained at a value greater than the downstream threshold for determining highspeed network */
int16_t countHighSpeedRec;
/* flag indicating bwe should not adjust down immediately for very late pckts */
int16_t inWaitPeriod;
/* variable holding the time of the start of a window of time when
bwe should not adjust down immediately for very late pckts */
uint32_t startWaitPeriod;
/* number of consecutive pkts sent during which the bwe estimate has
remained at a value greater than the upstream threshold for determining highspeed network */
int16_t countHighSpeedSent;
/* flag indicated the desired number of packets over threshold rate have been sent and
bwe will assume the connection is over broadband network */
int16_t highSpeedSend;
} BwEstimatorstr;
typedef struct {
/* boolean, flags if previous packet exceeded B.N. */
int16_t PrevExceed;
/* ms */
int16_t ExceedAgo;
/* packets left to send in current burst */
int16_t BurstCounter;
/* packets */
int16_t InitCounter;
/* ms remaining in buffer when next packet will be sent */
int16_t StillBuffered;
} RateModel;
/* The following strutc is used to store data from encoding, to make it
fast and easy to construct a new bitstream with a different Bandwidth
estimate. All values (except framelength and minBytes) is double size to
handle 60 ms of data.
*/
typedef struct {
/* Used to keep track of if it is first or second part of 60 msec packet */
int startIdx;
/* Frame length in samples */
int16_t framelength;
/* Pitch Gain */
int16_t pitchGain_index[2];
/* Pitch Lag */
int32_t meanGain[2];
int16_t pitchIndex[PITCH_SUBFRAMES*2];
/* LPC */
int32_t LPCcoeffs_g[12*2]; /* KLT_ORDER_GAIN = 12 */
int16_t LPCindex_s[108*2]; /* KLT_ORDER_SHAPE = 108 */
int16_t LPCindex_g[12*2]; /* KLT_ORDER_GAIN = 12 */
/* Encode Spec */
int16_t fre[FRAMESAMPLES];
int16_t fim[FRAMESAMPLES];
int16_t AvgPitchGain[2];
/* Used in adaptive mode only */
int minBytes;
} ISAC_SaveEncData_t;
typedef struct {
Bitstr_enc bitstr_obj;
MaskFiltstr_enc maskfiltstr_obj;
PreFiltBankstr prefiltbankstr_obj;
PitchFiltstr pitchfiltstr_obj;
PitchAnalysisStruct pitchanalysisstr_obj;
RateModel rate_data_obj;
int16_t buffer_index;
int16_t current_framesamples;
int16_t data_buffer_fix[FRAMESAMPLES]; // the size was MAX_FRAMESAMPLES
int16_t frame_nb;
int16_t BottleNeck;
int16_t MaxDelay;
int16_t new_framelength;
int16_t s2nr;
uint16_t MaxBits;
int16_t bitstr_seed;
#ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
PostFiltBankstr interpolatorstr_obj;
#endif
ISAC_SaveEncData_t *SaveEnc_ptr;
int16_t payloadLimitBytes30; /* Maximum allowed number of bits for a 30 msec packet */
int16_t payloadLimitBytes60; /* Maximum allowed number of bits for a 30 msec packet */
int16_t maxPayloadBytes; /* Maximum allowed number of bits for both 30 and 60 msec packet */
int16_t maxRateInBytes; /* Maximum allowed rate in bytes per 30 msec packet */
int16_t enforceFrameSize; /* If set iSAC will never change packet size */
} ISACFIX_EncInst_t;
typedef struct {
Bitstr_dec bitstr_obj;
MaskFiltstr_dec maskfiltstr_obj;
PostFiltBankstr postfiltbankstr_obj;
PitchFiltstr pitchfiltstr_obj;
PLCstr plcstr_obj; /* TS; for packet loss concealment */
#ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
PreFiltBankstr decimatorstr_obj;
#endif
} ISACFIX_DecInst_t;
typedef struct {
ISACFIX_EncInst_t ISACenc_obj;
ISACFIX_DecInst_t ISACdec_obj;
BwEstimatorstr bwestimator_obj;
int16_t CodingMode; /* 0 = adaptive; 1 = instantaneous */
int16_t errorcode;
int16_t initflag; /* 0 = nothing initiated; 1 = encoder or decoder */
/* not initiated; 2 = all initiated */
} ISACFIX_SubStruct;
typedef struct {
int32_t lpcGains[12]; /* 6 lower-band & 6 upper-band we may need to double it for 60*/
/* */
uint32_t W_upper; /* Upper boundary of interval W */
uint32_t streamval;
uint16_t stream_index; /* Index to the current position in bytestream */
int16_t full; /* 0 - first byte in memory filled, second empty*/
/* 1 - both bytes are empty (we just filled the previous memory */
uint16_t beforeLastWord;
uint16_t lastWord;
} transcode_obj;
//Bitstr_enc myBitStr;
#endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_SOURCE_STRUCTS_H_ */
|