| 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 memset(instISAC->analysisFBState2, 0, | 462 memset(instISAC->analysisFBState2, 0, |
| 463 FB_STATE_SIZE_WORD32 * sizeof(int32_t)); | 463 FB_STATE_SIZE_WORD32 * sizeof(int32_t)); |
| 464 | 464 |
| 465 status = EncoderInitUb(&(instISAC->instUB), | 465 status = EncoderInitUb(&(instISAC->instUB), |
| 466 instISAC->bandwidthKHz); | 466 instISAC->bandwidthKHz); |
| 467 if (status < 0) { | 467 if (status < 0) { |
| 468 instISAC->errorCode = -status; | 468 instISAC->errorCode = -status; |
| 469 return -1; | 469 return -1; |
| 470 } | 470 } |
| 471 } | 471 } |
| 472 memset(instISAC->state_in_resampler, 0, sizeof(instISAC->state_in_resampler)); | |
| 473 /* Initialization is successful, set the flag. */ | 472 /* Initialization is successful, set the flag. */ |
| 474 instISAC->initFlag |= BIT_MASK_ENC_INIT; | 473 instISAC->initFlag |= BIT_MASK_ENC_INIT; |
| 475 return 0; | 474 return 0; |
| 476 } | 475 } |
| 477 | 476 |
| 478 | 477 |
| 479 /**************************************************************************** | 478 /**************************************************************************** |
| 480 * WebRtcIsac_Encode(...) | 479 * WebRtcIsac_Encode(...) |
| 481 * | 480 * |
| 482 * This function encodes 10ms frame(s) and inserts it into a package. | 481 * This function encodes 10ms frame(s) and inserts it into a package. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 509 int streamLen = 0; | 508 int streamLen = 0; |
| 510 size_t k = 0; | 509 size_t k = 0; |
| 511 uint8_t garbageLen = 0; | 510 uint8_t garbageLen = 0; |
| 512 int32_t bottleneck = 0; | 511 int32_t bottleneck = 0; |
| 513 int16_t bottleneckIdx = 0; | 512 int16_t bottleneckIdx = 0; |
| 514 int16_t jitterInfo = 0; | 513 int16_t jitterInfo = 0; |
| 515 | 514 |
| 516 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 515 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
| 517 ISACLBStruct* instLB = &(instISAC->instLB); | 516 ISACLBStruct* instLB = &(instISAC->instLB); |
| 518 ISACUBStruct* instUB = &(instISAC->instUB); | 517 ISACUBStruct* instUB = &(instISAC->instUB); |
| 519 const int16_t* speech_in_ptr = speechIn; | |
| 520 int16_t resampled_buff[FRAMESAMPLES_10ms * 2]; | |
| 521 | 518 |
| 522 /* Check if encoder initiated. */ | 519 /* Check if encoder initiated. */ |
| 523 if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != | 520 if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != |
| 524 BIT_MASK_ENC_INIT) { | 521 BIT_MASK_ENC_INIT) { |
| 525 instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; | 522 instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; |
| 526 return -1; | 523 return -1; |
| 527 } | 524 } |
| 528 | 525 |
| 529 if (instISAC->in_sample_rate_hz == 48000) { | |
| 530 /* Samples in 10 ms @ 48 kHz. */ | |
| 531 const size_t kNumInputSamples = FRAMESAMPLES_10ms * 3; | |
| 532 /* Samples 10 ms @ 32 kHz. */ | |
| 533 const size_t kNumOutputSamples = FRAMESAMPLES_10ms * 2; | |
| 534 /* Resampler divide the input into blocks of 3 samples, i.e. | |
| 535 * kNumInputSamples / 3. */ | |
| 536 const size_t kNumResamplerBlocks = FRAMESAMPLES_10ms; | |
| 537 int32_t buffer32[FRAMESAMPLES_10ms * 3 + SIZE_RESAMPLER_STATE]; | |
| 538 | |
| 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. */ | |
| 541 for (k = 0; k < SIZE_RESAMPLER_STATE; k++) { | |
| 542 buffer32[k] = instISAC->state_in_resampler[k]; | |
| 543 instISAC->state_in_resampler[k] = speechIn[kNumInputSamples - | |
| 544 SIZE_RESAMPLER_STATE + k]; | |
| 545 } | |
| 546 for (k = 0; k < kNumInputSamples; k++) { | |
| 547 buffer32[SIZE_RESAMPLER_STATE + k] = speechIn[k]; | |
| 548 } | |
| 549 /* Resampling 3 samples to 2. Function divides the input in | |
| 550 * |kNumResamplerBlocks| number of 3-sample groups, and output is | |
| 551 * |kNumResamplerBlocks| number of 2-sample groups. */ | |
| 552 WebRtcSpl_Resample48khzTo32khz(buffer32, buffer32, kNumResamplerBlocks); | |
| 553 WebRtcSpl_VectorBitShiftW32ToW16(resampled_buff, kNumOutputSamples, | |
| 554 buffer32, 15); | |
| 555 speech_in_ptr = resampled_buff; | |
| 556 } | |
| 557 | |
| 558 if (instISAC->encoderSamplingRateKHz == kIsacSuperWideband) { | 526 if (instISAC->encoderSamplingRateKHz == kIsacSuperWideband) { |
| 559 WebRtcSpl_AnalysisQMF(speech_in_ptr, SWBFRAMESAMPLES_10ms, speechInLB, | 527 WebRtcSpl_AnalysisQMF(speechIn, SWBFRAMESAMPLES_10ms, speechInLB, |
| 560 speechInUB, instISAC->analysisFBState1, | 528 speechInUB, instISAC->analysisFBState1, |
| 561 instISAC->analysisFBState2); | 529 instISAC->analysisFBState2); |
| 562 | 530 |
| 563 /* Convert from fixed to floating point. */ | 531 /* Convert from fixed to floating point. */ |
| 564 for (k = 0; k < FRAMESAMPLES_10ms; k++) { | 532 for (k = 0; k < FRAMESAMPLES_10ms; k++) { |
| 565 inFrame[k] = (float)speechInLB[k]; | 533 inFrame[k] = (float)speechInLB[k]; |
| 566 } | 534 } |
| 567 } else { | 535 } else { |
| 568 for (k = 0; k < FRAMESAMPLES_10ms; k++) { | 536 for (k = 0; k < FRAMESAMPLES_10ms; k++) { |
| 569 inFrame[k] = (float) speechIn[k]; | 537 inFrame[k] = (float) speechIn[k]; |
| (...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1845 * | 1813 * |
| 1846 * Return Value : frame lenght in samples | 1814 * Return Value : frame lenght in samples |
| 1847 * | 1815 * |
| 1848 */ | 1816 */ |
| 1849 int16_t WebRtcIsac_GetNewFrameLen(ISACStruct* ISAC_main_inst) { | 1817 int16_t WebRtcIsac_GetNewFrameLen(ISACStruct* ISAC_main_inst) { |
| 1850 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 1818 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
| 1851 | 1819 |
| 1852 /* Return new frame length. */ | 1820 /* Return new frame length. */ |
| 1853 if (instISAC->in_sample_rate_hz == 16000) | 1821 if (instISAC->in_sample_rate_hz == 16000) |
| 1854 return (instISAC->instLB.ISACencLB_obj.new_framelength); | 1822 return (instISAC->instLB.ISACencLB_obj.new_framelength); |
| 1855 else if (instISAC->in_sample_rate_hz == 32000) | 1823 else /* 32000 Hz */ |
| 1856 return ((instISAC->instLB.ISACencLB_obj.new_framelength) * 2); | 1824 return ((instISAC->instLB.ISACencLB_obj.new_framelength) * 2); |
| 1857 else | |
| 1858 return ((instISAC->instLB.ISACencLB_obj.new_framelength) * 3); | |
| 1859 } | 1825 } |
| 1860 | 1826 |
| 1861 | 1827 |
| 1862 /**************************************************************************** | 1828 /**************************************************************************** |
| 1863 * WebRtcIsac_GetErrorCode(...) | 1829 * WebRtcIsac_GetErrorCode(...) |
| 1864 * | 1830 * |
| 1865 * This function can be used to check the error code of an iSAC instance. | 1831 * This function can be used to check the error code of an iSAC instance. |
| 1866 * When a function returns -1 an error code will be set for that instance. | 1832 * When a function returns -1 an error code will be set for that instance. |
| 1867 * The function below extracts the code of the last error that occurred in | 1833 * The function below extracts the code of the last error that occurred in |
| 1868 * the specified instance. | 1834 * the specified instance. |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2198 | 2164 |
| 2199 | 2165 |
| 2200 /****************************************************************************** | 2166 /****************************************************************************** |
| 2201 * WebRtcIsac_SetEncSampRate() | 2167 * WebRtcIsac_SetEncSampRate() |
| 2202 * This function sets the sampling rate of the encoder. Initialization of the | 2168 * This function sets the sampling rate of the encoder. Initialization of the |
| 2203 * encoder WILL NOT overwrite the sampling rate of the encoder. The default | 2169 * encoder WILL NOT overwrite the sampling rate of the encoder. The default |
| 2204 * value is 16 kHz which is set when the instance is created. The encoding-mode | 2170 * value is 16 kHz which is set when the instance is created. The encoding-mode |
| 2205 * and the bottleneck remain unchanged by this call, however, the maximum rate | 2171 * and the bottleneck remain unchanged by this call, however, the maximum rate |
| 2206 * and maximum payload-size will be reset to their default values. | 2172 * and maximum payload-size will be reset to their default values. |
| 2207 * | 2173 * |
| 2208 * NOTE: | |
| 2209 * The maximum internal sampling rate is 32 kHz. If the encoder sample rate is | |
| 2210 * set to 48 kHz the input is expected to be at 48 kHz but will be resampled to | |
| 2211 * 32 kHz before any further processing. | |
| 2212 * This mode is created for compatibility with full-band codecs if iSAC is used | |
| 2213 * in dual-streaming. See SetDecSampleRate() for sampling rates at the decoder. | |
| 2214 * | |
| 2215 * Input: | 2174 * Input: |
| 2216 * - ISAC_main_inst : iSAC instance | 2175 * - ISAC_main_inst : iSAC instance |
| 2217 * - sample_rate_hz : sampling rate in Hertz, valid values are 16000, | 2176 * - sample_rate_hz : sampling rate in Hertz, valid values are 16000 |
| 2218 * 32000 and 48000. | 2177 * and 32000. |
| 2219 * | 2178 * |
| 2220 * Return value : 0 if successful | 2179 * Return value : 0 if successful |
| 2221 * -1 if failed. | 2180 * -1 if failed. |
| 2222 */ | 2181 */ |
| 2223 int16_t WebRtcIsac_SetEncSampRate(ISACStruct* ISAC_main_inst, | 2182 int16_t WebRtcIsac_SetEncSampRate(ISACStruct* ISAC_main_inst, |
| 2224 uint16_t sample_rate_hz) { | 2183 uint16_t sample_rate_hz) { |
| 2225 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 2184 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
| 2226 enum IsacSamplingRate encoder_operational_rate; | 2185 enum IsacSamplingRate encoder_operational_rate; |
| 2227 | 2186 |
| 2228 if ((sample_rate_hz != 16000) && (sample_rate_hz != 32000) && | 2187 if ((sample_rate_hz != 16000) && (sample_rate_hz != 32000)) { |
| 2229 (sample_rate_hz != 48000)) { | |
| 2230 /* Sampling Frequency is not supported. */ | 2188 /* Sampling Frequency is not supported. */ |
| 2231 instISAC->errorCode = ISAC_UNSUPPORTED_SAMPLING_FREQUENCY; | 2189 instISAC->errorCode = ISAC_UNSUPPORTED_SAMPLING_FREQUENCY; |
| 2232 return -1; | 2190 return -1; |
| 2233 } | 2191 } |
| 2234 if (sample_rate_hz == 16000) { | 2192 if (sample_rate_hz == 16000) { |
| 2235 encoder_operational_rate = kIsacWideband; | 2193 encoder_operational_rate = kIsacWideband; |
| 2236 } else { | 2194 } else { |
| 2237 encoder_operational_rate = kIsacSuperWideband; | 2195 encoder_operational_rate = kIsacSuperWideband; |
| 2238 } | 2196 } |
| 2239 | 2197 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2396 } | 2354 } |
| 2397 | 2355 |
| 2398 void WebRtcIsac_SetEncSampRateInDecoder(ISACStruct* inst, | 2356 void WebRtcIsac_SetEncSampRateInDecoder(ISACStruct* inst, |
| 2399 int sample_rate_hz) { | 2357 int sample_rate_hz) { |
| 2400 ISACMainStruct* instISAC = (ISACMainStruct*)inst; | 2358 ISACMainStruct* instISAC = (ISACMainStruct*)inst; |
| 2401 assert(instISAC->initFlag & BIT_MASK_DEC_INIT); | 2359 assert(instISAC->initFlag & BIT_MASK_DEC_INIT); |
| 2402 assert(!(instISAC->initFlag & BIT_MASK_ENC_INIT)); | 2360 assert(!(instISAC->initFlag & BIT_MASK_ENC_INIT)); |
| 2403 assert(sample_rate_hz == 16000 || sample_rate_hz == 32000); | 2361 assert(sample_rate_hz == 16000 || sample_rate_hz == 32000); |
| 2404 instISAC->encoderSamplingRateKHz = sample_rate_hz / 1000; | 2362 instISAC->encoderSamplingRateKHz = sample_rate_hz / 1000; |
| 2405 } | 2363 } |
| OLD | NEW |