blob: 9371938d5f604540fd5a0d695445db873c21de8c [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
bjornv@webrtc.org152c34c2012-01-23 12:36:46 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11/*
12 * This file contains some DSP initialization functions,
13 * constant table definitions and other parameters.
14 * Also contains definitions of all DSP-side data structures.
15 */
16
17
18#ifndef DSP_H
19#define DSP_H
20
21#include "typedefs.h"
22
23#include "webrtc_cng.h"
24
25#include "codec_db_defines.h"
26#include "neteq_defines.h"
27#include "neteq_statistics.h"
28
29#ifdef NETEQ_ATEVENT_DECODE
30#include "dtmf_tonegen.h"
31#endif
32
33
34
35/*****************************/
36/* Pre-processor definitions */
37/*****************************/
38
39/* FSMULT is the sample rate divided by 8000 */
40#if defined(NETEQ_48KHZ_WIDEBAND)
41 #define FSMULT 6
42#elif defined(NETEQ_32KHZ_WIDEBAND)
43 #define FSMULT 4
44#elif defined(NETEQ_WIDEBAND)
45 #define FSMULT 2
46#else
47 #define FSMULT 1
48#endif
49
50/* Size of the speech buffer (or synchronization buffer). */
51/* 60 ms decoding + 10 ms syncbuff + 0.625ms lookahead */
52#define SPEECH_BUF_SIZE (565 * FSMULT)
53
54/* Misc definitions */
55#define BGN_LPC_ORDER (4 + FSMULT) /* 5, 6, 8, or 10 */
56#define UNVOICED_LPC_ORDER 6
57#define RANDVEC_NO_OF_SAMPLES 256
58
59/* Number of milliseconds to remove/add during accelerate/pre-emptive expand
60 under BGNonly operation */
61#define DEFAULT_TIME_ADJUST 8
62
63/* Number of RecOut calls without CNG/SID before re-enabling post-decode VAD */
64#define POST_DECODE_VAD_AUTO_ENABLE 3000
65
66/* 8kHz windowing in Q15 (over 5 samples) */
67#define NETEQ_OVERLAP_WINMUTE_8KHZ_START 27307
68#define NETEQ_OVERLAP_WINMUTE_8KHZ_INC -5461
69#define NETEQ_OVERLAP_WINUNMUTE_8KHZ_START 5461
70#define NETEQ_OVERLAP_WINUNMUTE_8KHZ_INC 5461
71/* 16kHz windowing in Q15 (over 10 samples) */
72#define NETEQ_OVERLAP_WINMUTE_16KHZ_START 29789
73#define NETEQ_OVERLAP_WINMUTE_16KHZ_INC -2979
74#define NETEQ_OVERLAP_WINUNMUTE_16KHZ_START 2979
75#define NETEQ_OVERLAP_WINUNMUTE_16KHZ_INC 2979
76/* 32kHz windowing in Q15 (over 20 samples) */
77#define NETEQ_OVERLAP_WINMUTE_32KHZ_START 31208
78#define NETEQ_OVERLAP_WINMUTE_32KHZ_INC -1560
79#define NETEQ_OVERLAP_WINUNMUTE_32KHZ_START 1560
80#define NETEQ_OVERLAP_WINUNMUTE_32KHZ_INC 1560
81/* 48kHz windowing in Q15 (over 30 samples) */
82#define NETEQ_OVERLAP_WINMUTE_48KHZ_START 31711
83#define NETEQ_OVERLAP_WINMUTE_48KHZ_INC -1057
84#define NETEQ_OVERLAP_WINUNMUTE_48KHZ_START 1057
85#define NETEQ_OVERLAP_WINUNMUTE_48KHZ_INC 1057
86
87/* Fade BGN towards zero after this many Expand calls */
88#define FADE_BGN_TIME 200
89
90
91/*******************/
92/* Constant tables */
93/*******************/
94
pbos@webrtc.org0946a562013-04-09 00:28:06 +000095extern const int16_t WebRtcNetEQ_kDownsample8kHzTbl[];
96extern const int16_t WebRtcNetEQ_kDownsample16kHzTbl[];
97extern const int16_t WebRtcNetEQ_kDownsample32kHzTbl[];
98extern const int16_t WebRtcNetEQ_kDownsample48kHzTbl[];
99extern const int16_t WebRtcNetEQ_kRandnTbl[];
100extern const int16_t WebRtcNetEQ_kMixFractionFuncTbl[];
101extern const int16_t WebRtcNetEQ_k1049div[];
102extern const int16_t WebRtcNetEQ_k2097div[];
103extern const int16_t WebRtcNetEQ_k5243div[];
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
105
106
107/************/
108/* Typedefs */
109/************/
110
111enum BGNMode
112{
113 BGN_ON, /* default "normal" behavior with eternal noise */
114 BGN_FADE, /* noise fades to zero after some time */
115 BGN_OFF /* background noise is always zero */
116};
117
118#ifdef NETEQ_STEREO
119enum MasterSlaveMode
120{
121 NETEQ_MONO, /* stand-alone instance */
122 NETEQ_MASTER, /* master instance in a spatial/stereo configuration */
123 NETEQ_SLAVE /* slave instance in a spatial/stereo configuration */
124};
125
126enum MasterSlaveExtraInfo
127{
128 NO_INFO, /* no info to convey */
129 ACC_FAIL, /* signal that accelerate failed */
130 PE_EXP_FAIL, /* signal that pre-emptive expand failed */
131 DTMF_OVERDUB, /* signal that DTMF overdub is generated */
132 DTMF_ONLY /* signal that DTMF only is played */
133};
134#endif
135
136/****************************/
137/* DSP-side data structures */
138/****************************/
139
140/* Background noise (BGN) instance for storing BGN parameters
141 (sub-instance of NETEQDSP_inst) */
142typedef struct BGNInst_t_
143{
144
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000145 int32_t w32_energy;
146 int32_t w32_energyMax;
147 int32_t w32_energyUpdate;
148 int32_t w32_energyUpdateLow;
149 int16_t pw16_filterState[BGN_LPC_ORDER];
150 int16_t pw16_filter[BGN_LPC_ORDER + 1];
151 int16_t w16_mutefactor;
152 int16_t w16_scale;
153 int16_t w16_scaleShift;
154 int16_t w16_initialized;
niklase@google.com470e71d2011-07-07 08:21:25 +0000155 enum BGNMode bgnMode;
156
157} BGNInst_t;
158
159/* Expansion instance (sub-instance of NETEQDSP_inst) */
160typedef struct ExpandInst_t_
161{
162
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000163 int16_t w16_overlap; /* Constant, 5 for NB and 10 for WB */
164 int16_t w16_consecExp; /* Number of consecutive expand calls */
165 int16_t *pw16_arFilter; /* length [UNVOICED_LPC_ORDER+1] */
166 int16_t *pw16_arState; /* length [UNVOICED_LPC_ORDER] */
167 int16_t w16_arGain;
168 int16_t w16_arGainScale;
169 int16_t w16_vFraction; /* Q14 */
170 int16_t w16_currentVFraction; /* Q14 */
171 int16_t *pw16_expVecs[2];
172 int16_t w16_lags[3];
173 int16_t w16_maxLag;
174 int16_t *pw16_overlapVec; /* last samples of speech history */
175 int16_t w16_lagsDirection;
176 int16_t w16_lagsPosition;
177 int16_t w16_expandMuteFactor; /* Q14 */
178 int16_t w16_stopMuting;
179 int16_t w16_onset;
180 int16_t w16_muteSlope; /* Q20 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
182} ExpandInst_t;
183
184#ifdef NETEQ_VAD
185
186/*
187 * VAD function pointer types, replicating the typedefs in webrtc_neteq_internal.h.
188 * These function pointers match the definitions of WebRtc VAD functions WebRtcVad_Init,
189 * WebRtcVad_set_mode and WebRtcVad_Process, respectively, all found in webrtc_vad.h.
190 */
bjornv@webrtc.orgab2bb822012-01-18 14:51:02 +0000191typedef int (*VADInitFunction)(void *VAD_inst);
bjornv@webrtc.orgf4b77fd2012-01-25 12:40:00 +0000192typedef int (*VADSetmodeFunction)(void *VAD_inst, int mode);
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000193typedef int (*VADFunction)(void *VAD_inst, int fs, int16_t *frame,
bjornv@webrtc.orgb38fca12012-06-19 11:03:32 +0000194 int frameLen);
niklase@google.com470e71d2011-07-07 08:21:25 +0000195
196/* Post-decode VAD instance (sub-instance of NETEQDSP_inst) */
197typedef struct PostDecodeVAD_t_
198{
199
200 void *VADState; /* pointer to a VAD instance */
201
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000202 int16_t VADEnabled; /* 1 if enabled, 0 if disabled */
bjornv@webrtc.orgf4b77fd2012-01-25 12:40:00 +0000203 int VADMode; /* mode parameter to pass to the VAD function */
bjornv@webrtc.orgb38fca12012-06-19 11:03:32 +0000204 int VADDecision; /* 1 for active, 0 for passive */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000205 int16_t SIDintervalCounter; /* reset when decoding CNG/SID frame,
niklase@google.com470e71d2011-07-07 08:21:25 +0000206 increment for each recout call */
207
208 /* Function pointers */
209 VADInitFunction initFunction; /* VAD init function */
210 VADSetmodeFunction setmodeFunction; /* VAD setmode function */
211 VADFunction VADFunction; /* VAD function */
212
213} PostDecodeVAD_t;
214
215#endif /* NETEQ_VAD */
216
217#ifdef NETEQ_STEREO
218#define MAX_MS_DECODES 10
219
220typedef struct
221{
222 /* Stand-alone, master, or slave */
223 enum MasterSlaveMode msMode;
224
225 enum MasterSlaveExtraInfo extraInfo;
226
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000227 uint16_t instruction;
228 int16_t distLag;
229 int16_t corrLag;
230 int16_t bestIndex;
niklase@google.com470e71d2011-07-07 08:21:25 +0000231
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000232 uint32_t endTimestamp;
233 uint16_t samplesLeftWithOverlap;
niklase@google.com470e71d2011-07-07 08:21:25 +0000234
235} MasterSlaveInfo;
236#endif
237
238
239/* "Main" NetEQ DSP instance */
240typedef struct DSPInst_t_
241{
242
243 /* MCU/DSP Communication layer */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000244 int16_t *pw16_readAddress;
245 int16_t *pw16_writeAddress;
niklase@google.com470e71d2011-07-07 08:21:25 +0000246 void *main_inst;
247
248 /* Output frame size in ms and samples */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000249 int16_t millisecondsPerCall;
250 int16_t timestampsPerCall;
niklase@google.com470e71d2011-07-07 08:21:25 +0000251
252 /*
253 * Example of speech buffer
254 *
255 * -----------------------------------------------------------
256 * | History T-60 to T | Future |
257 * -----------------------------------------------------------
258 * ^ ^
259 * | |
260 * curPosition endPosition
261 *
262 * History is gradually shifted out to the left when inserting
263 * new data at the end.
264 */
265
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000266 int16_t speechBuffer[SPEECH_BUF_SIZE]; /* History/future speech buffer */
niklase@google.com470e71d2011-07-07 08:21:25 +0000267 int curPosition; /* Next sample to play */
268 int endPosition; /* Position that ends future data */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000269 uint32_t endTimestamp; /* Timestamp value at end of future data */
270 uint32_t videoSyncTimestamp; /* (Estimated) timestamp of the last
niklase@google.com470e71d2011-07-07 08:21:25 +0000271 played sample (usually same as
272 endTimestamp-(endPosition-curPosition)
273 except during Expand and CNG) */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000274 uint16_t fs; /* sample rate in Hz */
275 int16_t w16_frameLen; /* decoder frame length in samples */
276 int16_t w16_mode; /* operation used during last RecOut call */
277 int16_t w16_muteFactor; /* speech mute factor in Q14 */
278 int16_t *pw16_speechHistory; /* beginning of speech history during Expand */
279 int16_t w16_speechHistoryLen; /* 256 for NB and 512 for WB */
niklase@google.com470e71d2011-07-07 08:21:25 +0000280
281 /* random noise seed parameters */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000282 int16_t w16_seedInc;
283 uint32_t uw16_seed;
niklase@google.com470e71d2011-07-07 08:21:25 +0000284
285 /* VQmon related variable */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000286 int16_t w16_concealedTS;
niklase@google.com470e71d2011-07-07 08:21:25 +0000287
288 /*****************/
289 /* Sub-instances */
290 /*****************/
291
292 /* Decoder data */
293 CodecFuncInst_t codec_ptr_inst;
294
295#ifdef NETEQ_CNG_CODEC
296 /* CNG "decoder" instance */
297 CNG_dec_inst *CNG_Codec_inst;
298#endif /* NETEQ_CNG_CODEC */
299
300#ifdef NETEQ_ATEVENT_DECODE
301 /* DTMF generator instance */
302 dtmf_tone_inst_t DTMFInst;
303#endif /* NETEQ_CNG_CODEC */
304
305#ifdef NETEQ_VAD
306 /* Post-decode VAD instance */
307 PostDecodeVAD_t VADInst;
308#endif /* NETEQ_VAD */
309
310 /* Expand instance (defined above) */
311 ExpandInst_t ExpandInst;
312
313 /* Background noise instance (defined above) */
314 BGNInst_t BGNInst;
315
316 /* Internal statistics instance */
317 DSPStats_t statInst;
318
turaj@webrtc.org92d1f072013-04-15 16:52:04 +0000319 /* Internal instance for short-term processing activity. */
320 ActivityStats activity_stats;
321
niklase@google.com470e71d2011-07-07 08:21:25 +0000322#ifdef NETEQ_STEREO
323 /* Pointer to Master/Slave info */
324 MasterSlaveInfo *msInfo;
325#endif
326
327} DSPInst_t;
328
329
330/*************************/
331/* Function declarations */
332/*************************/
333
334/****************************************************************************
335 * WebRtcNetEQ_DSPInit(...)
336 *
337 * Initializes DSP side of NetEQ.
338 *
339 * Input:
340 * - inst : NetEq DSP instance
341 * - fs : Initial sample rate (may change when decoding data)
342 *
343 * Output:
344 * - inst : Updated instance
345 *
346 * Return value : 0 - ok
347 * : non-zero - error
348 */
349
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000350int WebRtcNetEQ_DSPInit(DSPInst_t *inst, uint16_t fs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000351
352/****************************************************************************
353 * WebRtcNetEQ_AddressInit(...)
354 *
355 * Initializes the shared-memory communication on the DSP side.
356 *
357 * Input:
358 * - inst : NetEQ DSP instance
359 * - data2McuAddress : Pointer to memory where DSP writes / MCU reads
360 * - data2DspAddress : Pointer to memory where MCU writes / DSP reads
361 * - mainInst : NetEQ main instance
362 *
363 * Output:
364 * - inst : Updated instance
365 *
366 * Return value : 0 - ok
367 */
368
369int WebRtcNetEQ_AddressInit(DSPInst_t *inst, const void *data2McuAddress,
370 const void *data2DspAddress, const void *mainInst);
371
372/****************************************************************************
373 * WebRtcNetEQ_ClearInCallStats(...)
374 *
375 * Reset in-call statistics variables on DSP side.
376 *
377 * Input:
378 * - inst : NetEQ DSP instance
379 *
380 * Output:
381 * - inst : Updated instance
382 *
383 * Return value : 0 - ok
384 */
385
386int WebRtcNetEQ_ClearInCallStats(DSPInst_t *inst);
387
388/****************************************************************************
389 * WebRtcNetEQ_ClearPostCallStats(...)
390 *
391 * Reset post-call statistics variables on DSP side.
392 *
393 * Input:
394 * - inst : NetEQ DSP instance
395 *
396 * Output:
397 * - inst : Updated instance
398 *
399 * Return value : 0 - ok
400 */
401
402int WebRtcNetEQ_ClearPostCallStats(DSPInst_t *inst);
403
404/****************************************************************************
turaj@webrtc.org92d1f072013-04-15 16:52:04 +0000405 * WebRtcNetEQ_ClearActivityStats(...)
406 *
407 * Reset processing activity statistics.
408 *
409 * Input:
410 * - inst : NetEQ DSP instance
411 *
412 * Output:
413 * - inst : Updated instance
414 *
415 */
416
417void WebRtcNetEQ_ClearActivityStats(DSPInst_t *inst);
418
419/****************************************************************************
niklase@google.com470e71d2011-07-07 08:21:25 +0000420 * WebRtcNetEQ_RecOutInternal(...)
421 *
422 * This function asks NetEQ for more speech/audio data.
423 *
424 * Input:
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000425 * - inst : NetEQ instance, i.e. the user that requests more
426 * speech/audio data.
427 * - outdata : Pointer to a memory space where the output data
428 * should be stored.
429 * - BGNonly : If non-zero, RecOut will only produce background
430 * noise. It will still draw packets from the packet
431 * buffer, but they will never be decoded.
432 * - av_sync : 1 if NetEQ is in AV-sync, 0 otherwise.
niklase@google.com470e71d2011-07-07 08:21:25 +0000433 *
434 * Output:
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000435 * - inst : Updated user information
436 * - len : Number of samples that were outputted from NetEq
niklase@google.com470e71d2011-07-07 08:21:25 +0000437 *
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000438 * Return value : 0 - Ok
439 * -1 - Error
niklase@google.com470e71d2011-07-07 08:21:25 +0000440 */
441
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000442int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, int16_t *pw16_outData,
443 int16_t *pw16_len, int16_t BGNonly, int av_sync);
niklase@google.com470e71d2011-07-07 08:21:25 +0000444
445/****************************************************************************
446 * WebRtcNetEQ_Normal(...)
447 *
448 * This function has the possibility to modify data that is played out in Normal
449 * mode, for example adjust the gain of the signal. The length of the signal
450 * can not be changed.
451 *
452 * Input:
453 * - inst : NetEQ DSP instance
454 * - scratchPtr : Pointer to scratch vector
455 * - decoded : Pointer to vector of new data from decoder
456 * - len : Number of input samples
457 *
458 * Output:
459 * - inst : Updated user information
460 * - pw16_len : Pointer to varibale where the number of samples
461 * produced will be written
462 *
463 * Return value : >=0 - Number of samples written to outData
464 * -1 - Error
465 */
466
467int WebRtcNetEQ_Normal(DSPInst_t *inst,
468#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000469 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000470#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000471 int16_t *pw16_decoded, int16_t len,
472 int16_t *pw16_outData, int16_t *pw16_len);
niklase@google.com470e71d2011-07-07 08:21:25 +0000473
474/****************************************************************************
475 * WebRtcNetEQ_Expand(...)
476 *
477 * This function produces one "chunk" of expansion data (PLC audio). The
478 * lenght of the produced audio depends on the speech history.
479 *
480 * Input:
481 * - inst : NetEQ DSP instance
482 * - scratchPtr : Pointer to scratch vector
483 * - BGNonly : If non-zero, Expand will only produce background
484 * noise.
485 * - pw16_len : Desired number of samples (only for BGN mode).
486 *
487 * Output:
488 * - inst : Updated user information
489 * - outdata : Pointer to a memory space where the output data
490 * should be stored
491 * - pw16_len : Number of samples that were outputted from NetEq
492 *
493 * Return value : 0 - Ok
494 * <0 - Error
495 */
496
497int WebRtcNetEQ_Expand(DSPInst_t *inst,
498#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000499 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000500#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000501 int16_t *pw16_outData, int16_t *pw16_len,
502 int16_t BGNonly);
niklase@google.com470e71d2011-07-07 08:21:25 +0000503
504/****************************************************************************
505 * WebRtcNetEQ_GenerateBGN(...)
506 *
507 * This function generates and writes len samples of background noise to the
508 * output vector. The Expand function will be called repeteadly until the
509 * correct number of samples is produced.
510 *
511 * Input:
512 * - inst : NetEQ DSP instance
513 * - scratchPtr : Pointer to scratch vector
514 * - len : Desired length of produced BGN.
515 *
516 *
517 * Output:
518 * - pw16_outData : Pointer to a memory space where the output data
519 * should be stored
520 *
521 * Return value : >=0 - Number of noise samples produced and written
522 * to output
523 * -1 - Error
524 */
525
526int WebRtcNetEQ_GenerateBGN(DSPInst_t *inst,
527#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000528 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000529#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000530 int16_t *pw16_outData, int16_t len);
niklase@google.com470e71d2011-07-07 08:21:25 +0000531
532/****************************************************************************
533 * WebRtcNetEQ_PreEmptiveExpand(...)
534 *
535 * This function tries to extend the audio data by repeating one or several
536 * pitch periods. The operation is only carried out if the correlation is
537 * strong or if the signal energy is very low. The algorithm is the
538 * reciprocal of the Accelerate algorithm.
539 *
540 * Input:
541 * - inst : NetEQ DSP instance
542 * - scratchPtr : Pointer to scratch vector.
543 * - decoded : Pointer to newly decoded speech.
544 * - len : Length of decoded speech.
545 * - oldDataLen : Length of the part of decoded that has already been played out.
546 * - BGNonly : If non-zero, Pre-emptive Expand will only copy
547 * the first DEFAULT_TIME_ADJUST seconds of the
548 * input and append to the end. No signal matching is
549 * done.
550 *
551 * Output:
552 * - inst : Updated instance
553 * - outData : Pointer to a memory space where the output data
554 * should be stored. The vector must be at least
555 * min(len + 120*fs/8000, NETEQ_MAX_OUTPUT_SIZE)
556 * elements long.
557 * - pw16_len : Number of samples written to outData.
558 *
559 * Return value : 0 - Ok
560 * <0 - Error
561 */
562
563int WebRtcNetEQ_PreEmptiveExpand(DSPInst_t *inst,
564#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000565 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000566#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000567 const int16_t *pw16_decoded, int len, int oldDataLen,
568 int16_t *pw16_outData, int16_t *pw16_len,
569 int16_t BGNonly);
niklase@google.com470e71d2011-07-07 08:21:25 +0000570
571/****************************************************************************
572 * WebRtcNetEQ_Accelerate(...)
573 *
574 * This function tries to shorten the audio data by removing one or several
575 * pitch periods. The operation is only carried out if the correlation is
576 * strong or if the signal energy is very low.
577 *
578 * Input:
579 * - inst : NetEQ DSP instance
580 * - scratchPtr : Pointer to scratch vector.
581 * - decoded : Pointer to newly decoded speech.
582 * - len : Length of decoded speech.
583 * - BGNonly : If non-zero, Accelerate will only remove the last
584 * DEFAULT_TIME_ADJUST seconds of the intput.
585 * No signal matching is done.
586 *
587 *
588 * Output:
589 * - inst : Updated instance
590 * - outData : Pointer to a memory space where the output data
591 * should be stored
592 * - pw16_len : Number of samples written to outData.
593 *
594 * Return value : 0 - Ok
595 * <0 - Error
596 */
597
598int WebRtcNetEQ_Accelerate(DSPInst_t *inst,
599#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000600 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000601#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000602 const int16_t *pw16_decoded, int len,
603 int16_t *pw16_outData, int16_t *pw16_len,
604 int16_t BGNonly);
niklase@google.com470e71d2011-07-07 08:21:25 +0000605
606/****************************************************************************
607 * WebRtcNetEQ_Merge(...)
608 *
609 * This function is used to merge new data from the decoder to the exisiting
610 * stream in the synchronization buffer. The merge operation is typically
611 * done after a packet loss, where the end of the expanded data does not
612 * fit naturally with the new decoded data.
613 *
614 * Input:
615 * - inst : NetEQ DSP instance
616 * - scratchPtr : Pointer to scratch vector.
617 * - decoded : Pointer to new decoded speech.
618 * - len : Number of samples in pw16_decoded.
619 *
620 *
621 * Output:
622 * - inst : Updated user information
623 * - outData : Pointer to a memory space where the output data
624 * should be stored
625 * - pw16_len : Number of samples written to pw16_outData
626 *
627 * Return value : 0 - Ok
628 * <0 - Error
629 */
630
631int WebRtcNetEQ_Merge(DSPInst_t *inst,
632#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000633 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000634#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000635 int16_t *pw16_decoded, int len, int16_t *pw16_outData,
636 int16_t *pw16_len);
niklase@google.com470e71d2011-07-07 08:21:25 +0000637
638/****************************************************************************
639 * WebRtcNetEQ_Cng(...)
640 *
641 * This function produces CNG according to RFC 3389
642 *
643 * Input:
644 * - inst : NetEQ DSP instance
645 * - len : Number of samples to produce
646 *
647 * Output:
648 * - pw16_outData : Output CNG
649 *
650 * Return value : 0 - Ok
651 * <0 - Error
652 */
653
654#ifdef NETEQ_CNG_CODEC
655/* Must compile NetEQ with CNG support to enable this function */
656
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000657int WebRtcNetEQ_Cng(DSPInst_t *inst, int16_t *pw16_outData, int len);
niklase@google.com470e71d2011-07-07 08:21:25 +0000658
659#endif /* NETEQ_CNG_CODEC */
660
661/****************************************************************************
662 * WebRtcNetEQ_BGNUpdate(...)
663 *
664 * This function updates the background noise parameter estimates.
665 *
666 * Input:
667 * - inst : NetEQ instance, where the speech history is stored.
668 * - scratchPtr : Pointer to scratch vector.
669 *
670 * Output:
671 * - inst : Updated information about the BGN characteristics.
672 *
673 * Return value : No return value
674 */
675
676void WebRtcNetEQ_BGNUpdate(
677#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000678 DSPInst_t *inst, int16_t *pw16_scratchPtr
niklase@google.com470e71d2011-07-07 08:21:25 +0000679#else
680 DSPInst_t *inst
681#endif
682 );
683
684#ifdef NETEQ_VAD
685/* Functions used by post-decode VAD */
686
687/****************************************************************************
688 * WebRtcNetEQ_InitVAD(...)
689 *
690 * Initializes post-decode VAD instance.
691 *
692 * Input:
693 * - VADinst : PostDecodeVAD instance
694 * - fs : Initial sample rate
695 *
696 * Output:
697 * - VADinst : Updated instance
698 *
699 * Return value : 0 - Ok
700 * -1 - Error
701 */
702
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000703int WebRtcNetEQ_InitVAD(PostDecodeVAD_t *VADInst, uint16_t fs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000704
705/****************************************************************************
706 * WebRtcNetEQ_SetVADModeInternal(...)
707 *
708 * Set the VAD mode in the VAD struct, and communicate it to the VAD instance
709 * if it exists.
710 *
711 * Input:
712 * - VADinst : PostDecodeVAD instance
713 * - mode : Mode number passed on to the VAD function
714 *
715 * Output:
716 * - VADinst : Updated instance
717 *
718 * Return value : 0 - Ok
719 * -1 - Error
720 */
721
bjornv@webrtc.orgf4b77fd2012-01-25 12:40:00 +0000722int WebRtcNetEQ_SetVADModeInternal(PostDecodeVAD_t *VADInst, int mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000723
724#endif /* NETEQ_VAD */
725
726/****************************************************************************
727 * WebRtcNetEQ_FlushSpeechBuffer(...)
728 *
729 * Flush the speech buffer.
730 *
731 * Input:
732 * - inst : NetEq DSP instance
733 *
734 * Output:
735 * - inst : Updated instance
736 *
737 * Return value : 0 - ok
738 * : non-zero - error
739 */
740
741int WebRtcNetEQ_FlushSpeechBuffer(DSPInst_t *inst);
742
743#ifndef WEBRTC_NETEQ_40BITACC_TEST
744
745#include "signal_processing_library.h"
746/* Map to regular SPL functions */
747#define WebRtcNetEQ_CrossCorr WebRtcSpl_CrossCorrelation
748#define WebRtcNetEQ_DotW16W16 WebRtcSpl_DotProductWithScale
749
750#else /* WEBRTC_NETEQ_40BITACC_TEST defined */
751/* Run NetEQ with simulated 40-bit accumulator to run bit-exact to a DSP
752 implementation where the main (splib and NetEQ) functions have been
753 40-bit optimized. */
754
755/* Map to special 40-bit optimized functions, defined below */
756#define WebRtcNetEQ_CrossCorr WebRtcNetEQ_40BitAccCrossCorr
757#define WebRtcNetEQ_DotW16W16 WebRtcNetEQ_40BitAccDotW16W16
758
759/****************************************************************************
760 * WebRtcNetEQ_40BitAccCrossCorr(...)
761 *
762 * Calculates the Cross correlation between two sequences seq1 and seq2. Seq1
763 * is fixed and seq2 slides as the pointer is increased with step
764 *
765 * Input:
766 * - seq1 : First sequence (fixed throughout the correlation)
767 * - seq2 : Second sequence (slided step_seq2 for each
768 * new correlation)
769 * - dimSeq : Number of samples to use in the cross correlation.
770 * Should be no larger than 1024 to avoid overflow.
771 * - dimCrossCorr : Number of CrossCorrelations to calculate (start
772 * position for seq2 is updated for each new one)
773 * - rShift : Number of right shifts to use
774 * - step_seq2 : How many (positive or negative) steps the seq2
775 * pointer should be updated for each new cross
776 * correlation value
777 *
778 * Output:
779 * - crossCorr : The cross correlation in Q-rShift
780 */
781
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000782void WebRtcNetEQ_40BitAccCrossCorr(int32_t *crossCorr, int16_t *seq1,
783 int16_t *seq2, int16_t dimSeq,
784 int16_t dimCrossCorr, int16_t rShift,
785 int16_t step_seq2);
niklase@google.com470e71d2011-07-07 08:21:25 +0000786
787/****************************************************************************
788 * WebRtcNetEQ_40BitAccDotW16W16(...)
789 *
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000790 * Calculates the dot product between two vectors (int16_t)
niklase@google.com470e71d2011-07-07 08:21:25 +0000791 *
792 * Input:
793 * - vector1 : Vector 1
794 * - vector2 : Vector 2
795 * - len : Number of samples in vector
796 * Should be no larger than 1024 to avoid overflow.
797 * - scaling : The number of right shifts (after multiplication)
798 * required to avoid overflow in the dot product.
799 * Return value : The dot product
800 */
801
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000802int32_t WebRtcNetEQ_40BitAccDotW16W16(int16_t *vector1, int16_t *vector2,
803 int len, int scaling);
niklase@google.com470e71d2011-07-07 08:21:25 +0000804
805#endif /* WEBRTC_NETEQ_40BITACC_TEST */
806
807#endif /* DSP_H */