blob: d6e587efc66d253b529a0e08e08a38ac109ed603 [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:
425 * - 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 *
433 * Output:
434 * - inst : Updated user information
435 * - len : Number of samples that were outputted from NetEq
436 *
437 * Return value : 0 - Ok
438 * -1 - Error
439 */
440
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000441int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, int16_t *pw16_outData, int16_t *pw16_len,
442 int16_t BGNonly);
niklase@google.com470e71d2011-07-07 08:21:25 +0000443
444/****************************************************************************
445 * WebRtcNetEQ_Normal(...)
446 *
447 * This function has the possibility to modify data that is played out in Normal
448 * mode, for example adjust the gain of the signal. The length of the signal
449 * can not be changed.
450 *
451 * Input:
452 * - inst : NetEQ DSP instance
453 * - scratchPtr : Pointer to scratch vector
454 * - decoded : Pointer to vector of new data from decoder
455 * - len : Number of input samples
456 *
457 * Output:
458 * - inst : Updated user information
459 * - pw16_len : Pointer to varibale where the number of samples
460 * produced will be written
461 *
462 * Return value : >=0 - Number of samples written to outData
463 * -1 - Error
464 */
465
466int WebRtcNetEQ_Normal(DSPInst_t *inst,
467#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000468 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000469#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000470 int16_t *pw16_decoded, int16_t len,
471 int16_t *pw16_outData, int16_t *pw16_len);
niklase@google.com470e71d2011-07-07 08:21:25 +0000472
473/****************************************************************************
474 * WebRtcNetEQ_Expand(...)
475 *
476 * This function produces one "chunk" of expansion data (PLC audio). The
477 * lenght of the produced audio depends on the speech history.
478 *
479 * Input:
480 * - inst : NetEQ DSP instance
481 * - scratchPtr : Pointer to scratch vector
482 * - BGNonly : If non-zero, Expand will only produce background
483 * noise.
484 * - pw16_len : Desired number of samples (only for BGN mode).
485 *
486 * Output:
487 * - inst : Updated user information
488 * - outdata : Pointer to a memory space where the output data
489 * should be stored
490 * - pw16_len : Number of samples that were outputted from NetEq
491 *
492 * Return value : 0 - Ok
493 * <0 - Error
494 */
495
496int WebRtcNetEQ_Expand(DSPInst_t *inst,
497#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000498 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000499#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000500 int16_t *pw16_outData, int16_t *pw16_len,
501 int16_t BGNonly);
niklase@google.com470e71d2011-07-07 08:21:25 +0000502
503/****************************************************************************
504 * WebRtcNetEQ_GenerateBGN(...)
505 *
506 * This function generates and writes len samples of background noise to the
507 * output vector. The Expand function will be called repeteadly until the
508 * correct number of samples is produced.
509 *
510 * Input:
511 * - inst : NetEQ DSP instance
512 * - scratchPtr : Pointer to scratch vector
513 * - len : Desired length of produced BGN.
514 *
515 *
516 * Output:
517 * - pw16_outData : Pointer to a memory space where the output data
518 * should be stored
519 *
520 * Return value : >=0 - Number of noise samples produced and written
521 * to output
522 * -1 - Error
523 */
524
525int WebRtcNetEQ_GenerateBGN(DSPInst_t *inst,
526#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000527 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000528#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000529 int16_t *pw16_outData, int16_t len);
niklase@google.com470e71d2011-07-07 08:21:25 +0000530
531/****************************************************************************
532 * WebRtcNetEQ_PreEmptiveExpand(...)
533 *
534 * This function tries to extend the audio data by repeating one or several
535 * pitch periods. The operation is only carried out if the correlation is
536 * strong or if the signal energy is very low. The algorithm is the
537 * reciprocal of the Accelerate algorithm.
538 *
539 * Input:
540 * - inst : NetEQ DSP instance
541 * - scratchPtr : Pointer to scratch vector.
542 * - decoded : Pointer to newly decoded speech.
543 * - len : Length of decoded speech.
544 * - oldDataLen : Length of the part of decoded that has already been played out.
545 * - BGNonly : If non-zero, Pre-emptive Expand will only copy
546 * the first DEFAULT_TIME_ADJUST seconds of the
547 * input and append to the end. No signal matching is
548 * done.
549 *
550 * Output:
551 * - inst : Updated instance
552 * - outData : Pointer to a memory space where the output data
553 * should be stored. The vector must be at least
554 * min(len + 120*fs/8000, NETEQ_MAX_OUTPUT_SIZE)
555 * elements long.
556 * - pw16_len : Number of samples written to outData.
557 *
558 * Return value : 0 - Ok
559 * <0 - Error
560 */
561
562int WebRtcNetEQ_PreEmptiveExpand(DSPInst_t *inst,
563#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000564 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000565#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000566 const int16_t *pw16_decoded, int len, int oldDataLen,
567 int16_t *pw16_outData, int16_t *pw16_len,
568 int16_t BGNonly);
niklase@google.com470e71d2011-07-07 08:21:25 +0000569
570/****************************************************************************
571 * WebRtcNetEQ_Accelerate(...)
572 *
573 * This function tries to shorten the audio data by removing one or several
574 * pitch periods. The operation is only carried out if the correlation is
575 * strong or if the signal energy is very low.
576 *
577 * Input:
578 * - inst : NetEQ DSP instance
579 * - scratchPtr : Pointer to scratch vector.
580 * - decoded : Pointer to newly decoded speech.
581 * - len : Length of decoded speech.
582 * - BGNonly : If non-zero, Accelerate will only remove the last
583 * DEFAULT_TIME_ADJUST seconds of the intput.
584 * No signal matching is done.
585 *
586 *
587 * Output:
588 * - inst : Updated instance
589 * - outData : Pointer to a memory space where the output data
590 * should be stored
591 * - pw16_len : Number of samples written to outData.
592 *
593 * Return value : 0 - Ok
594 * <0 - Error
595 */
596
597int WebRtcNetEQ_Accelerate(DSPInst_t *inst,
598#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000599 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000600#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000601 const int16_t *pw16_decoded, int len,
602 int16_t *pw16_outData, int16_t *pw16_len,
603 int16_t BGNonly);
niklase@google.com470e71d2011-07-07 08:21:25 +0000604
605/****************************************************************************
606 * WebRtcNetEQ_Merge(...)
607 *
608 * This function is used to merge new data from the decoder to the exisiting
609 * stream in the synchronization buffer. The merge operation is typically
610 * done after a packet loss, where the end of the expanded data does not
611 * fit naturally with the new decoded data.
612 *
613 * Input:
614 * - inst : NetEQ DSP instance
615 * - scratchPtr : Pointer to scratch vector.
616 * - decoded : Pointer to new decoded speech.
617 * - len : Number of samples in pw16_decoded.
618 *
619 *
620 * Output:
621 * - inst : Updated user information
622 * - outData : Pointer to a memory space where the output data
623 * should be stored
624 * - pw16_len : Number of samples written to pw16_outData
625 *
626 * Return value : 0 - Ok
627 * <0 - Error
628 */
629
630int WebRtcNetEQ_Merge(DSPInst_t *inst,
631#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000632 int16_t *pw16_scratchPtr,
niklase@google.com470e71d2011-07-07 08:21:25 +0000633#endif
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000634 int16_t *pw16_decoded, int len, int16_t *pw16_outData,
635 int16_t *pw16_len);
niklase@google.com470e71d2011-07-07 08:21:25 +0000636
637/****************************************************************************
638 * WebRtcNetEQ_Cng(...)
639 *
640 * This function produces CNG according to RFC 3389
641 *
642 * Input:
643 * - inst : NetEQ DSP instance
644 * - len : Number of samples to produce
645 *
646 * Output:
647 * - pw16_outData : Output CNG
648 *
649 * Return value : 0 - Ok
650 * <0 - Error
651 */
652
653#ifdef NETEQ_CNG_CODEC
654/* Must compile NetEQ with CNG support to enable this function */
655
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000656int WebRtcNetEQ_Cng(DSPInst_t *inst, int16_t *pw16_outData, int len);
niklase@google.com470e71d2011-07-07 08:21:25 +0000657
658#endif /* NETEQ_CNG_CODEC */
659
660/****************************************************************************
661 * WebRtcNetEQ_BGNUpdate(...)
662 *
663 * This function updates the background noise parameter estimates.
664 *
665 * Input:
666 * - inst : NetEQ instance, where the speech history is stored.
667 * - scratchPtr : Pointer to scratch vector.
668 *
669 * Output:
670 * - inst : Updated information about the BGN characteristics.
671 *
672 * Return value : No return value
673 */
674
675void WebRtcNetEQ_BGNUpdate(
676#ifdef SCRATCH
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000677 DSPInst_t *inst, int16_t *pw16_scratchPtr
niklase@google.com470e71d2011-07-07 08:21:25 +0000678#else
679 DSPInst_t *inst
680#endif
681 );
682
683#ifdef NETEQ_VAD
684/* Functions used by post-decode VAD */
685
686/****************************************************************************
687 * WebRtcNetEQ_InitVAD(...)
688 *
689 * Initializes post-decode VAD instance.
690 *
691 * Input:
692 * - VADinst : PostDecodeVAD instance
693 * - fs : Initial sample rate
694 *
695 * Output:
696 * - VADinst : Updated instance
697 *
698 * Return value : 0 - Ok
699 * -1 - Error
700 */
701
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000702int WebRtcNetEQ_InitVAD(PostDecodeVAD_t *VADInst, uint16_t fs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000703
704/****************************************************************************
705 * WebRtcNetEQ_SetVADModeInternal(...)
706 *
707 * Set the VAD mode in the VAD struct, and communicate it to the VAD instance
708 * if it exists.
709 *
710 * Input:
711 * - VADinst : PostDecodeVAD instance
712 * - mode : Mode number passed on to the VAD function
713 *
714 * Output:
715 * - VADinst : Updated instance
716 *
717 * Return value : 0 - Ok
718 * -1 - Error
719 */
720
bjornv@webrtc.orgf4b77fd2012-01-25 12:40:00 +0000721int WebRtcNetEQ_SetVADModeInternal(PostDecodeVAD_t *VADInst, int mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000722
723#endif /* NETEQ_VAD */
724
725/****************************************************************************
726 * WebRtcNetEQ_FlushSpeechBuffer(...)
727 *
728 * Flush the speech buffer.
729 *
730 * Input:
731 * - inst : NetEq DSP instance
732 *
733 * Output:
734 * - inst : Updated instance
735 *
736 * Return value : 0 - ok
737 * : non-zero - error
738 */
739
740int WebRtcNetEQ_FlushSpeechBuffer(DSPInst_t *inst);
741
742#ifndef WEBRTC_NETEQ_40BITACC_TEST
743
744#include "signal_processing_library.h"
745/* Map to regular SPL functions */
746#define WebRtcNetEQ_CrossCorr WebRtcSpl_CrossCorrelation
747#define WebRtcNetEQ_DotW16W16 WebRtcSpl_DotProductWithScale
748
749#else /* WEBRTC_NETEQ_40BITACC_TEST defined */
750/* Run NetEQ with simulated 40-bit accumulator to run bit-exact to a DSP
751 implementation where the main (splib and NetEQ) functions have been
752 40-bit optimized. */
753
754/* Map to special 40-bit optimized functions, defined below */
755#define WebRtcNetEQ_CrossCorr WebRtcNetEQ_40BitAccCrossCorr
756#define WebRtcNetEQ_DotW16W16 WebRtcNetEQ_40BitAccDotW16W16
757
758/****************************************************************************
759 * WebRtcNetEQ_40BitAccCrossCorr(...)
760 *
761 * Calculates the Cross correlation between two sequences seq1 and seq2. Seq1
762 * is fixed and seq2 slides as the pointer is increased with step
763 *
764 * Input:
765 * - seq1 : First sequence (fixed throughout the correlation)
766 * - seq2 : Second sequence (slided step_seq2 for each
767 * new correlation)
768 * - dimSeq : Number of samples to use in the cross correlation.
769 * Should be no larger than 1024 to avoid overflow.
770 * - dimCrossCorr : Number of CrossCorrelations to calculate (start
771 * position for seq2 is updated for each new one)
772 * - rShift : Number of right shifts to use
773 * - step_seq2 : How many (positive or negative) steps the seq2
774 * pointer should be updated for each new cross
775 * correlation value
776 *
777 * Output:
778 * - crossCorr : The cross correlation in Q-rShift
779 */
780
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000781void WebRtcNetEQ_40BitAccCrossCorr(int32_t *crossCorr, int16_t *seq1,
782 int16_t *seq2, int16_t dimSeq,
783 int16_t dimCrossCorr, int16_t rShift,
784 int16_t step_seq2);
niklase@google.com470e71d2011-07-07 08:21:25 +0000785
786/****************************************************************************
787 * WebRtcNetEQ_40BitAccDotW16W16(...)
788 *
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000789 * Calculates the dot product between two vectors (int16_t)
niklase@google.com470e71d2011-07-07 08:21:25 +0000790 *
791 * Input:
792 * - vector1 : Vector 1
793 * - vector2 : Vector 2
794 * - len : Number of samples in vector
795 * Should be no larger than 1024 to avoid overflow.
796 * - scaling : The number of right shifts (after multiplication)
797 * required to avoid overflow in the dot product.
798 * Return value : The dot product
799 */
800
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000801int32_t WebRtcNetEQ_40BitAccDotW16W16(int16_t *vector1, int16_t *vector2,
802 int len, int scaling);
niklase@google.com470e71d2011-07-07 08:21:25 +0000803
804#endif /* WEBRTC_NETEQ_40BITACC_TEST */
805
806#endif /* DSP_H */