| 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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 */ | 500 */ |
| 501 int WebRtcIsac_Encode(ISACStruct* ISAC_main_inst, | 501 int WebRtcIsac_Encode(ISACStruct* ISAC_main_inst, |
| 502 const int16_t* speechIn, | 502 const int16_t* speechIn, |
| 503 uint8_t* encoded) { | 503 uint8_t* encoded) { |
| 504 float inFrame[FRAMESAMPLES_10ms]; | 504 float inFrame[FRAMESAMPLES_10ms]; |
| 505 int16_t speechInLB[FRAMESAMPLES_10ms]; | 505 int16_t speechInLB[FRAMESAMPLES_10ms]; |
| 506 int16_t speechInUB[FRAMESAMPLES_10ms]; | 506 int16_t speechInUB[FRAMESAMPLES_10ms]; |
| 507 int streamLenLB = 0; | 507 int streamLenLB = 0; |
| 508 int streamLenUB = 0; | 508 int streamLenUB = 0; |
| 509 int streamLen = 0; | 509 int streamLen = 0; |
| 510 int16_t k = 0; | 510 size_t k = 0; |
| 511 uint8_t garbageLen = 0; | 511 uint8_t garbageLen = 0; |
| 512 int32_t bottleneck = 0; | 512 int32_t bottleneck = 0; |
| 513 int16_t bottleneckIdx = 0; | 513 int16_t bottleneckIdx = 0; |
| 514 int16_t jitterInfo = 0; | 514 int16_t jitterInfo = 0; |
| 515 | 515 |
| 516 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 516 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
| 517 ISACLBStruct* instLB = &(instISAC->instLB); | 517 ISACLBStruct* instLB = &(instISAC->instLB); |
| 518 ISACUBStruct* instUB = &(instISAC->instUB); | 518 ISACUBStruct* instUB = &(instISAC->instUB); |
| 519 const int16_t* speech_in_ptr = speechIn; | 519 const int16_t* speech_in_ptr = speechIn; |
| 520 int16_t resampled_buff[FRAMESAMPLES_10ms * 2]; | 520 int16_t resampled_buff[FRAMESAMPLES_10ms * 2]; |
| 521 | 521 |
| 522 /* Check if encoder initiated. */ | 522 /* Check if encoder initiated. */ |
| 523 if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != | 523 if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != |
| 524 BIT_MASK_ENC_INIT) { | 524 BIT_MASK_ENC_INIT) { |
| 525 instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; | 525 instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; |
| 526 return -1; | 526 return -1; |
| 527 } | 527 } |
| 528 | 528 |
| 529 if (instISAC->in_sample_rate_hz == 48000) { | 529 if (instISAC->in_sample_rate_hz == 48000) { |
| 530 /* Samples in 10 ms @ 48 kHz. */ | 530 /* Samples in 10 ms @ 48 kHz. */ |
| 531 const int kNumInputSamples = FRAMESAMPLES_10ms * 3; | 531 const size_t kNumInputSamples = FRAMESAMPLES_10ms * 3; |
| 532 /* Samples 10 ms @ 32 kHz. */ | 532 /* Samples 10 ms @ 32 kHz. */ |
| 533 const int kNumOutputSamples = FRAMESAMPLES_10ms * 2; | 533 const size_t kNumOutputSamples = FRAMESAMPLES_10ms * 2; |
| 534 /* Resampler divide the input into blocks of 3 samples, i.e. | 534 /* Resampler divide the input into blocks of 3 samples, i.e. |
| 535 * kNumInputSamples / 3. */ | 535 * kNumInputSamples / 3. */ |
| 536 const int kNumResamplerBlocks = FRAMESAMPLES_10ms; | 536 const size_t kNumResamplerBlocks = FRAMESAMPLES_10ms; |
| 537 int32_t buffer32[FRAMESAMPLES_10ms * 3 + SIZE_RESAMPLER_STATE]; | 537 int32_t buffer32[FRAMESAMPLES_10ms * 3 + SIZE_RESAMPLER_STATE]; |
| 538 | 538 |
| 539 /* Restore last samples from the past to the beginning of the buffer | 539 /* Restore last samples from the past to the beginning of the buffer |
| 540 * and store the last samples of current frame for the next resampling. */ | 540 * and store the last samples of current frame for the next resampling. */ |
| 541 for (k = 0; k < SIZE_RESAMPLER_STATE; k++) { | 541 for (k = 0; k < SIZE_RESAMPLER_STATE; k++) { |
| 542 buffer32[k] = instISAC->state_in_resampler[k]; | 542 buffer32[k] = instISAC->state_in_resampler[k]; |
| 543 instISAC->state_in_resampler[k] = speechIn[kNumInputSamples - | 543 instISAC->state_in_resampler[k] = speechIn[kNumInputSamples - |
| 544 SIZE_RESAMPLER_STATE + k]; | 544 SIZE_RESAMPLER_STATE + k]; |
| 545 } | 545 } |
| 546 for (k = 0; k < kNumInputSamples; k++) { | 546 for (k = 0; k < kNumInputSamples; k++) { |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 * - packet_size : size of the packet. | 999 * - packet_size : size of the packet. |
| 1000 * - rtp_seq_number : the RTP number of the packet. | 1000 * - rtp_seq_number : the RTP number of the packet. |
| 1001 * - arr_ts : the arrival time of the packet (from NetEq) | 1001 * - arr_ts : the arrival time of the packet (from NetEq) |
| 1002 * in samples. | 1002 * in samples. |
| 1003 * | 1003 * |
| 1004 * Return value : 0 - Ok | 1004 * Return value : 0 - Ok |
| 1005 * -1 - Error | 1005 * -1 - Error |
| 1006 */ | 1006 */ |
| 1007 int16_t WebRtcIsac_UpdateBwEstimate(ISACStruct* ISAC_main_inst, | 1007 int16_t WebRtcIsac_UpdateBwEstimate(ISACStruct* ISAC_main_inst, |
| 1008 const uint8_t* encoded, | 1008 const uint8_t* encoded, |
| 1009 int32_t packet_size, | 1009 size_t packet_size, |
| 1010 uint16_t rtp_seq_number, | 1010 uint16_t rtp_seq_number, |
| 1011 uint32_t send_ts, | 1011 uint32_t send_ts, |
| 1012 uint32_t arr_ts) { | 1012 uint32_t arr_ts) { |
| 1013 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 1013 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
| 1014 Bitstr streamdata; | 1014 Bitstr streamdata; |
| 1015 #ifndef WEBRTC_ARCH_BIG_ENDIAN | 1015 #ifndef WEBRTC_ARCH_BIG_ENDIAN |
| 1016 int k; | 1016 int k; |
| 1017 #endif | 1017 #endif |
| 1018 int16_t err; | 1018 int16_t err; |
| 1019 | 1019 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1049 if (err < 0) { | 1049 if (err < 0) { |
| 1050 /* Return error code if something went wrong. */ | 1050 /* Return error code if something went wrong. */ |
| 1051 instISAC->errorCode = -err; | 1051 instISAC->errorCode = -err; |
| 1052 return -1; | 1052 return -1; |
| 1053 } | 1053 } |
| 1054 return 0; | 1054 return 0; |
| 1055 } | 1055 } |
| 1056 | 1056 |
| 1057 static int Decode(ISACStruct* ISAC_main_inst, | 1057 static int Decode(ISACStruct* ISAC_main_inst, |
| 1058 const uint8_t* encoded, | 1058 const uint8_t* encoded, |
| 1059 int16_t lenEncodedBytes, | 1059 size_t lenEncodedBytes, |
| 1060 int16_t* decoded, | 1060 int16_t* decoded, |
| 1061 int16_t* speechType, | 1061 int16_t* speechType, |
| 1062 int16_t isRCUPayload) { | 1062 int16_t isRCUPayload) { |
| 1063 /* Number of samples (480 or 960), output from decoder | 1063 /* Number of samples (480 or 960), output from decoder |
| 1064 that were actually used in the encoder/decoder | 1064 that were actually used in the encoder/decoder |
| 1065 (determined on the fly). */ | 1065 (determined on the fly). */ |
| 1066 int16_t numSamplesLB; | 1066 int16_t numSamplesLB; |
| 1067 int16_t numSamplesUB; | 1067 int16_t numSamplesUB; |
| 1068 int16_t speechIdx; | 1068 int16_t speechIdx; |
| 1069 float outFrame[MAX_FRAMESAMPLES]; | 1069 float outFrame[MAX_FRAMESAMPLES]; |
| 1070 int16_t outFrameLB[MAX_FRAMESAMPLES]; | 1070 int16_t outFrameLB[MAX_FRAMESAMPLES]; |
| 1071 int16_t outFrameUB[MAX_FRAMESAMPLES]; | 1071 int16_t outFrameUB[MAX_FRAMESAMPLES]; |
| 1072 int numDecodedBytesLB; | 1072 int numDecodedBytesLBint; |
| 1073 size_t numDecodedBytesLB; |
| 1073 int numDecodedBytesUB; | 1074 int numDecodedBytesUB; |
| 1074 int16_t lenEncodedLBBytes; | 1075 size_t lenEncodedLBBytes; |
| 1075 int16_t validChecksum = 1; | 1076 int16_t validChecksum = 1; |
| 1076 int16_t k; | 1077 int16_t k; |
| 1077 uint16_t numLayer; | 1078 uint16_t numLayer; |
| 1078 int16_t totSizeBytes; | 1079 size_t totSizeBytes; |
| 1079 int16_t err; | 1080 int16_t err; |
| 1080 | 1081 |
| 1081 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 1082 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
| 1082 ISACUBDecStruct* decInstUB = &(instISAC->instUB.ISACdecUB_obj); | 1083 ISACUBDecStruct* decInstUB = &(instISAC->instUB.ISACdecUB_obj); |
| 1083 ISACLBDecStruct* decInstLB = &(instISAC->instLB.ISACdecLB_obj); | 1084 ISACLBDecStruct* decInstLB = &(instISAC->instLB.ISACdecLB_obj); |
| 1084 | 1085 |
| 1085 /* Check if decoder initiated. */ | 1086 /* Check if decoder initiated. */ |
| 1086 if ((instISAC->initFlag & BIT_MASK_DEC_INIT) != | 1087 if ((instISAC->initFlag & BIT_MASK_DEC_INIT) != |
| 1087 BIT_MASK_DEC_INIT) { | 1088 BIT_MASK_DEC_INIT) { |
| 1088 instISAC->errorCode = ISAC_DECODER_NOT_INITIATED; | 1089 instISAC->errorCode = ISAC_DECODER_NOT_INITIATED; |
| 1089 return -1; | 1090 return -1; |
| 1090 } | 1091 } |
| 1091 | 1092 |
| 1092 if (lenEncodedBytes <= 0) { | 1093 if (lenEncodedBytes == 0) { |
| 1093 /* return error code if the packet length is null. */ | 1094 /* return error code if the packet length is null. */ |
| 1094 instISAC->errorCode = ISAC_EMPTY_PACKET; | 1095 instISAC->errorCode = ISAC_EMPTY_PACKET; |
| 1095 return -1; | 1096 return -1; |
| 1096 } | 1097 } |
| 1097 | 1098 |
| 1098 /* The size of the encoded lower-band is bounded by | 1099 /* The size of the encoded lower-band is bounded by |
| 1099 * STREAM_SIZE_MAX. If a payload with the size larger than STREAM_SIZE_MAX | 1100 * STREAM_SIZE_MAX. If a payload with the size larger than STREAM_SIZE_MAX |
| 1100 * is received, it is not considered erroneous. */ | 1101 * is received, it is not considered erroneous. */ |
| 1101 lenEncodedLBBytes = (lenEncodedBytes > STREAM_SIZE_MAX) ? | 1102 lenEncodedLBBytes = (lenEncodedBytes > STREAM_SIZE_MAX) ? |
| 1102 STREAM_SIZE_MAX : lenEncodedBytes; | 1103 STREAM_SIZE_MAX : lenEncodedBytes; |
| 1103 | 1104 |
| 1104 /* Copy to lower-band bit-stream structure. */ | 1105 /* Copy to lower-band bit-stream structure. */ |
| 1105 memcpy(instISAC->instLB.ISACdecLB_obj.bitstr_obj.stream, encoded, | 1106 memcpy(instISAC->instLB.ISACdecLB_obj.bitstr_obj.stream, encoded, |
| 1106 lenEncodedLBBytes); | 1107 lenEncodedLBBytes); |
| 1107 | 1108 |
| 1108 /* We need to initialize numSamplesLB to something; otherwise, in the test | 1109 /* We need to initialize numSamplesLB to something; otherwise, in the test |
| 1109 for whether we should return -1 below, the compiler might generate code | 1110 for whether we should return -1 below, the compiler might generate code |
| 1110 that fools Memcheck (Valgrind) into thinking that the control flow depends | 1111 that fools Memcheck (Valgrind) into thinking that the control flow depends |
| 1111 on the uninitialized value in numSamplesLB (since WebRtcIsac_DecodeLb will | 1112 on the uninitialized value in numSamplesLB (since WebRtcIsac_DecodeLb will |
| 1112 not fill it in if it fails and returns -1). */ | 1113 not fill it in if it fails and returns -1). */ |
| 1113 numSamplesLB = 0; | 1114 numSamplesLB = 0; |
| 1114 | 1115 |
| 1115 /* Regardless of that the current codec is setup to work in | 1116 /* Regardless of that the current codec is setup to work in |
| 1116 * wideband or super-wideband, the decoding of the lower-band | 1117 * wideband or super-wideband, the decoding of the lower-band |
| 1117 * has to be performed. */ | 1118 * has to be performed. */ |
| 1118 numDecodedBytesLB = WebRtcIsac_DecodeLb(&instISAC->transform_tables, | 1119 numDecodedBytesLBint = WebRtcIsac_DecodeLb(&instISAC->transform_tables, |
| 1119 outFrame, decInstLB, | 1120 outFrame, decInstLB, |
| 1120 &numSamplesLB, isRCUPayload); | 1121 &numSamplesLB, isRCUPayload); |
| 1121 | 1122 numDecodedBytesLB = (size_t)numDecodedBytesLBint; |
| 1122 if ((numDecodedBytesLB < 0) || (numDecodedBytesLB > lenEncodedLBBytes) || | 1123 if ((numDecodedBytesLBint < 0) || |
| 1124 (numDecodedBytesLB > lenEncodedLBBytes) || |
| 1123 (numSamplesLB > MAX_FRAMESAMPLES)) { | 1125 (numSamplesLB > MAX_FRAMESAMPLES)) { |
| 1124 instISAC->errorCode = ISAC_LENGTH_MISMATCH; | 1126 instISAC->errorCode = ISAC_LENGTH_MISMATCH; |
| 1125 return -1; | 1127 return -1; |
| 1126 } | 1128 } |
| 1127 | 1129 |
| 1128 /* Error Check, we accept multi-layer bit-stream This will limit number | 1130 /* Error Check, we accept multi-layer bit-stream This will limit number |
| 1129 * of iterations of the while loop. Even without this the number | 1131 * of iterations of the while loop. Even without this the number |
| 1130 * of iterations is limited. */ | 1132 * of iterations is limited. */ |
| 1131 numLayer = 1; | 1133 numLayer = 1; |
| 1132 totSizeBytes = numDecodedBytesLB; | 1134 totSizeBytes = numDecodedBytesLB; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 * | 1357 * |
| 1356 * Output: | 1358 * Output: |
| 1357 * - decoded : The decoded vector | 1359 * - decoded : The decoded vector |
| 1358 * | 1360 * |
| 1359 * Return value : >0 - number of samples in decoded vector | 1361 * Return value : >0 - number of samples in decoded vector |
| 1360 * -1 - Error | 1362 * -1 - Error |
| 1361 */ | 1363 */ |
| 1362 | 1364 |
| 1363 int WebRtcIsac_Decode(ISACStruct* ISAC_main_inst, | 1365 int WebRtcIsac_Decode(ISACStruct* ISAC_main_inst, |
| 1364 const uint8_t* encoded, | 1366 const uint8_t* encoded, |
| 1365 int16_t lenEncodedBytes, | 1367 size_t lenEncodedBytes, |
| 1366 int16_t* decoded, | 1368 int16_t* decoded, |
| 1367 int16_t* speechType) { | 1369 int16_t* speechType) { |
| 1368 int16_t isRCUPayload = 0; | 1370 int16_t isRCUPayload = 0; |
| 1369 return Decode(ISAC_main_inst, encoded, lenEncodedBytes, decoded, | 1371 return Decode(ISAC_main_inst, encoded, lenEncodedBytes, decoded, |
| 1370 speechType, isRCUPayload); | 1372 speechType, isRCUPayload); |
| 1371 } | 1373 } |
| 1372 | 1374 |
| 1373 /**************************************************************************** | 1375 /**************************************************************************** |
| 1374 * WebRtcIsac_DecodeRcu(...) | 1376 * WebRtcIsac_DecodeRcu(...) |
| 1375 * | 1377 * |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1387 * - decoded : The decoded vector | 1389 * - decoded : The decoded vector |
| 1388 * | 1390 * |
| 1389 * Return value : >0 - number of samples in decoded vector | 1391 * Return value : >0 - number of samples in decoded vector |
| 1390 * -1 - Error | 1392 * -1 - Error |
| 1391 */ | 1393 */ |
| 1392 | 1394 |
| 1393 | 1395 |
| 1394 | 1396 |
| 1395 int WebRtcIsac_DecodeRcu(ISACStruct* ISAC_main_inst, | 1397 int WebRtcIsac_DecodeRcu(ISACStruct* ISAC_main_inst, |
| 1396 const uint8_t* encoded, | 1398 const uint8_t* encoded, |
| 1397 int16_t lenEncodedBytes, | 1399 size_t lenEncodedBytes, |
| 1398 int16_t* decoded, | 1400 int16_t* decoded, |
| 1399 int16_t* speechType) { | 1401 int16_t* speechType) { |
| 1400 int16_t isRCUPayload = 1; | 1402 int16_t isRCUPayload = 1; |
| 1401 return Decode(ISAC_main_inst, encoded, lenEncodedBytes, decoded, | 1403 return Decode(ISAC_main_inst, encoded, lenEncodedBytes, decoded, |
| 1402 speechType, isRCUPayload); | 1404 speechType, isRCUPayload); |
| 1403 } | 1405 } |
| 1404 | 1406 |
| 1405 | 1407 |
| 1406 /**************************************************************************** | 1408 /**************************************************************************** |
| 1407 * WebRtcIsac_DecodePlc(...) | 1409 * WebRtcIsac_DecodePlc(...) |
| 1408 * | 1410 * |
| 1409 * This function conducts PLC for ISAC frame(s). Output speech length | 1411 * This function conducts PLC for ISAC frame(s). Output speech length |
| 1410 * will be a multiple of 480 samples: 480 or 960 samples, | 1412 * will be a multiple of 480 samples: 480 or 960 samples, |
| 1411 * depending on the frameSize (30 or 60 ms). | 1413 * depending on the frameSize (30 or 60 ms). |
| 1412 * | 1414 * |
| 1413 * Input: | 1415 * Input: |
| 1414 * - ISAC_main_inst : ISAC instance. | 1416 * - ISAC_main_inst : ISAC instance. |
| 1415 * - noOfLostFrames : Number of PLC frames to produce | 1417 * - noOfLostFrames : Number of PLC frames to produce |
| 1416 * | 1418 * |
| 1417 * Output: | 1419 * Output: |
| 1418 * - decoded : The decoded vector | 1420 * - decoded : The decoded vector |
| 1419 * | 1421 * |
| 1420 * Return value : >0 - number of samples in decoded PLC vector | 1422 * Return value : Number of samples in decoded PLC vector |
| 1421 * -1 - Error | |
| 1422 */ | 1423 */ |
| 1423 int16_t WebRtcIsac_DecodePlc(ISACStruct* ISAC_main_inst, | 1424 size_t WebRtcIsac_DecodePlc(ISACStruct* ISAC_main_inst, |
| 1424 int16_t* decoded, | 1425 int16_t* decoded, |
| 1425 int16_t noOfLostFrames) { | 1426 size_t noOfLostFrames) { |
| 1426 int16_t numSamples = 0; | 1427 size_t numSamples = 0; |
| 1427 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 1428 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
| 1428 | 1429 |
| 1429 /* Limit number of frames to two = 60 millisecond. | 1430 /* Limit number of frames to two = 60 millisecond. |
| 1430 * Otherwise we exceed data vectors. */ | 1431 * Otherwise we exceed data vectors. */ |
| 1431 if (noOfLostFrames > 2) { | 1432 if (noOfLostFrames > 2) { |
| 1432 noOfLostFrames = 2; | 1433 noOfLostFrames = 2; |
| 1433 } | 1434 } |
| 1434 | 1435 |
| 1435 /* Get the number of samples per frame */ | 1436 /* Get the number of samples per frame */ |
| 1436 switch (instISAC->decoderSamplingRateKHz) { | 1437 switch (instISAC->decoderSamplingRateKHz) { |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2409 } | 2410 } |
| 2410 | 2411 |
| 2411 void WebRtcIsac_SetEncSampRateInDecoder(ISACStruct* inst, | 2412 void WebRtcIsac_SetEncSampRateInDecoder(ISACStruct* inst, |
| 2412 int sample_rate_hz) { | 2413 int sample_rate_hz) { |
| 2413 ISACMainStruct* instISAC = (ISACMainStruct*)inst; | 2414 ISACMainStruct* instISAC = (ISACMainStruct*)inst; |
| 2414 assert(instISAC->initFlag & BIT_MASK_DEC_INIT); | 2415 assert(instISAC->initFlag & BIT_MASK_DEC_INIT); |
| 2415 assert(!(instISAC->initFlag & BIT_MASK_ENC_INIT)); | 2416 assert(!(instISAC->initFlag & BIT_MASK_ENC_INIT)); |
| 2416 assert(sample_rate_hz == 16000 || sample_rate_hz == 32000); | 2417 assert(sample_rate_hz == 16000 || sample_rate_hz == 32000); |
| 2417 instISAC->encoderSamplingRateKHz = sample_rate_hz / 1000; | 2418 instISAC->encoderSamplingRateKHz = sample_rate_hz / 1000; |
| 2418 } | 2419 } |
| OLD | NEW |