| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 int16_t dec_EfiltstateLow[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 28 int16_t dec_EfiltstateLow[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 29 int16_t dec_order; | 29 int16_t dec_order; |
| 30 int16_t dec_target_scale_factor; /* Q29 */ | 30 int16_t dec_target_scale_factor; /* Q29 */ |
| 31 int16_t dec_used_scale_factor; /* Q29 */ | 31 int16_t dec_used_scale_factor; /* Q29 */ |
| 32 int16_t target_scale_factor; /* Q13 */ | 32 int16_t target_scale_factor; /* Q13 */ |
| 33 int16_t errorcode; | 33 int16_t errorcode; |
| 34 int16_t initflag; | 34 int16_t initflag; |
| 35 } WebRtcCngDecoder; | 35 } WebRtcCngDecoder; |
| 36 | 36 |
| 37 typedef struct WebRtcCngEncoder_ { | 37 typedef struct WebRtcCngEncoder_ { |
| 38 int16_t enc_nrOfCoefs; | 38 size_t enc_nrOfCoefs; |
| 39 int enc_sampfreq; | 39 int enc_sampfreq; |
| 40 int16_t enc_interval; | 40 int16_t enc_interval; |
| 41 int16_t enc_msSinceSID; | 41 int16_t enc_msSinceSID; |
| 42 int32_t enc_Energy; | 42 int32_t enc_Energy; |
| 43 int16_t enc_reflCoefs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 43 int16_t enc_reflCoefs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 44 int32_t enc_corrVector[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 44 int32_t enc_corrVector[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 45 uint32_t enc_seed; | 45 uint32_t enc_seed; |
| 46 int16_t errorcode; | 46 int16_t errorcode; |
| 47 int16_t initflag; | 47 int16_t initflag; |
| 48 } WebRtcCngEncoder; | 48 } WebRtcCngEncoder; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 * Input: | 221 * Input: |
| 222 * - cng_inst : Pointer to created instance | 222 * - cng_inst : Pointer to created instance |
| 223 * - speech : Signal (noise) to be analyzed | 223 * - speech : Signal (noise) to be analyzed |
| 224 * - nrOfSamples : Size of speech vector | 224 * - nrOfSamples : Size of speech vector |
| 225 * - bytesOut : Nr of bytes to transmit, might be 0 | 225 * - bytesOut : Nr of bytes to transmit, might be 0 |
| 226 * | 226 * |
| 227 * Return value : 0 - Ok | 227 * Return value : 0 - Ok |
| 228 * -1 - Error | 228 * -1 - Error |
| 229 */ | 229 */ |
| 230 int WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, | 230 int WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, |
| 231 int16_t nrOfSamples, uint8_t* SIDdata, | 231 size_t nrOfSamples, uint8_t* SIDdata, |
| 232 int16_t* bytesOut, int16_t forceSID) { | 232 size_t* bytesOut, int16_t forceSID) { |
| 233 WebRtcCngEncoder* inst = (WebRtcCngEncoder*) cng_inst; | 233 WebRtcCngEncoder* inst = (WebRtcCngEncoder*) cng_inst; |
| 234 | 234 |
| 235 int16_t arCoefs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 235 int16_t arCoefs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 236 int32_t corrVector[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 236 int32_t corrVector[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 237 int16_t refCs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 237 int16_t refCs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 238 int16_t hanningW[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; | 238 int16_t hanningW[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; |
| 239 int16_t ReflBeta = 19661; /* 0.6 in q15. */ | 239 int16_t ReflBeta = 19661; /* 0.6 in q15. */ |
| 240 int16_t ReflBetaComp = 13107; /* 0.4 in q15. */ | 240 int16_t ReflBetaComp = 13107; /* 0.4 in q15. */ |
| 241 int32_t outEnergy; | 241 int32_t outEnergy; |
| 242 int outShifts; | 242 int outShifts; |
| 243 int i, stab; | 243 size_t i; |
| 244 int stab; |
| 244 int acorrScale; | 245 int acorrScale; |
| 245 int index; | 246 size_t index; |
| 246 int16_t ind, factor; | 247 size_t ind, factor; |
| 247 int32_t* bptr; | 248 int32_t* bptr; |
| 248 int32_t blo, bhi; | 249 int32_t blo, bhi; |
| 249 int16_t negate; | 250 int16_t negate; |
| 250 const int16_t* aptr; | 251 const int16_t* aptr; |
| 251 int16_t speechBuf[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; | 252 int16_t speechBuf[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; |
| 252 | 253 |
| 253 /* Check if encoder initiated. */ | 254 /* Check if encoder initiated. */ |
| 254 if (inst->initflag != 1) { | 255 if (inst->initflag != 1) { |
| 255 inst->errorcode = CNG_ENCODER_NOT_INITIATED; | 256 inst->errorcode = CNG_ENCODER_NOT_INITIATED; |
| 256 return -1; | 257 return -1; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 274 /* We can only do 5 shifts without destroying accuracy in | 275 /* We can only do 5 shifts without destroying accuracy in |
| 275 * division factor. */ | 276 * division factor. */ |
| 276 if (outShifts > 5) { | 277 if (outShifts > 5) { |
| 277 outEnergy <<= (outShifts - 5); | 278 outEnergy <<= (outShifts - 5); |
| 278 outShifts = 5; | 279 outShifts = 5; |
| 279 } else { | 280 } else { |
| 280 factor /= 2; | 281 factor /= 2; |
| 281 outShifts--; | 282 outShifts--; |
| 282 } | 283 } |
| 283 } | 284 } |
| 284 outEnergy = WebRtcSpl_DivW32W16(outEnergy, factor); | 285 outEnergy = WebRtcSpl_DivW32W16(outEnergy, (int16_t)factor); |
| 285 | 286 |
| 286 if (outEnergy > 1) { | 287 if (outEnergy > 1) { |
| 287 /* Create Hanning Window. */ | 288 /* Create Hanning Window. */ |
| 288 WebRtcSpl_GetHanningWindow(hanningW, nrOfSamples / 2); | 289 WebRtcSpl_GetHanningWindow(hanningW, nrOfSamples / 2); |
| 289 for (i = 0; i < (nrOfSamples / 2); i++) | 290 for (i = 0; i < (nrOfSamples / 2); i++) |
| 290 hanningW[nrOfSamples - i - 1] = hanningW[i]; | 291 hanningW[nrOfSamples - i - 1] = hanningW[i]; |
| 291 | 292 |
| 292 WebRtcSpl_ElementwiseVectorMult(speechBuf, hanningW, speechBuf, nrOfSamples, | 293 WebRtcSpl_ElementwiseVectorMult(speechBuf, hanningW, speechBuf, nrOfSamples, |
| 293 14); | 294 14); |
| 294 | 295 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 /* Q15 to Q7 with rounding. */ | 384 /* Q15 to Q7 with rounding. */ |
| 384 SIDdata[i + 1] = (127 + ((inst->enc_reflCoefs[i] + 128) >> 8)); | 385 SIDdata[i + 1] = (127 + ((inst->enc_reflCoefs[i] + 128) >> 8)); |
| 385 } | 386 } |
| 386 } | 387 } |
| 387 | 388 |
| 388 inst->enc_msSinceSID = 0; | 389 inst->enc_msSinceSID = 0; |
| 389 *bytesOut = inst->enc_nrOfCoefs + 1; | 390 *bytesOut = inst->enc_nrOfCoefs + 1; |
| 390 | 391 |
| 391 inst->enc_msSinceSID += | 392 inst->enc_msSinceSID += |
| 392 (int16_t)((1000 * nrOfSamples) / inst->enc_sampfreq); | 393 (int16_t)((1000 * nrOfSamples) / inst->enc_sampfreq); |
| 393 return inst->enc_nrOfCoefs + 1; | 394 return (int)(inst->enc_nrOfCoefs + 1); |
| 394 } else { | 395 } else { |
| 395 inst->enc_msSinceSID += | 396 inst->enc_msSinceSID += |
| 396 (int16_t)((1000 * nrOfSamples) / inst->enc_sampfreq); | 397 (int16_t)((1000 * nrOfSamples) / inst->enc_sampfreq); |
| 397 *bytesOut = 0; | 398 *bytesOut = 0; |
| 398 return 0; | 399 return 0; |
| 399 } | 400 } |
| 400 } | 401 } |
| 401 | 402 |
| 402 /**************************************************************************** | 403 /**************************************************************************** |
| 403 * WebRtcCng_UpdateSid(...) | 404 * WebRtcCng_UpdateSid(...) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 * | 469 * |
| 469 * Input: | 470 * Input: |
| 470 * - cng_inst : Pointer to created instance that should be freed | 471 * - cng_inst : Pointer to created instance that should be freed |
| 471 * - outData : pointer to area to write CN data | 472 * - outData : pointer to area to write CN data |
| 472 * - nrOfSamples : How much data to generate | 473 * - nrOfSamples : How much data to generate |
| 473 * | 474 * |
| 474 * Return value : 0 - Ok | 475 * Return value : 0 - Ok |
| 475 * -1 - Error | 476 * -1 - Error |
| 476 */ | 477 */ |
| 477 int16_t WebRtcCng_Generate(CNG_dec_inst* cng_inst, int16_t* outData, | 478 int16_t WebRtcCng_Generate(CNG_dec_inst* cng_inst, int16_t* outData, |
| 478 int16_t nrOfSamples, int16_t new_period) { | 479 size_t nrOfSamples, int16_t new_period) { |
| 479 WebRtcCngDecoder* inst = (WebRtcCngDecoder*) cng_inst; | 480 WebRtcCngDecoder* inst = (WebRtcCngDecoder*) cng_inst; |
| 480 | 481 |
| 481 int i; | 482 size_t i; |
| 482 int16_t excitation[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; | 483 int16_t excitation[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; |
| 483 int16_t low[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; | 484 int16_t low[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; |
| 484 int16_t lpPoly[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 485 int16_t lpPoly[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 485 int16_t ReflBetaStd = 26214; /* 0.8 in q15. */ | 486 int16_t ReflBetaStd = 26214; /* 0.8 in q15. */ |
| 486 int16_t ReflBetaCompStd = 6553; /* 0.2 in q15. */ | 487 int16_t ReflBetaCompStd = 6553; /* 0.2 in q15. */ |
| 487 int16_t ReflBetaNewP = 19661; /* 0.6 in q15. */ | 488 int16_t ReflBetaNewP = 19661; /* 0.6 in q15. */ |
| 488 int16_t ReflBetaCompNewP = 13107; /* 0.4 in q15. */ | 489 int16_t ReflBetaCompNewP = 13107; /* 0.4 in q15. */ |
| 489 int16_t Beta, BetaC, tmp1, tmp2, tmp3; | 490 int16_t Beta, BetaC, tmp1, tmp2, tmp3; |
| 490 int32_t targetEnergy; | 491 int32_t targetEnergy; |
| 491 int16_t En; | 492 int16_t En; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 /* Typecast pointer to real structure. */ | 596 /* Typecast pointer to real structure. */ |
| 596 WebRtcCngEncoder* inst = (WebRtcCngEncoder*) cng_inst; | 597 WebRtcCngEncoder* inst = (WebRtcCngEncoder*) cng_inst; |
| 597 return inst->errorcode; | 598 return inst->errorcode; |
| 598 } | 599 } |
| 599 | 600 |
| 600 int16_t WebRtcCng_GetErrorCodeDec(CNG_dec_inst* cng_inst) { | 601 int16_t WebRtcCng_GetErrorCodeDec(CNG_dec_inst* cng_inst) { |
| 601 /* Typecast pointer to real structure. */ | 602 /* Typecast pointer to real structure. */ |
| 602 WebRtcCngDecoder* inst = (WebRtcCngDecoder*) cng_inst; | 603 WebRtcCngDecoder* inst = (WebRtcCngDecoder*) cng_inst; |
| 603 return inst->errorcode; | 604 return inst->errorcode; |
| 604 } | 605 } |
| OLD | NEW |