niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
bjornv@webrtc.org | 152c34c | 2012-01-23 12:36:46 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 | |
| 95 | extern const WebRtc_Word16 WebRtcNetEQ_kDownsample8kHzTbl[]; |
| 96 | extern const WebRtc_Word16 WebRtcNetEQ_kDownsample16kHzTbl[]; |
| 97 | extern const WebRtc_Word16 WebRtcNetEQ_kDownsample32kHzTbl[]; |
| 98 | extern const WebRtc_Word16 WebRtcNetEQ_kDownsample48kHzTbl[]; |
| 99 | extern const WebRtc_Word16 WebRtcNetEQ_kRandnTbl[]; |
| 100 | extern const WebRtc_Word16 WebRtcNetEQ_kMixFractionFuncTbl[]; |
| 101 | extern const WebRtc_Word16 WebRtcNetEQ_k1049div[]; |
| 102 | extern const WebRtc_Word16 WebRtcNetEQ_k2097div[]; |
| 103 | extern const WebRtc_Word16 WebRtcNetEQ_k5243div[]; |
| 104 | |
| 105 | |
| 106 | |
| 107 | /************/ |
| 108 | /* Typedefs */ |
| 109 | /************/ |
| 110 | |
| 111 | enum 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 |
| 119 | enum 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 | |
| 126 | enum 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) */ |
| 142 | typedef struct BGNInst_t_ |
| 143 | { |
| 144 | |
| 145 | WebRtc_Word32 w32_energy; |
| 146 | WebRtc_Word32 w32_energyMax; |
| 147 | WebRtc_Word32 w32_energyUpdate; |
| 148 | WebRtc_Word32 w32_energyUpdateLow; |
| 149 | WebRtc_Word16 pw16_filterState[BGN_LPC_ORDER]; |
| 150 | WebRtc_Word16 pw16_filter[BGN_LPC_ORDER + 1]; |
| 151 | WebRtc_Word16 w16_mutefactor; |
| 152 | WebRtc_Word16 w16_scale; |
| 153 | WebRtc_Word16 w16_scaleShift; |
| 154 | WebRtc_Word16 w16_initialized; |
| 155 | enum BGNMode bgnMode; |
| 156 | |
| 157 | } BGNInst_t; |
| 158 | |
| 159 | /* Expansion instance (sub-instance of NETEQDSP_inst) */ |
| 160 | typedef struct ExpandInst_t_ |
| 161 | { |
| 162 | |
| 163 | WebRtc_Word16 w16_overlap; /* Constant, 5 for NB and 10 for WB */ |
| 164 | WebRtc_Word16 w16_consecExp; /* Number of consecutive expand calls */ |
| 165 | WebRtc_Word16 *pw16_arFilter; /* length [UNVOICED_LPC_ORDER+1] */ |
| 166 | WebRtc_Word16 *pw16_arState; /* length [UNVOICED_LPC_ORDER] */ |
| 167 | WebRtc_Word16 w16_arGain; |
| 168 | WebRtc_Word16 w16_arGainScale; |
| 169 | WebRtc_Word16 w16_vFraction; /* Q14 */ |
| 170 | WebRtc_Word16 w16_currentVFraction; /* Q14 */ |
| 171 | WebRtc_Word16 *pw16_expVecs[2]; |
| 172 | WebRtc_Word16 w16_lags[3]; |
| 173 | WebRtc_Word16 w16_maxLag; |
| 174 | WebRtc_Word16 *pw16_overlapVec; /* last samples of speech history */ |
| 175 | WebRtc_Word16 w16_lagsDirection; |
| 176 | WebRtc_Word16 w16_lagsPosition; |
| 177 | WebRtc_Word16 w16_expandMuteFactor; /* Q14 */ |
| 178 | WebRtc_Word16 w16_stopMuting; |
| 179 | WebRtc_Word16 w16_onset; |
| 180 | WebRtc_Word16 w16_muteSlope; /* Q20 */ |
| 181 | |
| 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.org | ab2bb82 | 2012-01-18 14:51:02 +0000 | [diff] [blame] | 191 | typedef int (*VADInitFunction)(void *VAD_inst); |
bjornv@webrtc.org | 152c34c | 2012-01-23 12:36:46 +0000 | [diff] [blame^] | 192 | typedef int (*VADSetmodeFunction)(void *VAD_inst, WebRtc_Word16 mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 193 | typedef WebRtc_Word16 (*VADFunction)(void *VAD_inst, WebRtc_Word16 fs, WebRtc_Word16 *frame, |
| 194 | WebRtc_Word16 frameLen); |
| 195 | |
| 196 | /* Post-decode VAD instance (sub-instance of NETEQDSP_inst) */ |
| 197 | typedef struct PostDecodeVAD_t_ |
| 198 | { |
| 199 | |
| 200 | void *VADState; /* pointer to a VAD instance */ |
| 201 | |
| 202 | WebRtc_Word16 VADEnabled; /* 1 if enabled, 0 if disabled */ |
| 203 | WebRtc_Word16 VADMode; /* mode parameter to pass to the VAD function */ |
| 204 | WebRtc_Word16 VADDecision; /* 1 for active, 0 for passive */ |
| 205 | WebRtc_Word16 SIDintervalCounter; /* reset when decoding CNG/SID frame, |
| 206 | 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 | |
| 220 | typedef struct |
| 221 | { |
| 222 | /* Stand-alone, master, or slave */ |
| 223 | enum MasterSlaveMode msMode; |
| 224 | |
| 225 | enum MasterSlaveExtraInfo extraInfo; |
| 226 | |
| 227 | WebRtc_UWord16 instruction; |
| 228 | WebRtc_Word16 distLag; |
| 229 | WebRtc_Word16 corrLag; |
| 230 | WebRtc_Word16 bestIndex; |
| 231 | |
| 232 | WebRtc_UWord32 endTimestamp; |
| 233 | WebRtc_UWord16 samplesLeftWithOverlap; |
| 234 | |
| 235 | } MasterSlaveInfo; |
| 236 | #endif |
| 237 | |
| 238 | |
| 239 | /* "Main" NetEQ DSP instance */ |
| 240 | typedef struct DSPInst_t_ |
| 241 | { |
| 242 | |
| 243 | /* MCU/DSP Communication layer */ |
| 244 | WebRtc_Word16 *pw16_readAddress; |
| 245 | WebRtc_Word16 *pw16_writeAddress; |
| 246 | void *main_inst; |
| 247 | |
| 248 | /* Output frame size in ms and samples */ |
| 249 | WebRtc_Word16 millisecondsPerCall; |
| 250 | WebRtc_Word16 timestampsPerCall; |
| 251 | |
| 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 | |
| 266 | WebRtc_Word16 speechBuffer[SPEECH_BUF_SIZE]; /* History/future speech buffer */ |
| 267 | int curPosition; /* Next sample to play */ |
| 268 | int endPosition; /* Position that ends future data */ |
| 269 | WebRtc_UWord32 endTimestamp; /* Timestamp value at end of future data */ |
| 270 | WebRtc_UWord32 videoSyncTimestamp; /* (Estimated) timestamp of the last |
| 271 | played sample (usually same as |
| 272 | endTimestamp-(endPosition-curPosition) |
| 273 | except during Expand and CNG) */ |
| 274 | WebRtc_UWord16 fs; /* sample rate in Hz */ |
| 275 | WebRtc_Word16 w16_frameLen; /* decoder frame length in samples */ |
| 276 | WebRtc_Word16 w16_mode; /* operation used during last RecOut call */ |
| 277 | WebRtc_Word16 w16_muteFactor; /* speech mute factor in Q14 */ |
| 278 | WebRtc_Word16 *pw16_speechHistory; /* beginning of speech history during Expand */ |
| 279 | WebRtc_Word16 w16_speechHistoryLen; /* 256 for NB and 512 for WB */ |
| 280 | |
| 281 | /* random noise seed parameters */ |
| 282 | WebRtc_Word16 w16_seedInc; |
| 283 | WebRtc_UWord32 uw16_seed; |
| 284 | |
| 285 | /* VQmon related variable */ |
| 286 | WebRtc_Word16 w16_concealedTS; |
| 287 | |
| 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 | |
| 319 | #ifdef NETEQ_STEREO |
| 320 | /* Pointer to Master/Slave info */ |
| 321 | MasterSlaveInfo *msInfo; |
| 322 | #endif |
| 323 | |
| 324 | } DSPInst_t; |
| 325 | |
| 326 | |
| 327 | /*************************/ |
| 328 | /* Function declarations */ |
| 329 | /*************************/ |
| 330 | |
| 331 | /**************************************************************************** |
| 332 | * WebRtcNetEQ_DSPInit(...) |
| 333 | * |
| 334 | * Initializes DSP side of NetEQ. |
| 335 | * |
| 336 | * Input: |
| 337 | * - inst : NetEq DSP instance |
| 338 | * - fs : Initial sample rate (may change when decoding data) |
| 339 | * |
| 340 | * Output: |
| 341 | * - inst : Updated instance |
| 342 | * |
| 343 | * Return value : 0 - ok |
| 344 | * : non-zero - error |
| 345 | */ |
| 346 | |
| 347 | int WebRtcNetEQ_DSPInit(DSPInst_t *inst, WebRtc_UWord16 fs); |
| 348 | |
| 349 | /**************************************************************************** |
| 350 | * WebRtcNetEQ_AddressInit(...) |
| 351 | * |
| 352 | * Initializes the shared-memory communication on the DSP side. |
| 353 | * |
| 354 | * Input: |
| 355 | * - inst : NetEQ DSP instance |
| 356 | * - data2McuAddress : Pointer to memory where DSP writes / MCU reads |
| 357 | * - data2DspAddress : Pointer to memory where MCU writes / DSP reads |
| 358 | * - mainInst : NetEQ main instance |
| 359 | * |
| 360 | * Output: |
| 361 | * - inst : Updated instance |
| 362 | * |
| 363 | * Return value : 0 - ok |
| 364 | */ |
| 365 | |
| 366 | int WebRtcNetEQ_AddressInit(DSPInst_t *inst, const void *data2McuAddress, |
| 367 | const void *data2DspAddress, const void *mainInst); |
| 368 | |
| 369 | /**************************************************************************** |
| 370 | * WebRtcNetEQ_ClearInCallStats(...) |
| 371 | * |
| 372 | * Reset in-call statistics variables on DSP side. |
| 373 | * |
| 374 | * Input: |
| 375 | * - inst : NetEQ DSP instance |
| 376 | * |
| 377 | * Output: |
| 378 | * - inst : Updated instance |
| 379 | * |
| 380 | * Return value : 0 - ok |
| 381 | */ |
| 382 | |
| 383 | int WebRtcNetEQ_ClearInCallStats(DSPInst_t *inst); |
| 384 | |
| 385 | /**************************************************************************** |
| 386 | * WebRtcNetEQ_ClearPostCallStats(...) |
| 387 | * |
| 388 | * Reset post-call statistics variables on DSP side. |
| 389 | * |
| 390 | * Input: |
| 391 | * - inst : NetEQ DSP instance |
| 392 | * |
| 393 | * Output: |
| 394 | * - inst : Updated instance |
| 395 | * |
| 396 | * Return value : 0 - ok |
| 397 | */ |
| 398 | |
| 399 | int WebRtcNetEQ_ClearPostCallStats(DSPInst_t *inst); |
| 400 | |
| 401 | /**************************************************************************** |
| 402 | * WebRtcNetEQ_RecOutInternal(...) |
| 403 | * |
| 404 | * This function asks NetEQ for more speech/audio data. |
| 405 | * |
| 406 | * Input: |
| 407 | * - inst : NetEQ instance, i.e. the user that requests more |
| 408 | * speech/audio data. |
| 409 | * - outdata : Pointer to a memory space where the output data |
| 410 | * should be stored. |
| 411 | * - BGNonly : If non-zero, RecOut will only produce background |
| 412 | * noise. It will still draw packets from the packet |
| 413 | * buffer, but they will never be decoded. |
| 414 | * |
| 415 | * Output: |
| 416 | * - inst : Updated user information |
| 417 | * - len : Number of samples that were outputted from NetEq |
| 418 | * |
| 419 | * Return value : 0 - Ok |
| 420 | * -1 - Error |
| 421 | */ |
| 422 | |
| 423 | int WebRtcNetEQ_RecOutInternal(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, WebRtc_Word16 *pw16_len, |
| 424 | WebRtc_Word16 BGNonly); |
| 425 | |
| 426 | /**************************************************************************** |
| 427 | * WebRtcNetEQ_Normal(...) |
| 428 | * |
| 429 | * This function has the possibility to modify data that is played out in Normal |
| 430 | * mode, for example adjust the gain of the signal. The length of the signal |
| 431 | * can not be changed. |
| 432 | * |
| 433 | * Input: |
| 434 | * - inst : NetEQ DSP instance |
| 435 | * - scratchPtr : Pointer to scratch vector |
| 436 | * - decoded : Pointer to vector of new data from decoder |
| 437 | * - len : Number of input samples |
| 438 | * |
| 439 | * Output: |
| 440 | * - inst : Updated user information |
| 441 | * - pw16_len : Pointer to varibale where the number of samples |
| 442 | * produced will be written |
| 443 | * |
| 444 | * Return value : >=0 - Number of samples written to outData |
| 445 | * -1 - Error |
| 446 | */ |
| 447 | |
| 448 | int WebRtcNetEQ_Normal(DSPInst_t *inst, |
| 449 | #ifdef SCRATCH |
| 450 | WebRtc_Word16 *pw16_scratchPtr, |
| 451 | #endif |
| 452 | WebRtc_Word16 *pw16_decoded, WebRtc_Word16 len, |
| 453 | WebRtc_Word16 *pw16_outData, WebRtc_Word16 *pw16_len); |
| 454 | |
| 455 | /**************************************************************************** |
| 456 | * WebRtcNetEQ_Expand(...) |
| 457 | * |
| 458 | * This function produces one "chunk" of expansion data (PLC audio). The |
| 459 | * lenght of the produced audio depends on the speech history. |
| 460 | * |
| 461 | * Input: |
| 462 | * - inst : NetEQ DSP instance |
| 463 | * - scratchPtr : Pointer to scratch vector |
| 464 | * - BGNonly : If non-zero, Expand will only produce background |
| 465 | * noise. |
| 466 | * - pw16_len : Desired number of samples (only for BGN mode). |
| 467 | * |
| 468 | * Output: |
| 469 | * - inst : Updated user information |
| 470 | * - outdata : Pointer to a memory space where the output data |
| 471 | * should be stored |
| 472 | * - pw16_len : Number of samples that were outputted from NetEq |
| 473 | * |
| 474 | * Return value : 0 - Ok |
| 475 | * <0 - Error |
| 476 | */ |
| 477 | |
| 478 | int WebRtcNetEQ_Expand(DSPInst_t *inst, |
| 479 | #ifdef SCRATCH |
| 480 | WebRtc_Word16 *pw16_scratchPtr, |
| 481 | #endif |
| 482 | WebRtc_Word16 *pw16_outData, WebRtc_Word16 *pw16_len, |
| 483 | WebRtc_Word16 BGNonly); |
| 484 | |
| 485 | /**************************************************************************** |
| 486 | * WebRtcNetEQ_GenerateBGN(...) |
| 487 | * |
| 488 | * This function generates and writes len samples of background noise to the |
| 489 | * output vector. The Expand function will be called repeteadly until the |
| 490 | * correct number of samples is produced. |
| 491 | * |
| 492 | * Input: |
| 493 | * - inst : NetEQ DSP instance |
| 494 | * - scratchPtr : Pointer to scratch vector |
| 495 | * - len : Desired length of produced BGN. |
| 496 | * |
| 497 | * |
| 498 | * Output: |
| 499 | * - pw16_outData : Pointer to a memory space where the output data |
| 500 | * should be stored |
| 501 | * |
| 502 | * Return value : >=0 - Number of noise samples produced and written |
| 503 | * to output |
| 504 | * -1 - Error |
| 505 | */ |
| 506 | |
| 507 | int WebRtcNetEQ_GenerateBGN(DSPInst_t *inst, |
| 508 | #ifdef SCRATCH |
| 509 | WebRtc_Word16 *pw16_scratchPtr, |
| 510 | #endif |
| 511 | WebRtc_Word16 *pw16_outData, WebRtc_Word16 len); |
| 512 | |
| 513 | /**************************************************************************** |
| 514 | * WebRtcNetEQ_PreEmptiveExpand(...) |
| 515 | * |
| 516 | * This function tries to extend the audio data by repeating one or several |
| 517 | * pitch periods. The operation is only carried out if the correlation is |
| 518 | * strong or if the signal energy is very low. The algorithm is the |
| 519 | * reciprocal of the Accelerate algorithm. |
| 520 | * |
| 521 | * Input: |
| 522 | * - inst : NetEQ DSP instance |
| 523 | * - scratchPtr : Pointer to scratch vector. |
| 524 | * - decoded : Pointer to newly decoded speech. |
| 525 | * - len : Length of decoded speech. |
| 526 | * - oldDataLen : Length of the part of decoded that has already been played out. |
| 527 | * - BGNonly : If non-zero, Pre-emptive Expand will only copy |
| 528 | * the first DEFAULT_TIME_ADJUST seconds of the |
| 529 | * input and append to the end. No signal matching is |
| 530 | * done. |
| 531 | * |
| 532 | * Output: |
| 533 | * - inst : Updated instance |
| 534 | * - outData : Pointer to a memory space where the output data |
| 535 | * should be stored. The vector must be at least |
| 536 | * min(len + 120*fs/8000, NETEQ_MAX_OUTPUT_SIZE) |
| 537 | * elements long. |
| 538 | * - pw16_len : Number of samples written to outData. |
| 539 | * |
| 540 | * Return value : 0 - Ok |
| 541 | * <0 - Error |
| 542 | */ |
| 543 | |
| 544 | int WebRtcNetEQ_PreEmptiveExpand(DSPInst_t *inst, |
| 545 | #ifdef SCRATCH |
| 546 | WebRtc_Word16 *pw16_scratchPtr, |
| 547 | #endif |
| 548 | const WebRtc_Word16 *pw16_decoded, int len, int oldDataLen, |
| 549 | WebRtc_Word16 *pw16_outData, WebRtc_Word16 *pw16_len, |
| 550 | WebRtc_Word16 BGNonly); |
| 551 | |
| 552 | /**************************************************************************** |
| 553 | * WebRtcNetEQ_Accelerate(...) |
| 554 | * |
| 555 | * This function tries to shorten the audio data by removing one or several |
| 556 | * pitch periods. The operation is only carried out if the correlation is |
| 557 | * strong or if the signal energy is very low. |
| 558 | * |
| 559 | * Input: |
| 560 | * - inst : NetEQ DSP instance |
| 561 | * - scratchPtr : Pointer to scratch vector. |
| 562 | * - decoded : Pointer to newly decoded speech. |
| 563 | * - len : Length of decoded speech. |
| 564 | * - BGNonly : If non-zero, Accelerate will only remove the last |
| 565 | * DEFAULT_TIME_ADJUST seconds of the intput. |
| 566 | * No signal matching is done. |
| 567 | * |
| 568 | * |
| 569 | * Output: |
| 570 | * - inst : Updated instance |
| 571 | * - outData : Pointer to a memory space where the output data |
| 572 | * should be stored |
| 573 | * - pw16_len : Number of samples written to outData. |
| 574 | * |
| 575 | * Return value : 0 - Ok |
| 576 | * <0 - Error |
| 577 | */ |
| 578 | |
| 579 | int WebRtcNetEQ_Accelerate(DSPInst_t *inst, |
| 580 | #ifdef SCRATCH |
| 581 | WebRtc_Word16 *pw16_scratchPtr, |
| 582 | #endif |
| 583 | const WebRtc_Word16 *pw16_decoded, int len, |
| 584 | WebRtc_Word16 *pw16_outData, WebRtc_Word16 *pw16_len, |
| 585 | WebRtc_Word16 BGNonly); |
| 586 | |
| 587 | /**************************************************************************** |
| 588 | * WebRtcNetEQ_Merge(...) |
| 589 | * |
| 590 | * This function is used to merge new data from the decoder to the exisiting |
| 591 | * stream in the synchronization buffer. The merge operation is typically |
| 592 | * done after a packet loss, where the end of the expanded data does not |
| 593 | * fit naturally with the new decoded data. |
| 594 | * |
| 595 | * Input: |
| 596 | * - inst : NetEQ DSP instance |
| 597 | * - scratchPtr : Pointer to scratch vector. |
| 598 | * - decoded : Pointer to new decoded speech. |
| 599 | * - len : Number of samples in pw16_decoded. |
| 600 | * |
| 601 | * |
| 602 | * Output: |
| 603 | * - inst : Updated user information |
| 604 | * - outData : Pointer to a memory space where the output data |
| 605 | * should be stored |
| 606 | * - pw16_len : Number of samples written to pw16_outData |
| 607 | * |
| 608 | * Return value : 0 - Ok |
| 609 | * <0 - Error |
| 610 | */ |
| 611 | |
| 612 | int WebRtcNetEQ_Merge(DSPInst_t *inst, |
| 613 | #ifdef SCRATCH |
| 614 | WebRtc_Word16 *pw16_scratchPtr, |
| 615 | #endif |
| 616 | WebRtc_Word16 *pw16_decoded, int len, WebRtc_Word16 *pw16_outData, |
| 617 | WebRtc_Word16 *pw16_len); |
| 618 | |
| 619 | /**************************************************************************** |
| 620 | * WebRtcNetEQ_Cng(...) |
| 621 | * |
| 622 | * This function produces CNG according to RFC 3389 |
| 623 | * |
| 624 | * Input: |
| 625 | * - inst : NetEQ DSP instance |
| 626 | * - len : Number of samples to produce |
| 627 | * |
| 628 | * Output: |
| 629 | * - pw16_outData : Output CNG |
| 630 | * |
| 631 | * Return value : 0 - Ok |
| 632 | * <0 - Error |
| 633 | */ |
| 634 | |
| 635 | #ifdef NETEQ_CNG_CODEC |
| 636 | /* Must compile NetEQ with CNG support to enable this function */ |
| 637 | |
| 638 | int WebRtcNetEQ_Cng(DSPInst_t *inst, WebRtc_Word16 *pw16_outData, int len); |
| 639 | |
| 640 | #endif /* NETEQ_CNG_CODEC */ |
| 641 | |
| 642 | /**************************************************************************** |
| 643 | * WebRtcNetEQ_BGNUpdate(...) |
| 644 | * |
| 645 | * This function updates the background noise parameter estimates. |
| 646 | * |
| 647 | * Input: |
| 648 | * - inst : NetEQ instance, where the speech history is stored. |
| 649 | * - scratchPtr : Pointer to scratch vector. |
| 650 | * |
| 651 | * Output: |
| 652 | * - inst : Updated information about the BGN characteristics. |
| 653 | * |
| 654 | * Return value : No return value |
| 655 | */ |
| 656 | |
| 657 | void WebRtcNetEQ_BGNUpdate( |
| 658 | #ifdef SCRATCH |
| 659 | DSPInst_t *inst, WebRtc_Word16 *pw16_scratchPtr |
| 660 | #else |
| 661 | DSPInst_t *inst |
| 662 | #endif |
| 663 | ); |
| 664 | |
| 665 | #ifdef NETEQ_VAD |
| 666 | /* Functions used by post-decode VAD */ |
| 667 | |
| 668 | /**************************************************************************** |
| 669 | * WebRtcNetEQ_InitVAD(...) |
| 670 | * |
| 671 | * Initializes post-decode VAD instance. |
| 672 | * |
| 673 | * Input: |
| 674 | * - VADinst : PostDecodeVAD instance |
| 675 | * - fs : Initial sample rate |
| 676 | * |
| 677 | * Output: |
| 678 | * - VADinst : Updated instance |
| 679 | * |
| 680 | * Return value : 0 - Ok |
| 681 | * -1 - Error |
| 682 | */ |
| 683 | |
| 684 | int WebRtcNetEQ_InitVAD(PostDecodeVAD_t *VADInst, WebRtc_UWord16 fs); |
| 685 | |
| 686 | /**************************************************************************** |
| 687 | * WebRtcNetEQ_SetVADModeInternal(...) |
| 688 | * |
| 689 | * Set the VAD mode in the VAD struct, and communicate it to the VAD instance |
| 690 | * if it exists. |
| 691 | * |
| 692 | * Input: |
| 693 | * - VADinst : PostDecodeVAD instance |
| 694 | * - mode : Mode number passed on to the VAD function |
| 695 | * |
| 696 | * Output: |
| 697 | * - VADinst : Updated instance |
| 698 | * |
| 699 | * Return value : 0 - Ok |
| 700 | * -1 - Error |
| 701 | */ |
| 702 | |
| 703 | int WebRtcNetEQ_SetVADModeInternal(PostDecodeVAD_t *VADInst, WebRtc_Word16 mode); |
| 704 | |
| 705 | #endif /* NETEQ_VAD */ |
| 706 | |
| 707 | /**************************************************************************** |
| 708 | * WebRtcNetEQ_FlushSpeechBuffer(...) |
| 709 | * |
| 710 | * Flush the speech buffer. |
| 711 | * |
| 712 | * Input: |
| 713 | * - inst : NetEq DSP instance |
| 714 | * |
| 715 | * Output: |
| 716 | * - inst : Updated instance |
| 717 | * |
| 718 | * Return value : 0 - ok |
| 719 | * : non-zero - error |
| 720 | */ |
| 721 | |
| 722 | int WebRtcNetEQ_FlushSpeechBuffer(DSPInst_t *inst); |
| 723 | |
| 724 | #ifndef WEBRTC_NETEQ_40BITACC_TEST |
| 725 | |
| 726 | #include "signal_processing_library.h" |
| 727 | /* Map to regular SPL functions */ |
| 728 | #define WebRtcNetEQ_CrossCorr WebRtcSpl_CrossCorrelation |
| 729 | #define WebRtcNetEQ_DotW16W16 WebRtcSpl_DotProductWithScale |
| 730 | |
| 731 | #else /* WEBRTC_NETEQ_40BITACC_TEST defined */ |
| 732 | /* Run NetEQ with simulated 40-bit accumulator to run bit-exact to a DSP |
| 733 | implementation where the main (splib and NetEQ) functions have been |
| 734 | 40-bit optimized. */ |
| 735 | |
| 736 | /* Map to special 40-bit optimized functions, defined below */ |
| 737 | #define WebRtcNetEQ_CrossCorr WebRtcNetEQ_40BitAccCrossCorr |
| 738 | #define WebRtcNetEQ_DotW16W16 WebRtcNetEQ_40BitAccDotW16W16 |
| 739 | |
| 740 | /**************************************************************************** |
| 741 | * WebRtcNetEQ_40BitAccCrossCorr(...) |
| 742 | * |
| 743 | * Calculates the Cross correlation between two sequences seq1 and seq2. Seq1 |
| 744 | * is fixed and seq2 slides as the pointer is increased with step |
| 745 | * |
| 746 | * Input: |
| 747 | * - seq1 : First sequence (fixed throughout the correlation) |
| 748 | * - seq2 : Second sequence (slided step_seq2 for each |
| 749 | * new correlation) |
| 750 | * - dimSeq : Number of samples to use in the cross correlation. |
| 751 | * Should be no larger than 1024 to avoid overflow. |
| 752 | * - dimCrossCorr : Number of CrossCorrelations to calculate (start |
| 753 | * position for seq2 is updated for each new one) |
| 754 | * - rShift : Number of right shifts to use |
| 755 | * - step_seq2 : How many (positive or negative) steps the seq2 |
| 756 | * pointer should be updated for each new cross |
| 757 | * correlation value |
| 758 | * |
| 759 | * Output: |
| 760 | * - crossCorr : The cross correlation in Q-rShift |
| 761 | */ |
| 762 | |
| 763 | void WebRtcNetEQ_40BitAccCrossCorr(WebRtc_Word32 *crossCorr, WebRtc_Word16 *seq1, |
| 764 | WebRtc_Word16 *seq2, WebRtc_Word16 dimSeq, |
| 765 | WebRtc_Word16 dimCrossCorr, WebRtc_Word16 rShift, |
| 766 | WebRtc_Word16 step_seq2); |
| 767 | |
| 768 | /**************************************************************************** |
| 769 | * WebRtcNetEQ_40BitAccDotW16W16(...) |
| 770 | * |
| 771 | * Calculates the dot product between two vectors (WebRtc_Word16) |
| 772 | * |
| 773 | * Input: |
| 774 | * - vector1 : Vector 1 |
| 775 | * - vector2 : Vector 2 |
| 776 | * - len : Number of samples in vector |
| 777 | * Should be no larger than 1024 to avoid overflow. |
| 778 | * - scaling : The number of right shifts (after multiplication) |
| 779 | * required to avoid overflow in the dot product. |
| 780 | * Return value : The dot product |
| 781 | */ |
| 782 | |
| 783 | WebRtc_Word32 WebRtcNetEQ_40BitAccDotW16W16(WebRtc_Word16 *vector1, WebRtc_Word16 *vector2, |
| 784 | int len, int scaling); |
| 785 | |
| 786 | #endif /* WEBRTC_NETEQ_40BITACC_TEST */ |
| 787 | |
| 788 | #endif /* DSP_H */ |