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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 instISAC->initFlag = 0; | 244 instISAC->initFlag = 0; |
245 | 245 |
246 /* Assign the address. */ | 246 /* Assign the address. */ |
247 *ISAC_main_inst = (ISACStruct*)instISAC_Addr; | 247 *ISAC_main_inst = (ISACStruct*)instISAC_Addr; |
248 | 248 |
249 /* Default is wideband. */ | 249 /* Default is wideband. */ |
250 instISAC->encoderSamplingRateKHz = kIsacWideband; | 250 instISAC->encoderSamplingRateKHz = kIsacWideband; |
251 instISAC->decoderSamplingRateKHz = kIsacWideband; | 251 instISAC->decoderSamplingRateKHz = kIsacWideband; |
252 instISAC->bandwidthKHz = isac8kHz; | 252 instISAC->bandwidthKHz = isac8kHz; |
253 instISAC->in_sample_rate_hz = 16000; | 253 instISAC->in_sample_rate_hz = 16000; |
| 254 |
| 255 WebRtcIsac_InitTransform(&instISAC->transform_tables); |
254 return 0; | 256 return 0; |
255 } else { | 257 } else { |
256 return -1; | 258 return -1; |
257 } | 259 } |
258 } | 260 } |
259 | 261 |
260 | 262 |
261 /**************************************************************************** | 263 /**************************************************************************** |
262 * WebRtcIsac_Create(...) | 264 * WebRtcIsac_Create(...) |
263 * | 265 * |
(...skipping 13 matching lines...) Expand all Loading... |
277 instISAC = (ISACMainStruct*)malloc(sizeof(ISACMainStruct)); | 279 instISAC = (ISACMainStruct*)malloc(sizeof(ISACMainStruct)); |
278 *ISAC_main_inst = (ISACStruct*)instISAC; | 280 *ISAC_main_inst = (ISACStruct*)instISAC; |
279 if (*ISAC_main_inst != NULL) { | 281 if (*ISAC_main_inst != NULL) { |
280 instISAC->errorCode = 0; | 282 instISAC->errorCode = 0; |
281 instISAC->initFlag = 0; | 283 instISAC->initFlag = 0; |
282 /* Default is wideband. */ | 284 /* Default is wideband. */ |
283 instISAC->bandwidthKHz = isac8kHz; | 285 instISAC->bandwidthKHz = isac8kHz; |
284 instISAC->encoderSamplingRateKHz = kIsacWideband; | 286 instISAC->encoderSamplingRateKHz = kIsacWideband; |
285 instISAC->decoderSamplingRateKHz = kIsacWideband; | 287 instISAC->decoderSamplingRateKHz = kIsacWideband; |
286 instISAC->in_sample_rate_hz = 16000; | 288 instISAC->in_sample_rate_hz = 16000; |
| 289 |
| 290 WebRtcIsac_InitTransform(&instISAC->transform_tables); |
287 return 0; | 291 return 0; |
288 } else { | 292 } else { |
289 return -1; | 293 return -1; |
290 } | 294 } |
291 } else { | 295 } else { |
292 return -1; | 296 return -1; |
293 } | 297 } |
294 } | 298 } |
295 | 299 |
296 | 300 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 inFrame[2] += (float)1.90854954e-3; | 576 inFrame[2] += (float)1.90854954e-3; |
573 inFrame[9] += (float)1.84854878e-3; | 577 inFrame[9] += (float)1.84854878e-3; |
574 | 578 |
575 /* This function will update the bottleneck if required. */ | 579 /* This function will update the bottleneck if required. */ |
576 UpdateBottleneck(instISAC); | 580 UpdateBottleneck(instISAC); |
577 | 581 |
578 /* Get the bandwith information which has to be sent to the other side. */ | 582 /* Get the bandwith information which has to be sent to the other side. */ |
579 GetSendBandwidthInfo(instISAC, &bottleneckIdx, &jitterInfo); | 583 GetSendBandwidthInfo(instISAC, &bottleneckIdx, &jitterInfo); |
580 | 584 |
581 /* Encode lower-band. */ | 585 /* Encode lower-band. */ |
582 streamLenLB = WebRtcIsac_EncodeLb(inFrame, &instLB->ISACencLB_obj, | 586 streamLenLB = WebRtcIsac_EncodeLb(&instISAC->transform_tables, |
| 587 inFrame, &instLB->ISACencLB_obj, |
583 instISAC->codingMode, bottleneckIdx); | 588 instISAC->codingMode, bottleneckIdx); |
584 if (streamLenLB < 0) { | 589 if (streamLenLB < 0) { |
585 return -1; | 590 return -1; |
586 } | 591 } |
587 | 592 |
588 if (instISAC->encoderSamplingRateKHz == kIsacSuperWideband) { | 593 if (instISAC->encoderSamplingRateKHz == kIsacSuperWideband) { |
589 instUB = &(instISAC->instUB); | 594 instUB = &(instISAC->instUB); |
590 | 595 |
591 /* Convert to float. */ | 596 /* Convert to float. */ |
592 for (k = 0; k < FRAMESAMPLES_10ms; k++) { | 597 for (k = 0; k < FRAMESAMPLES_10ms; k++) { |
593 inFrame[k] = (float) speechInUB[k]; | 598 inFrame[k] = (float) speechInUB[k]; |
594 } | 599 } |
595 | 600 |
596 /* Add some noise to avoid denormal numbers. */ | 601 /* Add some noise to avoid denormal numbers. */ |
597 inFrame[0] += (float)1.23455334e-3; | 602 inFrame[0] += (float)1.23455334e-3; |
598 inFrame[1] -= (float)2.04324239e-3; | 603 inFrame[1] -= (float)2.04324239e-3; |
599 inFrame[2] += (float)1.90854954e-3; | 604 inFrame[2] += (float)1.90854954e-3; |
600 inFrame[9] += (float)1.84854878e-3; | 605 inFrame[9] += (float)1.84854878e-3; |
601 | 606 |
602 /* Tell to upper-band the number of bytes used so far. | 607 /* Tell to upper-band the number of bytes used so far. |
603 * This is for payload limitation. */ | 608 * This is for payload limitation. */ |
604 instUB->ISACencUB_obj.numBytesUsed = | 609 instUB->ISACencUB_obj.numBytesUsed = |
605 (int16_t)(streamLenLB + 1 + LEN_CHECK_SUM_WORD8); | 610 (int16_t)(streamLenLB + 1 + LEN_CHECK_SUM_WORD8); |
606 /* Encode upper-band. */ | 611 /* Encode upper-band. */ |
607 switch (instISAC->bandwidthKHz) { | 612 switch (instISAC->bandwidthKHz) { |
608 case isac12kHz: { | 613 case isac12kHz: { |
609 streamLenUB = WebRtcIsac_EncodeUb12(inFrame, &instUB->ISACencUB_obj, | 614 streamLenUB = WebRtcIsac_EncodeUb12(&instISAC->transform_tables, |
| 615 inFrame, &instUB->ISACencUB_obj, |
610 jitterInfo); | 616 jitterInfo); |
611 break; | 617 break; |
612 } | 618 } |
613 case isac16kHz: { | 619 case isac16kHz: { |
614 streamLenUB = WebRtcIsac_EncodeUb16(inFrame, &instUB->ISACencUB_obj, | 620 streamLenUB = WebRtcIsac_EncodeUb16(&instISAC->transform_tables, |
| 621 inFrame, &instUB->ISACencUB_obj, |
615 jitterInfo); | 622 jitterInfo); |
616 break; | 623 break; |
617 } | 624 } |
618 case isac8kHz: { | 625 case isac8kHz: { |
619 streamLenUB = 0; | 626 streamLenUB = 0; |
620 break; | 627 break; |
621 } | 628 } |
622 } | 629 } |
623 | 630 |
624 if ((streamLenUB < 0) && (streamLenUB != -ISAC_PAYLOAD_LARGER_THAN_LIMIT)) { | 631 if ((streamLenUB < 0) && (streamLenUB != -ISAC_PAYLOAD_LARGER_THAN_LIMIT)) { |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 /* We need to initialize numSamplesLB to something; otherwise, in the test | 1106 /* We need to initialize numSamplesLB to something; otherwise, in the test |
1100 for whether we should return -1 below, the compiler might generate code | 1107 for whether we should return -1 below, the compiler might generate code |
1101 that fools Memcheck (Valgrind) into thinking that the control flow depends | 1108 that fools Memcheck (Valgrind) into thinking that the control flow depends |
1102 on the uninitialized value in numSamplesLB (since WebRtcIsac_DecodeLb will | 1109 on the uninitialized value in numSamplesLB (since WebRtcIsac_DecodeLb will |
1103 not fill it in if it fails and returns -1). */ | 1110 not fill it in if it fails and returns -1). */ |
1104 numSamplesLB = 0; | 1111 numSamplesLB = 0; |
1105 | 1112 |
1106 /* Regardless of that the current codec is setup to work in | 1113 /* Regardless of that the current codec is setup to work in |
1107 * wideband or super-wideband, the decoding of the lower-band | 1114 * wideband or super-wideband, the decoding of the lower-band |
1108 * has to be performed. */ | 1115 * has to be performed. */ |
1109 numDecodedBytesLB = WebRtcIsac_DecodeLb(outFrame, decInstLB, | 1116 numDecodedBytesLB = WebRtcIsac_DecodeLb(&instISAC->transform_tables, |
| 1117 outFrame, decInstLB, |
1110 &numSamplesLB, isRCUPayload); | 1118 &numSamplesLB, isRCUPayload); |
1111 | 1119 |
1112 if ((numDecodedBytesLB < 0) || (numDecodedBytesLB > lenEncodedLBBytes) || | 1120 if ((numDecodedBytesLB < 0) || (numDecodedBytesLB > lenEncodedLBBytes) || |
1113 (numSamplesLB > MAX_FRAMESAMPLES)) { | 1121 (numSamplesLB > MAX_FRAMESAMPLES)) { |
1114 instISAC->errorCode = ISAC_LENGTH_MISMATCH; | 1122 instISAC->errorCode = ISAC_LENGTH_MISMATCH; |
1115 return -1; | 1123 return -1; |
1116 } | 1124 } |
1117 | 1125 |
1118 /* Error Check, we accept multi-layer bit-stream This will limit number | 1126 /* Error Check, we accept multi-layer bit-stream This will limit number |
1119 * of iterations of the while loop. Even without this the number | 1127 * of iterations of the while loop. Even without this the number |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 /* Decode bandwidth information. */ | 1250 /* Decode bandwidth information. */ |
1243 err = WebRtcIsac_DecodeBandwidth(&decInstUB->bitstr_obj, | 1251 err = WebRtcIsac_DecodeBandwidth(&decInstUB->bitstr_obj, |
1244 &bandwidthKHz); | 1252 &bandwidthKHz); |
1245 if (err < 0) { | 1253 if (err < 0) { |
1246 instISAC->errorCode = -err; | 1254 instISAC->errorCode = -err; |
1247 return -1; | 1255 return -1; |
1248 } | 1256 } |
1249 | 1257 |
1250 switch (bandwidthKHz) { | 1258 switch (bandwidthKHz) { |
1251 case isac12kHz: { | 1259 case isac12kHz: { |
1252 numDecodedBytesUB = WebRtcIsac_DecodeUb12(outFrame, decInstUB, | 1260 numDecodedBytesUB = WebRtcIsac_DecodeUb12( |
1253 isRCUPayload); | 1261 &instISAC->transform_tables, outFrame, decInstUB, isRCUPayload); |
1254 | 1262 |
1255 /* Hang-over for transient alleviation - | 1263 /* Hang-over for transient alleviation - |
1256 * wait two frames to add the upper band going up from 8 kHz. */ | 1264 * wait two frames to add the upper band going up from 8 kHz. */ |
1257 if (instISAC->resetFlag_8kHz > 0) { | 1265 if (instISAC->resetFlag_8kHz > 0) { |
1258 if (instISAC->resetFlag_8kHz == 2) { | 1266 if (instISAC->resetFlag_8kHz == 2) { |
1259 /* Silence first and a half frame. */ | 1267 /* Silence first and a half frame. */ |
1260 memset(outFrame, 0, MAX_FRAMESAMPLES * | 1268 memset(outFrame, 0, MAX_FRAMESAMPLES * |
1261 sizeof(float)); | 1269 sizeof(float)); |
1262 } else { | 1270 } else { |
1263 const float rampStep = 2.0f / MAX_FRAMESAMPLES; | 1271 const float rampStep = 2.0f / MAX_FRAMESAMPLES; |
1264 float rampVal = 0; | 1272 float rampVal = 0; |
1265 memset(outFrame, 0, (MAX_FRAMESAMPLES >> 1) * | 1273 memset(outFrame, 0, (MAX_FRAMESAMPLES >> 1) * |
1266 sizeof(float)); | 1274 sizeof(float)); |
1267 | 1275 |
1268 /* Ramp up second half of second frame. */ | 1276 /* Ramp up second half of second frame. */ |
1269 for (k = MAX_FRAMESAMPLES / 2; k < MAX_FRAMESAMPLES; k++) { | 1277 for (k = MAX_FRAMESAMPLES / 2; k < MAX_FRAMESAMPLES; k++) { |
1270 outFrame[k] *= rampVal; | 1278 outFrame[k] *= rampVal; |
1271 rampVal += rampStep; | 1279 rampVal += rampStep; |
1272 } | 1280 } |
1273 } | 1281 } |
1274 instISAC->resetFlag_8kHz -= 1; | 1282 instISAC->resetFlag_8kHz -= 1; |
1275 } | 1283 } |
1276 | 1284 |
1277 break; | 1285 break; |
1278 } | 1286 } |
1279 case isac16kHz: { | 1287 case isac16kHz: { |
1280 numDecodedBytesUB = WebRtcIsac_DecodeUb16(outFrame, decInstUB, | 1288 numDecodedBytesUB = WebRtcIsac_DecodeUb16( |
1281 isRCUPayload); | 1289 &instISAC->transform_tables, outFrame, decInstUB, isRCUPayload); |
1282 break; | 1290 break; |
1283 } | 1291 } |
1284 default: | 1292 default: |
1285 return -1; | 1293 return -1; |
1286 } | 1294 } |
1287 | 1295 |
1288 /* It might be less due to garbage. */ | 1296 /* It might be less due to garbage. */ |
1289 if ((numDecodedBytesUB != lenNextStream) && | 1297 if ((numDecodedBytesUB != lenNextStream) && |
1290 (numDecodedBytesUB != (lenNextStream - | 1298 (numDecodedBytesUB != (lenNextStream - |
1291 encoded[numDecodedBytesLB + 1 + numDecodedBytesUB]))) { | 1299 encoded[numDecodedBytesLB + 1 + numDecodedBytesUB]))) { |
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2368 * - ISAC_main_inst : iSAC instance | 2376 * - ISAC_main_inst : iSAC instance |
2369 * | 2377 * |
2370 * Return value : sampling rate in Hertz. Decoder output is | 2378 * Return value : sampling rate in Hertz. Decoder output is |
2371 * sampled at this rate. | 2379 * sampled at this rate. |
2372 * | 2380 * |
2373 */ | 2381 */ |
2374 uint16_t WebRtcIsac_DecSampRate(ISACStruct* ISAC_main_inst) { | 2382 uint16_t WebRtcIsac_DecSampRate(ISACStruct* ISAC_main_inst) { |
2375 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 2383 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
2376 return instISAC->decoderSamplingRateKHz == kIsacWideband ? 16000 : 32000; | 2384 return instISAC->decoderSamplingRateKHz == kIsacWideband ? 16000 : 32000; |
2377 } | 2385 } |
OLD | NEW |