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 |
11 /* | 11 /* |
12 * isac.c | 12 * isac.c |
13 * | 13 * |
14 * This C file contains the functions for the ISAC API | 14 * This C file contains the functions for the ISAC API |
15 * | 15 * |
16 */ | 16 */ |
17 | 17 |
18 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h" | 18 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h" |
19 | 19 |
| 20 #include <assert.h> |
20 #include <math.h> | 21 #include <math.h> |
21 #include <stdio.h> | 22 #include <stdio.h> |
22 #include <stdlib.h> | 23 #include <stdlib.h> |
23 #include <string.h> | 24 #include <string.h> |
24 | 25 |
25 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 26 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
26 #include "webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimato
r.h" | 27 #include "webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimato
r.h" |
27 #include "webrtc/modules/audio_coding/codecs/isac/main/source/codec.h" | 28 #include "webrtc/modules/audio_coding/codecs/isac/main/source/codec.h" |
28 #include "webrtc/modules/audio_coding/codecs/isac/main/source/crc.h" | 29 #include "webrtc/modules/audio_coding/codecs/isac/main/source/crc.h" |
29 #include "webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.h" | 30 #include "webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 * updated just right before the first 10ms of a frame is pushed into encoder. | 107 * updated just right before the first 10ms of a frame is pushed into encoder. |
107 * | 108 * |
108 */ | 109 */ |
109 static void UpdateBottleneck(ISACMainStruct* instISAC) { | 110 static void UpdateBottleneck(ISACMainStruct* instISAC) { |
110 /* Read the bottleneck from bandwidth estimator for the | 111 /* Read the bottleneck from bandwidth estimator for the |
111 * first 10 ms audio. This way, if there is a change | 112 * first 10 ms audio. This way, if there is a change |
112 * in bandwidth, upper and lower-band will be in sync. */ | 113 * in bandwidth, upper and lower-band will be in sync. */ |
113 if ((instISAC->codingMode == 0) && | 114 if ((instISAC->codingMode == 0) && |
114 (instISAC->instLB.ISACencLB_obj.buffer_index == 0) && | 115 (instISAC->instLB.ISACencLB_obj.buffer_index == 0) && |
115 (instISAC->instLB.ISACencLB_obj.frame_nb == 0)) { | 116 (instISAC->instLB.ISACencLB_obj.frame_nb == 0)) { |
116 int32_t bottleneck; | 117 int32_t bottleneck = |
117 WebRtcIsac_GetUplinkBandwidth(&(instISAC->bwestimator_obj), | 118 WebRtcIsac_GetUplinkBandwidth(&instISAC->bwestimator_obj); |
118 &bottleneck); | |
119 | 119 |
120 /* Adding hysteresis when increasing signal bandwidth. */ | 120 /* Adding hysteresis when increasing signal bandwidth. */ |
121 if ((instISAC->bandwidthKHz == isac8kHz) | 121 if ((instISAC->bandwidthKHz == isac8kHz) |
122 && (bottleneck > 37000) | 122 && (bottleneck > 37000) |
123 && (bottleneck < 41000)) { | 123 && (bottleneck < 41000)) { |
124 bottleneck = 37000; | 124 bottleneck = 37000; |
125 } | 125 } |
126 | 126 |
127 /* Switching from 12 kHz to 16 kHz is not allowed at this revision. | 127 /* Switching from 12 kHz to 16 kHz is not allowed at this revision. |
128 * If we let this happen, we have to take care of buffer_index and | 128 * If we let this happen, we have to take care of buffer_index and |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 } else { | 663 } else { |
664 if (streamLenLB == 0) { | 664 if (streamLenLB == 0) { |
665 return 0; | 665 return 0; |
666 } | 666 } |
667 memcpy(encoded, instLB->ISACencLB_obj.bitstr_obj.stream, streamLenLB); | 667 memcpy(encoded, instLB->ISACencLB_obj.bitstr_obj.stream, streamLenLB); |
668 streamLenUB = 0; | 668 streamLenUB = 0; |
669 streamLen = streamLenLB; | 669 streamLen = streamLenLB; |
670 } | 670 } |
671 | 671 |
672 /* Add Garbage if required. */ | 672 /* Add Garbage if required. */ |
673 WebRtcIsac_GetUplinkBandwidth(&instISAC->bwestimator_obj, &bottleneck); | 673 bottleneck = WebRtcIsac_GetUplinkBandwidth(&instISAC->bwestimator_obj); |
674 if (instISAC->codingMode == 0) { | 674 if (instISAC->codingMode == 0) { |
675 int minBytes; | 675 int minBytes; |
676 int limit; | 676 int limit; |
677 uint8_t* ptrGarbage; | 677 uint8_t* ptrGarbage; |
678 | 678 |
679 instISAC->MaxDelay = (double)WebRtcIsac_GetUplinkMaxDelay( | 679 instISAC->MaxDelay = (double)WebRtcIsac_GetUplinkMaxDelay( |
680 &instISAC->bwestimator_obj); | 680 &instISAC->bwestimator_obj); |
681 | 681 |
682 /* Update rate model and get minimum number of bytes in this packet. */ | 682 /* Update rate model and get minimum number of bytes in this packet. */ |
683 minBytes = WebRtcIsac_GetMinBytes( | 683 minBytes = WebRtcIsac_GetMinBytes( |
(...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 * - ISAC_main_inst : iSAC instance | 2377 * - ISAC_main_inst : iSAC instance |
2378 * | 2378 * |
2379 * Return value : sampling rate in Hertz. Decoder output is | 2379 * Return value : sampling rate in Hertz. Decoder output is |
2380 * sampled at this rate. | 2380 * sampled at this rate. |
2381 * | 2381 * |
2382 */ | 2382 */ |
2383 uint16_t WebRtcIsac_DecSampRate(ISACStruct* ISAC_main_inst) { | 2383 uint16_t WebRtcIsac_DecSampRate(ISACStruct* ISAC_main_inst) { |
2384 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | 2384 ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; |
2385 return instISAC->decoderSamplingRateKHz == kIsacWideband ? 16000 : 32000; | 2385 return instISAC->decoderSamplingRateKHz == kIsacWideband ? 16000 : 32000; |
2386 } | 2386 } |
| 2387 |
| 2388 void WebRtcIsac_GetBandwidthInfo(ISACStruct* inst, |
| 2389 IsacBandwidthInfo* bwinfo) { |
| 2390 ISACMainStruct* instISAC = (ISACMainStruct*)inst; |
| 2391 assert(instISAC->initFlag & BIT_MASK_DEC_INIT); |
| 2392 WebRtcIsacBw_GetBandwidthInfo(&instISAC->bwestimator_obj, |
| 2393 instISAC->decoderSamplingRateKHz, bwinfo); |
| 2394 } |
| 2395 |
| 2396 void WebRtcIsac_SetBandwidthInfo(ISACStruct* inst, |
| 2397 const IsacBandwidthInfo* bwinfo) { |
| 2398 ISACMainStruct* instISAC = (ISACMainStruct*)inst; |
| 2399 assert(instISAC->initFlag & BIT_MASK_ENC_INIT); |
| 2400 WebRtcIsacBw_SetBandwidthInfo(&instISAC->bwestimator_obj, bwinfo); |
| 2401 } |
OLD | NEW |