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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 * Output: | 487 * Output: |
488 * - encoded : the encoded data vector | 488 * - encoded : the encoded data vector |
489 * | 489 * |
490 * Return value: | 490 * Return value: |
491 * : >0 - Length (in bytes) of coded data | 491 * : >0 - Length (in bytes) of coded data |
492 * : 0 - The buffer didn't reach the chosen | 492 * : 0 - The buffer didn't reach the chosen |
493 * frameSize so it keeps buffering speech | 493 * frameSize so it keeps buffering speech |
494 * samples. | 494 * samples. |
495 * : -1 - Error | 495 * : -1 - Error |
496 */ | 496 */ |
497 int WebRtcIsac_Encode(ISACStruct* ISAC_main_inst, | 497 int16_t WebRtcIsac_Encode(ISACStruct* ISAC_main_inst, |
498 const int16_t* speechIn, | 498 const int16_t* speechIn, |
499 uint8_t* encoded) { | 499 uint8_t* encoded) { |
500 float inFrame[FRAMESAMPLES_10ms]; | 500 float inFrame[FRAMESAMPLES_10ms]; |
501 int16_t speechInLB[FRAMESAMPLES_10ms]; | 501 int16_t speechInLB[FRAMESAMPLES_10ms]; |
502 int16_t speechInUB[FRAMESAMPLES_10ms]; | 502 int16_t speechInUB[FRAMESAMPLES_10ms]; |
503 int streamLenLB = 0; | 503 int16_t streamLenLB = 0; |
504 int streamLenUB = 0; | 504 int16_t streamLenUB = 0; |
505 int streamLen = 0; | 505 int16_t streamLen = 0; |
506 int16_t k = 0; | 506 int16_t k = 0; |
507 int garbageLen = 0; | 507 int garbageLen = 0; |
508 int32_t bottleneck = 0; | 508 int32_t bottleneck = 0; |
509 int16_t bottleneckIdx = 0; | 509 int16_t bottleneckIdx = 0; |
510 int16_t jitterInfo = 0; | 510 int16_t jitterInfo = 0; |
511 | 511 |
512 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 512 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
513 ISACLBStruct* instLB = &(instISAC->instLB); | 513 ISACLBStruct* instLB = &(instISAC->instLB); |
514 ISACUBStruct* instUB = &(instISAC->instUB); | 514 ISACUBStruct* instUB = &(instISAC->instUB); |
515 const int16_t* speech_in_ptr = speechIn; | 515 const int16_t* speech_in_ptr = speechIn; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 } | 594 } |
595 | 595 |
596 /* Add some noise to avoid denormal numbers. */ | 596 /* Add some noise to avoid denormal numbers. */ |
597 inFrame[0] += (float)1.23455334e-3; | 597 inFrame[0] += (float)1.23455334e-3; |
598 inFrame[1] -= (float)2.04324239e-3; | 598 inFrame[1] -= (float)2.04324239e-3; |
599 inFrame[2] += (float)1.90854954e-3; | 599 inFrame[2] += (float)1.90854954e-3; |
600 inFrame[9] += (float)1.84854878e-3; | 600 inFrame[9] += (float)1.84854878e-3; |
601 | 601 |
602 /* Tell to upper-band the number of bytes used so far. | 602 /* Tell to upper-band the number of bytes used so far. |
603 * This is for payload limitation. */ | 603 * This is for payload limitation. */ |
604 instUB->ISACencUB_obj.numBytesUsed = | 604 instUB->ISACencUB_obj.numBytesUsed = streamLenLB + 1 + |
605 (int16_t)(streamLenLB + 1 + LEN_CHECK_SUM_WORD8); | 605 LEN_CHECK_SUM_WORD8; |
606 /* Encode upper-band. */ | 606 /* Encode upper-band. */ |
607 switch (instISAC->bandwidthKHz) { | 607 switch (instISAC->bandwidthKHz) { |
608 case isac12kHz: { | 608 case isac12kHz: { |
609 streamLenUB = WebRtcIsac_EncodeUb12(inFrame, &instUB->ISACencUB_obj, | 609 streamLenUB = WebRtcIsac_EncodeUb12(inFrame, &instUB->ISACencUB_obj, |
610 jitterInfo); | 610 jitterInfo); |
611 break; | 611 break; |
612 } | 612 } |
613 case isac16kHz: { | 613 case isac16kHz: { |
614 streamLenUB = WebRtcIsac_EncodeUb16(inFrame, &instUB->ISACencUB_obj, | 614 streamLenUB = WebRtcIsac_EncodeUb16(inFrame, &instUB->ISACencUB_obj, |
615 jitterInfo); | 615 jitterInfo); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 arr_ts, instISAC->encoderSamplingRateKHz, | 1038 arr_ts, instISAC->encoderSamplingRateKHz, |
1039 instISAC->decoderSamplingRateKHz); | 1039 instISAC->decoderSamplingRateKHz); |
1040 if (err < 0) { | 1040 if (err < 0) { |
1041 /* Return error code if something went wrong. */ | 1041 /* Return error code if something went wrong. */ |
1042 instISAC->errorCode = -err; | 1042 instISAC->errorCode = -err; |
1043 return -1; | 1043 return -1; |
1044 } | 1044 } |
1045 return 0; | 1045 return 0; |
1046 } | 1046 } |
1047 | 1047 |
1048 static int Decode(ISACStruct* ISAC_main_inst, | 1048 static int16_t Decode(ISACStruct* ISAC_main_inst, |
1049 const uint8_t* encoded, | 1049 const uint8_t* encoded, |
1050 int16_t lenEncodedBytes, | 1050 int16_t lenEncodedBytes, |
1051 int16_t* decoded, | 1051 int16_t* decoded, |
1052 int16_t* speechType, | 1052 int16_t* speechType, |
1053 int16_t isRCUPayload) { | 1053 int16_t isRCUPayload) { |
1054 /* Number of samples (480 or 960), output from decoder | 1054 /* Number of samples (480 or 960), output from decoder |
1055 that were actually used in the encoder/decoder | 1055 that were actually used in the encoder/decoder |
1056 (determined on the fly). */ | 1056 (determined on the fly). */ |
1057 int16_t numSamplesLB; | 1057 int16_t numSamplesLB; |
1058 int16_t numSamplesUB; | 1058 int16_t numSamplesUB; |
1059 int16_t speechIdx; | 1059 int16_t speechIdx; |
1060 float outFrame[MAX_FRAMESAMPLES]; | 1060 float outFrame[MAX_FRAMESAMPLES]; |
1061 int16_t outFrameLB[MAX_FRAMESAMPLES]; | 1061 int16_t outFrameLB[MAX_FRAMESAMPLES]; |
1062 int16_t outFrameUB[MAX_FRAMESAMPLES]; | 1062 int16_t outFrameUB[MAX_FRAMESAMPLES]; |
1063 int numDecodedBytesLB; | 1063 int16_t numDecodedBytesLB; |
1064 int numDecodedBytesUB; | 1064 int16_t numDecodedBytesUB; |
1065 int16_t lenEncodedLBBytes; | 1065 int16_t lenEncodedLBBytes; |
1066 int16_t validChecksum = 1; | 1066 int16_t validChecksum = 1; |
1067 int16_t k; | 1067 int16_t k; |
1068 uint16_t numLayer; | 1068 uint16_t numLayer; |
1069 int16_t totSizeBytes; | 1069 int16_t totSizeBytes; |
1070 int16_t err; | 1070 int16_t err; |
1071 | 1071 |
1072 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 1072 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
1073 ISACUBDecStruct* decInstUB = &(instISAC->instUB.ISACdecUB_obj); | 1073 ISACUBDecStruct* decInstUB = &(instISAC->instUB.ISACdecUB_obj); |
1074 ISACLBDecStruct* decInstLB = &(instISAC->instLB.ISACdecLB_obj); | 1074 ISACLBDecStruct* decInstLB = &(instISAC->instLB.ISACdecLB_obj); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 * - encoded : encoded ISAC frame(s) | 1343 * - encoded : encoded ISAC frame(s) |
1344 * - len : bytes in encoded vector | 1344 * - len : bytes in encoded vector |
1345 * | 1345 * |
1346 * Output: | 1346 * Output: |
1347 * - decoded : The decoded vector | 1347 * - decoded : The decoded vector |
1348 * | 1348 * |
1349 * Return value : >0 - number of samples in decoded vector | 1349 * Return value : >0 - number of samples in decoded vector |
1350 * -1 - Error | 1350 * -1 - Error |
1351 */ | 1351 */ |
1352 | 1352 |
1353 int WebRtcIsac_Decode(ISACStruct* ISAC_main_inst, | 1353 int16_t WebRtcIsac_Decode(ISACStruct* ISAC_main_inst, |
1354 const uint8_t* encoded, | 1354 const uint8_t* encoded, |
1355 int16_t lenEncodedBytes, | 1355 int16_t lenEncodedBytes, |
1356 int16_t* decoded, | 1356 int16_t* decoded, |
1357 int16_t* speechType) { | 1357 int16_t* speechType) { |
1358 int16_t isRCUPayload = 0; | 1358 int16_t isRCUPayload = 0; |
1359 return Decode(ISAC_main_inst, encoded, lenEncodedBytes, decoded, | 1359 return Decode(ISAC_main_inst, encoded, lenEncodedBytes, decoded, |
1360 speechType, isRCUPayload); | 1360 speechType, isRCUPayload); |
1361 } | 1361 } |
1362 | 1362 |
1363 /**************************************************************************** | 1363 /**************************************************************************** |
1364 * WebRtcIsac_DecodeRcu(...) | 1364 * WebRtcIsac_DecodeRcu(...) |
1365 * | 1365 * |
1366 * This function decodes a redundant (RCU) iSAC frame. Function is called in | 1366 * This function decodes a redundant (RCU) iSAC frame. Function is called in |
1367 * NetEq with a stored RCU payload in case of packet loss. Output speech length | 1367 * NetEq with a stored RCU payload in case of packet loss. Output speech length |
1368 * will be a multiple of 480 samples: 480 or 960 samples, | 1368 * will be a multiple of 480 samples: 480 or 960 samples, |
1369 * depending on the framesize (30 or 60 ms). | 1369 * depending on the framesize (30 or 60 ms). |
1370 * | 1370 * |
1371 * Input: | 1371 * Input: |
1372 * - ISAC_main_inst : ISAC instance. | 1372 * - ISAC_main_inst : ISAC instance. |
1373 * - encoded : encoded ISAC RCU frame(s) | 1373 * - encoded : encoded ISAC RCU frame(s) |
1374 * - len : bytes in encoded vector | 1374 * - len : bytes in encoded vector |
1375 * | 1375 * |
1376 * Output: | 1376 * Output: |
1377 * - decoded : The decoded vector | 1377 * - decoded : The decoded vector |
1378 * | 1378 * |
1379 * Return value : >0 - number of samples in decoded vector | 1379 * Return value : >0 - number of samples in decoded vector |
1380 * -1 - Error | 1380 * -1 - Error |
1381 */ | 1381 */ |
1382 | 1382 |
1383 | 1383 |
1384 | 1384 |
1385 int WebRtcIsac_DecodeRcu(ISACStruct* ISAC_main_inst, | 1385 int16_t WebRtcIsac_DecodeRcu(ISACStruct* ISAC_main_inst, |
1386 const uint8_t* encoded, | 1386 const uint8_t* encoded, |
1387 int16_t lenEncodedBytes, | 1387 int16_t lenEncodedBytes, |
1388 int16_t* decoded, | 1388 int16_t* decoded, |
1389 int16_t* speechType) { | 1389 int16_t* speechType) { |
1390 int16_t isRCUPayload = 1; | 1390 int16_t isRCUPayload = 1; |
1391 return Decode(ISAC_main_inst, encoded, lenEncodedBytes, decoded, | 1391 return Decode(ISAC_main_inst, encoded, lenEncodedBytes, decoded, |
1392 speechType, isRCUPayload); | 1392 speechType, isRCUPayload); |
1393 } | 1393 } |
1394 | 1394 |
1395 | 1395 |
1396 /**************************************************************************** | 1396 /**************************************************************************** |
1397 * WebRtcIsac_DecodePlc(...) | 1397 * WebRtcIsac_DecodePlc(...) |
1398 * | 1398 * |
1399 * This function conducts PLC for ISAC frame(s). Output speech length | 1399 * This function conducts PLC for ISAC frame(s). Output speech length |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 if ((rate >= 10000) && (rate <= 32000)) { | 1478 if ((rate >= 10000) && (rate <= 32000)) { |
1479 instISAC->ISACencUB_obj.bottleneck = rate; | 1479 instISAC->ISACencUB_obj.bottleneck = rate; |
1480 } else { | 1480 } else { |
1481 return -ISAC_DISALLOWED_BOTTLENECK; | 1481 return -ISAC_DISALLOWED_BOTTLENECK; |
1482 } | 1482 } |
1483 return 0; | 1483 return 0; |
1484 } | 1484 } |
1485 | 1485 |
1486 int16_t WebRtcIsac_Control(ISACStruct* ISAC_main_inst, | 1486 int16_t WebRtcIsac_Control(ISACStruct* ISAC_main_inst, |
1487 int32_t bottleneckBPS, | 1487 int32_t bottleneckBPS, |
1488 int frameSize) { | 1488 int16_t frameSize) { |
1489 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 1489 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
1490 int16_t status; | 1490 int16_t status; |
1491 double rateLB; | 1491 double rateLB; |
1492 double rateUB; | 1492 double rateUB; |
1493 enum ISACBandwidth bandwidthKHz; | 1493 enum ISACBandwidth bandwidthKHz; |
1494 | 1494 |
1495 if (instISAC->codingMode == 0) { | 1495 if (instISAC->codingMode == 0) { |
1496 /* In adaptive mode. */ | 1496 /* In adaptive mode. */ |
1497 instISAC->errorCode = ISAC_MODE_MISMATCH; | 1497 instISAC->errorCode = ISAC_MODE_MISMATCH; |
1498 return -1; | 1498 return -1; |
(...skipping 20 matching lines...) Expand all Loading... |
1519 } | 1519 } |
1520 | 1520 |
1521 if ((instISAC->encoderSamplingRateKHz == kIsacSuperWideband) && | 1521 if ((instISAC->encoderSamplingRateKHz == kIsacSuperWideband) && |
1522 (frameSize != 30) && | 1522 (frameSize != 30) && |
1523 (bandwidthKHz != isac8kHz)) { | 1523 (bandwidthKHz != isac8kHz)) { |
1524 /* Cannot have 60 ms in super-wideband. */ | 1524 /* Cannot have 60 ms in super-wideband. */ |
1525 instISAC->errorCode = ISAC_DISALLOWED_FRAME_LENGTH; | 1525 instISAC->errorCode = ISAC_DISALLOWED_FRAME_LENGTH; |
1526 return -1; | 1526 return -1; |
1527 } | 1527 } |
1528 | 1528 |
1529 status = ControlLb(&instISAC->instLB, rateLB, (int16_t)frameSize); | 1529 status = ControlLb(&instISAC->instLB, rateLB, frameSize); |
1530 if (status < 0) { | 1530 if (status < 0) { |
1531 instISAC->errorCode = -status; | 1531 instISAC->errorCode = -status; |
1532 return -1; | 1532 return -1; |
1533 } | 1533 } |
1534 if (bandwidthKHz != isac8kHz) { | 1534 if (bandwidthKHz != isac8kHz) { |
1535 status = ControlUb(&(instISAC->instUB), rateUB); | 1535 status = ControlUb(&(instISAC->instUB), rateUB); |
1536 if (status < 0) { | 1536 if (status < 0) { |
1537 instISAC->errorCode = -status; | 1537 instISAC->errorCode = -status; |
1538 return -1; | 1538 return -1; |
1539 } | 1539 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 * - frameSizeMs : number of milliseconds per frame (30 or 60) | 1587 * - frameSizeMs : number of milliseconds per frame (30 or 60) |
1588 * - enforceFrameSize : 1 to enforce the given frame-size through out | 1588 * - enforceFrameSize : 1 to enforce the given frame-size through out |
1589 * the adaptation process, 0 to let iSAC change | 1589 * the adaptation process, 0 to let iSAC change |
1590 * the frame-size if required. | 1590 * the frame-size if required. |
1591 * | 1591 * |
1592 * Return value : 0 - ok | 1592 * Return value : 0 - ok |
1593 * -1 - Error | 1593 * -1 - Error |
1594 */ | 1594 */ |
1595 int16_t WebRtcIsac_ControlBwe(ISACStruct* ISAC_main_inst, | 1595 int16_t WebRtcIsac_ControlBwe(ISACStruct* ISAC_main_inst, |
1596 int32_t bottleneckBPS, | 1596 int32_t bottleneckBPS, |
1597 int frameSizeMs, | 1597 int16_t frameSizeMs, |
1598 int16_t enforceFrameSize) { | 1598 int16_t enforceFrameSize) { |
1599 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 1599 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
1600 enum ISACBandwidth bandwidth; | 1600 enum ISACBandwidth bandwidth; |
1601 | 1601 |
1602 /* Check if encoder initiated */ | 1602 /* Check if encoder initiated */ |
1603 if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != | 1603 if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != |
1604 BIT_MASK_ENC_INIT) { | 1604 BIT_MASK_ENC_INIT) { |
1605 instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; | 1605 instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; |
1606 return -1; | 1606 return -1; |
1607 } | 1607 } |
(...skipping 26 matching lines...) Expand all Loading... |
1634 return -1; | 1634 return -1; |
1635 } | 1635 } |
1636 instISAC->bwestimator_obj.send_bw_avg = (float)bottleneckBPS; | 1636 instISAC->bwestimator_obj.send_bw_avg = (float)bottleneckBPS; |
1637 instISAC->bandwidthKHz = bandwidth; | 1637 instISAC->bandwidthKHz = bandwidth; |
1638 } | 1638 } |
1639 | 1639 |
1640 /* Set the initial frame-size. If 'enforceFrameSize' is set, the frame-size | 1640 /* Set the initial frame-size. If 'enforceFrameSize' is set, the frame-size |
1641 * will not change */ | 1641 * will not change */ |
1642 if (frameSizeMs != 0) { | 1642 if (frameSizeMs != 0) { |
1643 if ((frameSizeMs == 30) || (frameSizeMs == 60)) { | 1643 if ((frameSizeMs == 30) || (frameSizeMs == 60)) { |
1644 instISAC->instLB.ISACencLB_obj.new_framelength = | 1644 instISAC->instLB.ISACencLB_obj.new_framelength = (FS / 1000) * |
1645 (int16_t)((FS / 1000) * frameSizeMs); | 1645 frameSizeMs; |
1646 } else { | 1646 } else { |
1647 instISAC->errorCode = ISAC_DISALLOWED_FRAME_LENGTH; | 1647 instISAC->errorCode = ISAC_DISALLOWED_FRAME_LENGTH; |
1648 return -1; | 1648 return -1; |
1649 } | 1649 } |
1650 } | 1650 } |
1651 return 0; | 1651 return 0; |
1652 } | 1652 } |
1653 | 1653 |
1654 | 1654 |
1655 /**************************************************************************** | 1655 /**************************************************************************** |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2368 * - ISAC_main_inst : iSAC instance | 2368 * - ISAC_main_inst : iSAC instance |
2369 * | 2369 * |
2370 * Return value : sampling rate in Hertz. Decoder output is | 2370 * Return value : sampling rate in Hertz. Decoder output is |
2371 * sampled at this rate. | 2371 * sampled at this rate. |
2372 * | 2372 * |
2373 */ | 2373 */ |
2374 uint16_t WebRtcIsac_DecSampRate(ISACStruct* ISAC_main_inst) { | 2374 uint16_t WebRtcIsac_DecSampRate(ISACStruct* ISAC_main_inst) { |
2375 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 2375 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
2376 return instISAC->decoderSamplingRateKHz == kIsacWideband ? 16000 : 32000; | 2376 return instISAC->decoderSamplingRateKHz == kIsacWideband ? 16000 : 32000; |
2377 } | 2377 } |
OLD | NEW |