2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
14 * This C file contains the functions for the ISAC API
18 #include "modules/audio_coding/codecs/isac/fix/interface/isacfix.h"
22 #include "modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.h"
23 #include "modules/audio_coding/codecs/isac/fix/source/codec.h"
24 #include "modules/audio_coding/codecs/isac/fix/source/entropy_coding.h"
25 #include "modules/audio_coding/codecs/isac/fix/source/filterbank_internal.h"
26 #include "modules/audio_coding/codecs/isac/fix/source/lpc_masking_model.h"
27 #include "modules/audio_coding/codecs/isac/fix/source/structs.h"
28 #include "system_wrappers/interface/cpu_features_wrapper.h"
30 // Declare function pointers.
31 FilterMaLoopFix WebRtcIsacfix_FilterMaLoopFix;
32 Spec2Time WebRtcIsacfix_Spec2Time;
33 Time2Spec WebRtcIsacfix_Time2Spec;
34 MatrixProduct1 WebRtcIsacfix_MatrixProduct1;
35 MatrixProduct2 WebRtcIsacfix_MatrixProduct2;
37 /**************************************************************************
38 * WebRtcIsacfix_AssignSize(...)
40 * Functions used when malloc is not allowed
41 * Returns number of bytes needed to allocate for iSAC struct.
45 int16_t WebRtcIsacfix_AssignSize(int *sizeinbytes) {
46 *sizeinbytes=sizeof(ISACFIX_SubStruct)*2/sizeof(int16_t);
50 /***************************************************************************
51 * WebRtcIsacfix_Assign(...)
53 * Functions used when malloc is not allowed
54 * Place struct at given address
56 * If successful, Return 0, else Return -1
59 int16_t WebRtcIsacfix_Assign(ISACFIX_MainStruct **inst, void *ISACFIX_inst_Addr) {
60 if (ISACFIX_inst_Addr!=NULL) {
61 *inst = (ISACFIX_MainStruct*)ISACFIX_inst_Addr;
62 (*(ISACFIX_SubStruct**)inst)->errorcode = 0;
63 (*(ISACFIX_SubStruct**)inst)->initflag = 0;
64 (*(ISACFIX_SubStruct**)inst)->ISACenc_obj.SaveEnc_ptr = NULL;
72 #ifndef ISACFIX_NO_DYNAMIC_MEM
74 /****************************************************************************
75 * WebRtcIsacfix_Create(...)
77 * This function creates a ISAC instance, which will contain the state
78 * information for one coding/decoding channel.
81 * - *ISAC_main_inst : a pointer to the coder instance.
83 * Return value : 0 - Ok
87 int16_t WebRtcIsacfix_Create(ISACFIX_MainStruct **ISAC_main_inst)
89 ISACFIX_SubStruct *tempo;
90 tempo = malloc(1 * sizeof(ISACFIX_SubStruct));
91 *ISAC_main_inst = (ISACFIX_MainStruct *)tempo;
92 if (*ISAC_main_inst!=NULL) {
93 (*(ISACFIX_SubStruct**)ISAC_main_inst)->errorcode = 0;
94 (*(ISACFIX_SubStruct**)ISAC_main_inst)->initflag = 0;
95 (*(ISACFIX_SubStruct**)ISAC_main_inst)->ISACenc_obj.SaveEnc_ptr = NULL;
104 /****************************************************************************
105 * WebRtcIsacfix_CreateInternal(...)
107 * This function creates the memory that is used to store data in the encoder
110 * - *ISAC_main_inst : a pointer to the coder instance.
112 * Return value : 0 - Ok
116 int16_t WebRtcIsacfix_CreateInternal(ISACFIX_MainStruct *ISAC_main_inst)
118 ISACFIX_SubStruct *ISAC_inst;
120 /* typecast pointer to real structure */
121 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
123 /* Allocate memory for storing encoder data */
124 ISAC_inst->ISACenc_obj.SaveEnc_ptr = malloc(1 * sizeof(ISAC_SaveEncData_t));
126 if (ISAC_inst->ISACenc_obj.SaveEnc_ptr!=NULL) {
138 /****************************************************************************
139 * WebRtcIsacfix_Free(...)
141 * This function frees the ISAC instance created at the beginning.
144 * - ISAC_main_inst : a ISAC instance.
146 * Return value : 0 - Ok
150 int16_t WebRtcIsacfix_Free(ISACFIX_MainStruct *ISAC_main_inst)
152 free(ISAC_main_inst);
156 /****************************************************************************
157 * WebRtcIsacfix_FreeInternal(...)
159 * This function frees the internal memory for storing encoder data.
162 * - ISAC_main_inst : a ISAC instance.
164 * Return value : 0 - Ok
168 int16_t WebRtcIsacfix_FreeInternal(ISACFIX_MainStruct *ISAC_main_inst)
170 ISACFIX_SubStruct *ISAC_inst;
172 /* typecast pointer to real structure */
173 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
176 free(ISAC_inst->ISACenc_obj.SaveEnc_ptr);
181 /****************************************************************************
182 * WebRtcIsacfix_InitNeon(...)
184 * This function initializes function pointers for ARM Neon platform.
187 #if (defined WEBRTC_DETECT_ARM_NEON || defined WEBRTC_ARCH_ARM_NEON)
188 static void WebRtcIsacfix_InitNeon(void) {
189 WebRtcIsacfix_AutocorrFix = WebRtcIsacfix_AutocorrNeon;
190 WebRtcIsacfix_FilterMaLoopFix = WebRtcIsacfix_FilterMaLoopNeon;
191 WebRtcIsacfix_Spec2Time = WebRtcIsacfix_Spec2TimeNeon;
192 WebRtcIsacfix_Time2Spec = WebRtcIsacfix_Time2SpecNeon;
193 WebRtcIsacfix_CalculateResidualEnergy =
194 WebRtcIsacfix_CalculateResidualEnergyNeon;
195 WebRtcIsacfix_AllpassFilter2FixDec16 =
196 WebRtcIsacfix_AllpassFilter2FixDec16Neon;
197 WebRtcIsacfix_MatrixProduct1 = WebRtcIsacfix_MatrixProduct1Neon;
198 WebRtcIsacfix_MatrixProduct2 = WebRtcIsacfix_MatrixProduct2Neon;
202 /****************************************************************************
203 * WebRtcIsacfix_InitMIPS(...)
205 * This function initializes function pointers for MIPS platform.
208 #if defined(MIPS32_LE)
209 static void WebRtcIsacfix_InitMIPS(void) {
210 WebRtcIsacfix_AutocorrFix = WebRtcIsacfix_AutocorrMIPS;
211 WebRtcIsacfix_FilterMaLoopFix = WebRtcIsacfix_FilterMaLoopMIPS;
212 WebRtcIsacfix_Spec2Time = WebRtcIsacfix_Spec2TimeMIPS;
213 WebRtcIsacfix_Time2Spec = WebRtcIsacfix_Time2SpecMIPS;
214 #if defined(MIPS_DSP_R1_LE)
215 WebRtcIsacfix_AllpassFilter2FixDec16 =
216 WebRtcIsacfix_AllpassFilter2FixDec16MIPS;
217 WebRtcIsacfix_HighpassFilterFixDec32 =
218 WebRtcIsacfix_HighpassFilterFixDec32MIPS;
220 #if defined(MIPS_DSP_R2_LE)
221 WebRtcIsacfix_CalculateResidualEnergy =
222 WebRtcIsacfix_CalculateResidualEnergyMIPS;
227 /****************************************************************************
228 * WebRtcIsacfix_EncoderInit(...)
230 * This function initializes a ISAC instance prior to the encoder calls.
233 * - ISAC_main_inst : ISAC instance.
234 * - CodingMode : 0 -> Bit rate and frame length are automatically
235 * adjusted to available bandwidth on
236 * transmission channel.
237 * 1 -> User sets a frame length and a target bit
238 * rate which is taken as the maximum short-term
241 * Return value : 0 - Ok
245 int16_t WebRtcIsacfix_EncoderInit(ISACFIX_MainStruct *ISAC_main_inst,
250 ISACFIX_SubStruct *ISAC_inst;
253 /* typecast pointer to rela structure */
254 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
256 /* flag encoder init */
257 ISAC_inst->initflag |= 2;
261 ISAC_inst->ISACenc_obj.new_framelength = INITIAL_FRAMESAMPLES;
262 else if (CodingMode == 1)
263 /* Instantaneous mode */
264 ISAC_inst->ISACenc_obj.new_framelength = 480; /* default for I-mode */
266 ISAC_inst->errorcode = ISAC_DISALLOWED_CODING_MODE;
270 ISAC_inst->CodingMode = CodingMode;
272 WebRtcIsacfix_InitMaskingEnc(&ISAC_inst->ISACenc_obj.maskfiltstr_obj);
273 WebRtcIsacfix_InitPreFilterbank(&ISAC_inst->ISACenc_obj.prefiltbankstr_obj);
274 WebRtcIsacfix_InitPitchFilter(&ISAC_inst->ISACenc_obj.pitchfiltstr_obj);
275 WebRtcIsacfix_InitPitchAnalysis(&ISAC_inst->ISACenc_obj.pitchanalysisstr_obj);
278 WebRtcIsacfix_InitBandwidthEstimator(&ISAC_inst->bwestimator_obj);
279 WebRtcIsacfix_InitRateModel(&ISAC_inst->ISACenc_obj.rate_data_obj);
282 ISAC_inst->ISACenc_obj.buffer_index = 0;
283 ISAC_inst->ISACenc_obj.frame_nb = 0;
284 ISAC_inst->ISACenc_obj.BottleNeck = 32000; /* default for I-mode */
285 ISAC_inst->ISACenc_obj.MaxDelay = 10; /* default for I-mode */
286 ISAC_inst->ISACenc_obj.current_framesamples = 0;
287 ISAC_inst->ISACenc_obj.s2nr = 0;
288 ISAC_inst->ISACenc_obj.MaxBits = 0;
289 ISAC_inst->ISACenc_obj.bitstr_seed = 4447;
290 ISAC_inst->ISACenc_obj.payloadLimitBytes30 = STREAM_MAXW16_30MS << 1;
291 ISAC_inst->ISACenc_obj.payloadLimitBytes60 = STREAM_MAXW16_60MS << 1;
292 ISAC_inst->ISACenc_obj.maxPayloadBytes = STREAM_MAXW16_60MS << 1;
293 ISAC_inst->ISACenc_obj.maxRateInBytes = STREAM_MAXW16_30MS << 1;
294 ISAC_inst->ISACenc_obj.enforceFrameSize = 0;
296 /* Init the bistream data area to zero */
297 for (k=0; k<STREAM_MAXW16_60MS; k++){
298 ISAC_inst->ISACenc_obj.bitstr_obj.stream[k] = 0;
301 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
302 WebRtcIsacfix_InitPostFilterbank(&ISAC_inst->ISACenc_obj.interpolatorstr_obj);
305 // Initiaze function pointers.
306 WebRtcIsacfix_AutocorrFix = WebRtcIsacfix_AutocorrC;
307 WebRtcIsacfix_FilterMaLoopFix = WebRtcIsacfix_FilterMaLoopC;
308 WebRtcIsacfix_CalculateResidualEnergy =
309 WebRtcIsacfix_CalculateResidualEnergyC;
310 WebRtcIsacfix_AllpassFilter2FixDec16 = WebRtcIsacfix_AllpassFilter2FixDec16C;
311 WebRtcIsacfix_HighpassFilterFixDec32 = WebRtcIsacfix_HighpassFilterFixDec32C;
312 WebRtcIsacfix_Time2Spec = WebRtcIsacfix_Time2SpecC;
313 WebRtcIsacfix_Spec2Time = WebRtcIsacfix_Spec2TimeC;
314 WebRtcIsacfix_MatrixProduct1 = WebRtcIsacfix_MatrixProduct1C;
315 WebRtcIsacfix_MatrixProduct2 = WebRtcIsacfix_MatrixProduct2C;
317 #ifdef WEBRTC_DETECT_ARM_NEON
318 if ((WebRtc_GetCPUFeaturesARM() & kCPUFeatureNEON) != 0) {
319 WebRtcIsacfix_InitNeon();
321 #elif defined(WEBRTC_ARCH_ARM_NEON)
322 WebRtcIsacfix_InitNeon();
325 #if defined(MIPS32_LE)
326 WebRtcIsacfix_InitMIPS();
332 /****************************************************************************
333 * WebRtcIsacfix_Encode(...)
335 * This function encodes 10ms frame(s) and inserts it into a package.
336 * Input speech length has to be 160 samples (10ms). The encoder buffers those
337 * 10ms frames until it reaches the chosen Framesize (480 or 960 samples
338 * corresponding to 30 or 60 ms frames), and then proceeds to the encoding.
341 * - ISAC_main_inst : ISAC instance.
342 * - speechIn : input speech vector.
345 * - encoded : the encoded data vector
348 * : >0 - Length (in bytes) of coded data
349 * : 0 - The buffer didn't reach the chosen framesize
350 * so it keeps buffering speech samples.
354 int16_t WebRtcIsacfix_Encode(ISACFIX_MainStruct *ISAC_main_inst,
355 const int16_t *speechIn,
358 ISACFIX_SubStruct *ISAC_inst;
360 #ifndef WEBRTC_ARCH_BIG_ENDIAN
364 /* typecast pointer to rela structure */
365 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
368 /* check if encoder initiated */
369 if ((ISAC_inst->initflag & 2) != 2) {
370 ISAC_inst->errorcode = ISAC_ENCODER_NOT_INITIATED;
374 stream_len = WebRtcIsacfix_EncodeImpl((int16_t*)speechIn,
375 &ISAC_inst->ISACenc_obj,
376 &ISAC_inst->bwestimator_obj,
377 ISAC_inst->CodingMode);
379 ISAC_inst->errorcode = - stream_len;
384 /* convert from bytes to int16_t */
385 #ifndef WEBRTC_ARCH_BIG_ENDIAN
386 for (k=0;k<(stream_len+1)>>1;k++) {
387 encoded[k] = (int16_t)( ( (uint16_t)(ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] >> 8 )
388 | (((ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] & 0x00FF) << 8));
392 WEBRTC_SPL_MEMCPY_W16(encoded, (ISAC_inst->ISACenc_obj.bitstr_obj).stream, (stream_len + 1)>>1);
404 /****************************************************************************
405 * WebRtcIsacfix_EncodeNb(...)
407 * This function encodes 10ms narrow band (8 kHz sampling) frame(s) and inserts
408 * it into a package. Input speech length has to be 80 samples (10ms). The encoder
409 * interpolates into wide-band (16 kHz sampling) buffers those
410 * 10ms frames until it reaches the chosen Framesize (480 or 960 wide-band samples
411 * corresponding to 30 or 60 ms frames), and then proceeds to the encoding.
413 * The function is enabled if WEBRTC_ISAC_FIX_NB_CALLS_ENABLED is defined
416 * - ISAC_main_inst : ISAC instance.
417 * - speechIn : input speech vector.
420 * - encoded : the encoded data vector
423 * : >0 - Length (in bytes) of coded data
424 * : 0 - The buffer didn't reach the chosen framesize
425 * so it keeps buffering speech samples.
428 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
429 int16_t WebRtcIsacfix_EncodeNb(ISACFIX_MainStruct *ISAC_main_inst,
430 const int16_t *speechIn,
433 ISACFIX_SubStruct *ISAC_inst;
435 int16_t speechInWB[FRAMESAMPLES_10ms];
436 int16_t Vector_Word16_1[FRAMESAMPLES_10ms/2];
437 int16_t Vector_Word16_2[FRAMESAMPLES_10ms/2];
442 /* typecast pointer to rela structure */
443 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
446 /* check if encoder initiated */
447 if ((ISAC_inst->initflag & 2) != 2) {
448 ISAC_inst->errorcode = ISAC_ENCODER_NOT_INITIATED;
453 /* Oversample to WB */
455 /* Form polyphase signals, and compensate for DC offset */
456 for (k=0;k<FRAMESAMPLES_10ms/2;k++) {
457 Vector_Word16_1[k] = speechIn[k] + 1;
458 Vector_Word16_2[k] = speechIn[k];
460 WebRtcIsacfix_FilterAndCombine2(Vector_Word16_1, Vector_Word16_2, speechInWB, &ISAC_inst->ISACenc_obj.interpolatorstr_obj, FRAMESAMPLES_10ms);
463 /* Encode WB signal */
464 stream_len = WebRtcIsacfix_EncodeImpl((int16_t*)speechInWB,
465 &ISAC_inst->ISACenc_obj,
466 &ISAC_inst->bwestimator_obj,
467 ISAC_inst->CodingMode);
469 ISAC_inst->errorcode = - stream_len;
474 /* convert from bytes to int16_t */
475 #ifndef WEBRTC_ARCH_BIG_ENDIAN
476 for (k=0;k<(stream_len+1)>>1;k++) {
477 encoded[k] = (int16_t)(((uint16_t)(ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] >> 8)
478 | (((ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] & 0x00FF) << 8));
482 WEBRTC_SPL_MEMCPY_W16(encoded, (ISAC_inst->ISACenc_obj.bitstr_obj).stream, (stream_len + 1)>>1);
489 #endif /* WEBRTC_ISAC_FIX_NB_CALLS_ENABLED */
492 /****************************************************************************
493 * WebRtcIsacfix_GetNewBitStream(...)
495 * This function returns encoded data, with the recieved bwe-index in the
496 * stream. It should always return a complete packet, i.e. only called once
497 * even for 60 msec frames
500 * - ISAC_main_inst : ISAC instance.
501 * - bweIndex : index of bandwidth estimate to put in new bitstream
504 * - encoded : the encoded data vector
507 * : >0 - Length (in bytes) of coded data
511 int16_t WebRtcIsacfix_GetNewBitStream(ISACFIX_MainStruct *ISAC_main_inst,
516 ISACFIX_SubStruct *ISAC_inst;
518 #ifndef WEBRTC_ARCH_BIG_ENDIAN
522 /* typecast pointer to rela structure */
523 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
526 /* check if encoder initiated */
527 if ((ISAC_inst->initflag & 2) != 2) {
528 ISAC_inst->errorcode = ISAC_ENCODER_NOT_INITIATED;
532 stream_len = WebRtcIsacfix_EncodeStoredData(&ISAC_inst->ISACenc_obj,
536 ISAC_inst->errorcode = - stream_len;
540 #ifndef WEBRTC_ARCH_BIG_ENDIAN
541 for (k=0;k<(stream_len+1)>>1;k++) {
542 encoded[k] = (int16_t)( ( (uint16_t)(ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] >> 8 )
543 | (((ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] & 0x00FF) << 8));
547 WEBRTC_SPL_MEMCPY_W16(encoded, (ISAC_inst->ISACenc_obj.bitstr_obj).stream, (stream_len + 1)>>1);
556 /****************************************************************************
557 * WebRtcIsacfix_DecoderInit(...)
559 * This function initializes a ISAC instance prior to the decoder calls.
562 * - ISAC_main_inst : ISAC instance.
569 int16_t WebRtcIsacfix_DecoderInit(ISACFIX_MainStruct *ISAC_main_inst)
571 ISACFIX_SubStruct *ISAC_inst;
573 /* typecast pointer to real structure */
574 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
576 /* flag decoder init */
577 ISAC_inst->initflag |= 1;
579 WebRtcIsacfix_InitMaskingDec(&ISAC_inst->ISACdec_obj.maskfiltstr_obj);
580 WebRtcIsacfix_InitPostFilterbank(&ISAC_inst->ISACdec_obj.postfiltbankstr_obj);
581 WebRtcIsacfix_InitPitchFilter(&ISAC_inst->ISACdec_obj.pitchfiltstr_obj);
584 WebRtcIsacfix_InitPlc( &ISAC_inst->ISACdec_obj.plcstr_obj );
587 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
588 WebRtcIsacfix_InitPreFilterbank(&ISAC_inst->ISACdec_obj.decimatorstr_obj);
595 /****************************************************************************
596 * WebRtcIsacfix_UpdateBwEstimate1(...)
598 * This function updates the estimate of the bandwidth.
601 * - ISAC_main_inst : ISAC instance.
602 * - encoded : encoded ISAC frame(s).
603 * - packet_size : size of the packet.
604 * - rtp_seq_number : the RTP number of the packet.
605 * - arr_ts : the arrival time of the packet (from NetEq)
608 * Return value : 0 - Ok
612 int16_t WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_MainStruct *ISAC_main_inst,
613 const uint16_t *encoded,
615 uint16_t rtp_seq_number,
618 ISACFIX_SubStruct *ISAC_inst;
619 Bitstr_dec streamdata;
620 #ifndef WEBRTC_ARCH_BIG_ENDIAN
625 /* typecast pointer to real structure */
626 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
628 /* Sanity check of packet length */
629 if (packet_size <= 0) {
630 /* return error code if the packet length is null or less */
631 ISAC_inst->errorcode = ISAC_EMPTY_PACKET;
633 } else if (packet_size > (STREAM_MAXW16<<1)) {
634 /* return error code if length of stream is too long */
635 ISAC_inst->errorcode = ISAC_LENGTH_MISMATCH;
639 /* check if decoder initiated */
640 if ((ISAC_inst->initflag & 1) != 1) {
641 ISAC_inst->errorcode = ISAC_DECODER_NOT_INITIATED;
645 streamdata.W_upper = 0xFFFFFFFF;
646 streamdata.streamval = 0;
647 streamdata.stream_index = 0;
650 #ifndef WEBRTC_ARCH_BIG_ENDIAN
651 for (k=0; k<5; k++) {
652 streamdata.stream[k] = (uint16_t) (((uint16_t)encoded[k] >> 8)|((encoded[k] & 0xFF)<<8));
655 memcpy(streamdata.stream, encoded, 5);
658 err = WebRtcIsacfix_EstimateBandwidth(&ISAC_inst->bwestimator_obj,
668 /* return error code if something went wrong */
669 ISAC_inst->errorcode = -err;
677 /****************************************************************************
678 * WebRtcIsacfix_UpdateBwEstimate(...)
680 * This function updates the estimate of the bandwidth.
683 * - ISAC_main_inst : ISAC instance.
684 * - encoded : encoded ISAC frame(s).
685 * - packet_size : size of the packet.
686 * - rtp_seq_number : the RTP number of the packet.
687 * - send_ts : Send Time Stamp from RTP header
688 * - arr_ts : the arrival time of the packet (from NetEq)
691 * Return value : 0 - Ok
695 int16_t WebRtcIsacfix_UpdateBwEstimate(ISACFIX_MainStruct *ISAC_main_inst,
696 const uint16_t *encoded,
698 uint16_t rtp_seq_number,
702 ISACFIX_SubStruct *ISAC_inst;
703 Bitstr_dec streamdata;
704 #ifndef WEBRTC_ARCH_BIG_ENDIAN
709 /* typecast pointer to real structure */
710 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
712 /* Sanity check of packet length */
713 if (packet_size <= 0) {
714 /* return error code if the packet length is null or less */
715 ISAC_inst->errorcode = ISAC_EMPTY_PACKET;
717 } else if (packet_size > (STREAM_MAXW16<<1)) {
718 /* return error code if length of stream is too long */
719 ISAC_inst->errorcode = ISAC_LENGTH_MISMATCH;
723 /* check if decoder initiated */
724 if ((ISAC_inst->initflag & 1) != 1) {
725 ISAC_inst->errorcode = ISAC_DECODER_NOT_INITIATED;
729 streamdata.W_upper = 0xFFFFFFFF;
730 streamdata.streamval = 0;
731 streamdata.stream_index = 0;
734 #ifndef WEBRTC_ARCH_BIG_ENDIAN
735 for (k=0; k<5; k++) {
736 streamdata.stream[k] = (uint16_t) ((encoded[k] >> 8)|((encoded[k] & 0xFF)<<8));
739 memcpy(streamdata.stream, encoded, 5);
742 err = WebRtcIsacfix_EstimateBandwidth(&ISAC_inst->bwestimator_obj,
751 /* return error code if something went wrong */
752 ISAC_inst->errorcode = -err;
760 /****************************************************************************
761 * WebRtcIsacfix_Decode(...)
763 * This function decodes a ISAC frame. Output speech length
764 * will be a multiple of 480 samples: 480 or 960 samples,
765 * depending on the framesize (30 or 60 ms).
768 * - ISAC_main_inst : ISAC instance.
769 * - encoded : encoded ISAC frame(s)
770 * - len : bytes in encoded vector
773 * - decoded : The decoded vector
775 * Return value : >0 - number of samples in decoded vector
780 int16_t WebRtcIsacfix_Decode(ISACFIX_MainStruct *ISAC_main_inst,
781 const uint16_t *encoded,
786 ISACFIX_SubStruct *ISAC_inst;
787 /* number of samples (480 or 960), output from decoder */
788 /* that were actually used in the encoder/decoder (determined on the fly) */
789 int16_t number_of_samples;
790 #ifndef WEBRTC_ARCH_BIG_ENDIAN
795 /* typecast pointer to real structure */
796 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
798 /* check if decoder initiated */
799 if ((ISAC_inst->initflag & 1) != 1) {
800 ISAC_inst->errorcode = ISAC_DECODER_NOT_INITIATED;
804 /* Sanity check of packet length */
806 /* return error code if the packet length is null or less */
807 ISAC_inst->errorcode = ISAC_EMPTY_PACKET;
809 } else if (len > (STREAM_MAXW16<<1)) {
810 /* return error code if length of stream is too long */
811 ISAC_inst->errorcode = ISAC_LENGTH_MISMATCH;
815 ISAC_inst->ISACdec_obj.bitstr_obj.stream_size = (len + 1) >> 1;
817 /* convert bitstream from int16_t to bytes */
818 #ifndef WEBRTC_ARCH_BIG_ENDIAN
819 for (k=0; k<(len>>1); k++) {
820 (ISAC_inst->ISACdec_obj.bitstr_obj).stream[k] = (uint16_t) ((encoded[k] >> 8)|((encoded[k] & 0xFF)<<8));
823 (ISAC_inst->ISACdec_obj.bitstr_obj).stream[k] = (uint16_t) ((encoded[k] & 0xFF)<<8);
826 /* added for NetEq purposes (VAD/DTX related) */
829 declen = WebRtcIsacfix_DecodeImpl(decoded,&ISAC_inst->ISACdec_obj, &number_of_samples);
832 /* Some error inside the decoder */
833 ISAC_inst->errorcode = -declen;
834 memset(decoded, 0, sizeof(int16_t) * MAX_FRAMESAMPLES);
840 if (declen & 0x0001) {
841 if (len != declen && len != declen + (((ISAC_inst->ISACdec_obj.bitstr_obj).stream[declen>>1]) & 0x00FF) ) {
842 ISAC_inst->errorcode = ISAC_LENGTH_MISMATCH;
843 memset(decoded, 0, sizeof(int16_t) * number_of_samples);
847 if (len != declen && len != declen + (((ISAC_inst->ISACdec_obj.bitstr_obj).stream[declen>>1]) >> 8) ) {
848 ISAC_inst->errorcode = ISAC_LENGTH_MISMATCH;
849 memset(decoded, 0, sizeof(int16_t) * number_of_samples);
854 return number_of_samples;
861 /****************************************************************************
862 * WebRtcIsacfix_DecodeNb(...)
864 * This function decodes a ISAC frame in narrow-band (8 kHz sampling).
865 * Output speech length will be a multiple of 240 samples: 240 or 480 samples,
866 * depending on the framesize (30 or 60 ms).
868 * The function is enabled if WEBRTC_ISAC_FIX_NB_CALLS_ENABLED is defined
871 * - ISAC_main_inst : ISAC instance.
872 * - encoded : encoded ISAC frame(s)
873 * - len : bytes in encoded vector
876 * - decoded : The decoded vector
878 * Return value : >0 - number of samples in decoded vector
882 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
883 int16_t WebRtcIsacfix_DecodeNb(ISACFIX_MainStruct *ISAC_main_inst,
884 const uint16_t *encoded,
889 ISACFIX_SubStruct *ISAC_inst;
890 /* twice the number of samples (480 or 960), output from decoder */
891 /* that were actually used in the encoder/decoder (determined on the fly) */
892 int16_t number_of_samples;
893 #ifndef WEBRTC_ARCH_BIG_ENDIAN
897 int16_t dummy[FRAMESAMPLES/2];
900 /* typecast pointer to real structure */
901 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
903 /* check if decoder initiated */
904 if ((ISAC_inst->initflag & 1) != 1) {
905 ISAC_inst->errorcode = ISAC_DECODER_NOT_INITIATED;
910 { /* return error code if the packet length is null */
912 ISAC_inst->errorcode = ISAC_EMPTY_PACKET;
916 ISAC_inst->ISACdec_obj.bitstr_obj.stream_size = (len + 1) >> 1;
918 /* convert bitstream from int16_t to bytes */
919 #ifndef WEBRTC_ARCH_BIG_ENDIAN
920 for (k=0; k<(len>>1); k++) {
921 (ISAC_inst->ISACdec_obj.bitstr_obj).stream[k] = (uint16_t) ((encoded[k] >> 8)|((encoded[k] & 0xFF)<<8));
924 (ISAC_inst->ISACdec_obj.bitstr_obj).stream[k] = (uint16_t) ((encoded[k] & 0xFF)<<8);
927 /* added for NetEq purposes (VAD/DTX related) */
930 declen = WebRtcIsacfix_DecodeImpl(decoded,&ISAC_inst->ISACdec_obj, &number_of_samples);
933 /* Some error inside the decoder */
934 ISAC_inst->errorcode = -declen;
935 memset(decoded, 0, sizeof(int16_t) * FRAMESAMPLES);
941 if (declen & 0x0001) {
942 if (len != declen && len != declen + (((ISAC_inst->ISACdec_obj.bitstr_obj).stream[declen>>1]) & 0x00FF) ) {
943 ISAC_inst->errorcode = ISAC_LENGTH_MISMATCH;
944 memset(decoded, 0, sizeof(int16_t) * number_of_samples);
948 if (len != declen && len != declen + (((ISAC_inst->ISACdec_obj.bitstr_obj).stream[declen>>1]) >> 8) ) {
949 ISAC_inst->errorcode = ISAC_LENGTH_MISMATCH;
950 memset(decoded, 0, sizeof(int16_t) * number_of_samples);
955 WebRtcIsacfix_SplitAndFilter2(decoded, decoded, dummy, &ISAC_inst->ISACdec_obj.decimatorstr_obj);
957 if (number_of_samples>FRAMESAMPLES) {
958 WebRtcIsacfix_SplitAndFilter2(decoded + FRAMESAMPLES, decoded + FRAMESAMPLES/2,
959 dummy, &ISAC_inst->ISACdec_obj.decimatorstr_obj);
962 return number_of_samples/2;
964 #endif /* WEBRTC_ISAC_FIX_NB_CALLS_ENABLED */
967 /****************************************************************************
968 * WebRtcIsacfix_DecodePlcNb(...)
970 * This function conducts PLC for ISAC frame(s) in narrow-band (8kHz sampling).
971 * Output speech length will be "240*noOfLostFrames" samples
972 * that is equevalent of "30*noOfLostFrames" millisecond.
974 * The function is enabled if WEBRTC_ISAC_FIX_NB_CALLS_ENABLED is defined
977 * - ISAC_main_inst : ISAC instance.
978 * - noOfLostFrames : Number of PLC frames (240 sample=30ms) to produce
981 * - decoded : The decoded vector
983 * Return value : >0 - number of samples in decoded PLC vector
987 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
988 int16_t WebRtcIsacfix_DecodePlcNb(ISACFIX_MainStruct *ISAC_main_inst,
990 int16_t noOfLostFrames )
992 int16_t no_of_samples, declen, k, ok;
993 int16_t outframeNB[FRAMESAMPLES];
994 int16_t outframeWB[FRAMESAMPLES];
995 int16_t dummy[FRAMESAMPLES/2];
998 ISACFIX_SubStruct *ISAC_inst;
999 /* typecast pointer to real structure */
1000 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
1002 /* Limit number of frames to two = 60 msec. Otherwise we exceed data vectors */
1003 if (noOfLostFrames > 2){
1009 while( noOfLostFrames > 0 )
1011 ok = WebRtcIsacfix_DecodePlcImpl( outframeWB, &ISAC_inst->ISACdec_obj, &no_of_samples );
1015 WebRtcIsacfix_SplitAndFilter2(outframeWB, &(outframeNB[k*240]), dummy, &ISAC_inst->ISACdec_obj.decimatorstr_obj);
1017 declen += no_of_samples;
1024 for (k=0;k<declen;k++) {
1025 decoded[k] = outframeNB[k];
1030 #endif /* WEBRTC_ISAC_FIX_NB_CALLS_ENABLED */
1035 /****************************************************************************
1036 * WebRtcIsacfix_DecodePlc(...)
1038 * This function conducts PLC for ISAC frame(s) in wide-band (16kHz sampling).
1039 * Output speech length will be "480*noOfLostFrames" samples
1040 * that is equevalent of "30*noOfLostFrames" millisecond.
1043 * - ISAC_main_inst : ISAC instance.
1044 * - noOfLostFrames : Number of PLC frames (480sample = 30ms)
1048 * - decoded : The decoded vector
1050 * Return value : >0 - number of samples in decoded PLC vector
1054 int16_t WebRtcIsacfix_DecodePlc(ISACFIX_MainStruct *ISAC_main_inst,
1056 int16_t noOfLostFrames)
1059 int16_t no_of_samples, declen, k, ok;
1060 int16_t outframe16[MAX_FRAMESAMPLES];
1062 ISACFIX_SubStruct *ISAC_inst;
1063 /* typecast pointer to real structure */
1064 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
1066 /* Limit number of frames to two = 60 msec. Otherwise we exceed data vectors */
1067 if (noOfLostFrames > 2) {
1072 while( noOfLostFrames > 0 )
1074 ok = WebRtcIsacfix_DecodePlcImpl( &(outframe16[k*480]), &ISAC_inst->ISACdec_obj, &no_of_samples );
1077 declen += no_of_samples;
1082 for (k=0;k<declen;k++) {
1083 decoded[k] = outframe16[k];
1090 /****************************************************************************
1091 * WebRtcIsacfix_Control(...)
1093 * This function sets the limit on the short-term average bit rate and the
1094 * frame length. Should be used only in Instantaneous mode.
1097 * - ISAC_main_inst : ISAC instance.
1098 * - rate : limit on the short-term average bit rate,
1099 * in bits/second (between 10000 and 32000)
1100 * - framesize : number of milliseconds per frame (30 or 60)
1102 * Return value : 0 - ok
1106 int16_t WebRtcIsacfix_Control(ISACFIX_MainStruct *ISAC_main_inst,
1110 ISACFIX_SubStruct *ISAC_inst;
1111 /* typecast pointer to real structure */
1112 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
1114 if (ISAC_inst->CodingMode == 0)
1116 /* in adaptive mode */
1117 ISAC_inst->errorcode = ISAC_MODE_MISMATCH;
1122 if (rate >= 10000 && rate <= 32000)
1123 ISAC_inst->ISACenc_obj.BottleNeck = rate;
1125 ISAC_inst->errorcode = ISAC_DISALLOWED_BOTTLENECK;
1131 if (framesize == 30 || framesize == 60)
1132 ISAC_inst->ISACenc_obj.new_framelength = (FS/1000) * framesize;
1134 ISAC_inst->errorcode = ISAC_DISALLOWED_FRAME_LENGTH;
1142 /****************************************************************************
1143 * WebRtcIsacfix_ControlBwe(...)
1145 * This function sets the initial values of bottleneck and frame-size if
1146 * iSAC is used in channel-adaptive mode. Through this API, users can
1147 * enforce a frame-size for all values of bottleneck. Then iSAC will not
1148 * automatically change the frame-size.
1152 * - ISAC_main_inst : ISAC instance.
1153 * - rateBPS : initial value of bottleneck in bits/second
1154 * 10000 <= rateBPS <= 32000 is accepted
1155 * For default bottleneck set rateBPS = 0
1156 * - frameSizeMs : number of milliseconds per frame (30 or 60)
1157 * - enforceFrameSize : 1 to enforce the given frame-size through out
1158 * the adaptation process, 0 to let iSAC change
1159 * the frame-size if required.
1161 * Return value : 0 - ok
1165 int16_t WebRtcIsacfix_ControlBwe(ISACFIX_MainStruct *ISAC_main_inst,
1167 int16_t frameSizeMs,
1168 int16_t enforceFrameSize)
1170 ISACFIX_SubStruct *ISAC_inst;
1171 /* Typecast pointer to real structure */
1172 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
1174 /* check if encoder initiated */
1175 if ((ISAC_inst->initflag & 2) != 2) {
1176 ISAC_inst->errorcode = ISAC_ENCODER_NOT_INITIATED;
1180 /* Check that we are in channel-adaptive mode, otherwise, return -1 */
1181 if (ISAC_inst->CodingMode != 0) {
1182 ISAC_inst->errorcode = ISAC_MODE_MISMATCH;
1186 /* Set struct variable if enforceFrameSize is set. ISAC will then keep the */
1187 /* chosen frame size. */
1188 ISAC_inst->ISACenc_obj.enforceFrameSize = (enforceFrameSize != 0)? 1:0;
1190 /* Set initial rate, if value between 10000 and 32000, */
1191 /* if rateBPS is 0, keep the default initial bottleneck value (15000) */
1192 if ((rateBPS >= 10000) && (rateBPS <= 32000)) {
1193 ISAC_inst->bwestimator_obj.sendBwAvg = (((uint32_t)rateBPS) << 7);
1194 } else if (rateBPS != 0) {
1195 ISAC_inst->errorcode = ISAC_DISALLOWED_BOTTLENECK;
1199 /* Set initial framesize. If enforceFrameSize is set the frame size will not change */
1200 if ((frameSizeMs == 30) || (frameSizeMs == 60)) {
1201 ISAC_inst->ISACenc_obj.new_framelength = (FS/1000) * frameSizeMs;
1203 ISAC_inst->errorcode = ISAC_DISALLOWED_FRAME_LENGTH;
1214 /****************************************************************************
1215 * WebRtcIsacfix_GetDownLinkBwIndex(...)
1217 * This function returns index representing the Bandwidth estimate from
1218 * other side to this side.
1221 * - ISAC_main_inst: iSAC struct
1224 * - rateIndex : Bandwidth estimate to transmit to other side.
1228 int16_t WebRtcIsacfix_GetDownLinkBwIndex(ISACFIX_MainStruct* ISAC_main_inst,
1231 ISACFIX_SubStruct *ISAC_inst;
1233 /* typecast pointer to real structure */
1234 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
1236 /* Call function to get Bandwidth Estimate */
1237 *rateIndex = WebRtcIsacfix_GetDownlinkBwIndexImpl(&ISAC_inst->bwestimator_obj);
1243 /****************************************************************************
1244 * WebRtcIsacfix_UpdateUplinkBw(...)
1246 * This function takes an index representing the Bandwidth estimate from
1247 * this side to other side and updates BWE.
1250 * - ISAC_main_inst: iSAC struct
1251 * - rateIndex : Bandwidth estimate from other side.
1255 int16_t WebRtcIsacfix_UpdateUplinkBw(ISACFIX_MainStruct* ISAC_main_inst,
1259 ISACFIX_SubStruct *ISAC_inst;
1261 /* typecast pointer to real structure */
1262 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
1264 /* Call function to update BWE with received Bandwidth Estimate */
1265 err = WebRtcIsacfix_UpdateUplinkBwRec(&ISAC_inst->bwestimator_obj, rateIndex);
1267 ISAC_inst->errorcode = -err;
1274 /****************************************************************************
1275 * WebRtcIsacfix_ReadFrameLen(...)
1277 * This function returns the length of the frame represented in the packet.
1280 * - encoded : Encoded bitstream
1283 * - frameLength : Length of frame in packet (in samples)
1287 int16_t WebRtcIsacfix_ReadFrameLen(const int16_t* encoded,
1288 int16_t* frameLength)
1290 Bitstr_dec streamdata;
1291 #ifndef WEBRTC_ARCH_BIG_ENDIAN
1296 streamdata.W_upper = 0xFFFFFFFF;
1297 streamdata.streamval = 0;
1298 streamdata.stream_index = 0;
1299 streamdata.full = 1;
1301 #ifndef WEBRTC_ARCH_BIG_ENDIAN
1302 for (k=0; k<5; k++) {
1303 streamdata.stream[k] = (uint16_t) (((uint16_t)encoded[k] >> 8)|((encoded[k] & 0xFF)<<8));
1306 memcpy(streamdata.stream, encoded, 5);
1309 /* decode frame length */
1310 err = WebRtcIsacfix_DecodeFrameLen(&streamdata, frameLength);
1311 if (err<0) // error check
1318 /****************************************************************************
1319 * WebRtcIsacfix_ReadBwIndex(...)
1321 * This function returns the index of the Bandwidth estimate from the bitstream.
1324 * - encoded : Encoded bitstream
1327 * - frameLength : Length of frame in packet (in samples)
1328 * - rateIndex : Bandwidth estimate in bitstream
1332 int16_t WebRtcIsacfix_ReadBwIndex(const int16_t* encoded,
1335 Bitstr_dec streamdata;
1336 #ifndef WEBRTC_ARCH_BIG_ENDIAN
1341 streamdata.W_upper = 0xFFFFFFFF;
1342 streamdata.streamval = 0;
1343 streamdata.stream_index = 0;
1344 streamdata.full = 1;
1346 #ifndef WEBRTC_ARCH_BIG_ENDIAN
1347 for (k=0; k<5; k++) {
1348 streamdata.stream[k] = (uint16_t) (((uint16_t)encoded[k] >> 8)|((encoded[k] & 0xFF)<<8));
1351 memcpy(streamdata.stream, encoded, 5);
1354 /* decode frame length, needed to get to the rateIndex in the bitstream */
1355 err = WebRtcIsacfix_DecodeFrameLen(&streamdata, rateIndex);
1356 if (err<0) // error check
1359 /* decode BW estimation */
1360 err = WebRtcIsacfix_DecodeSendBandwidth(&streamdata, rateIndex);
1361 if (err<0) // error check
1370 /****************************************************************************
1371 * WebRtcIsacfix_GetErrorCode(...)
1373 * This function can be used to check the error code of an iSAC instance. When
1374 * a function returns -1 a error code will be set for that instance. The
1375 * function below extract the code of the last error that occured in the
1376 * specified instance.
1379 * - ISAC_main_inst : ISAC instance
1381 * Return value : Error code
1384 int16_t WebRtcIsacfix_GetErrorCode(ISACFIX_MainStruct *ISAC_main_inst)
1386 ISACFIX_SubStruct *ISAC_inst;
1387 /* typecast pointer to real structure */
1388 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
1390 return ISAC_inst->errorcode;
1395 /****************************************************************************
1396 * WebRtcIsacfix_GetUplinkBw(...)
1398 * This function returns the inst quantized iSAC send bitrate
1401 * - ISAC_main_inst : iSAC instance
1403 * Return value : bitrate
1406 int32_t WebRtcIsacfix_GetUplinkBw(ISACFIX_MainStruct *ISAC_main_inst)
1408 ISACFIX_SubStruct *ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
1409 BwEstimatorstr * bw = (BwEstimatorstr*)&(ISAC_inst->bwestimator_obj);
1411 return (int32_t) WebRtcIsacfix_GetUplinkBandwidth(bw);
1414 /****************************************************************************
1415 * WebRtcIsacfix_GetNewFrameLen(...)
1417 * This function return the next frame length (in samples) of iSAC.
1420 * - ISAC_main_inst : iSAC instance
1422 * Return value : frame lenght in samples
1425 int16_t WebRtcIsacfix_GetNewFrameLen(ISACFIX_MainStruct *ISAC_main_inst)
1427 ISACFIX_SubStruct *ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
1428 return ISAC_inst->ISACenc_obj.new_framelength;
1432 /****************************************************************************
1433 * WebRtcIsacfix_SetMaxPayloadSize(...)
1435 * This function sets a limit for the maximum payload size of iSAC. The same
1436 * value is used both for 30 and 60 msec packets.
1437 * The absolute max will be valid until next time the function is called.
1438 * NOTE! This function may override the function WebRtcIsacfix_SetMaxRate()
1441 * - ISAC_main_inst : iSAC instance
1442 * - maxPayloadBytes : maximum size of the payload in bytes
1443 * valid values are between 100 and 400 bytes
1446 * Return value : 0 if sucessful
1447 * -1 if error happens
1450 int16_t WebRtcIsacfix_SetMaxPayloadSize(ISACFIX_MainStruct *ISAC_main_inst,
1451 int16_t maxPayloadBytes)
1453 ISACFIX_SubStruct *ISAC_inst;
1455 /* typecast pointer to real structure */
1456 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
1458 if((maxPayloadBytes < 100) || (maxPayloadBytes > 400))
1460 /* maxPayloadBytes is out of valid range */
1465 /* Set new absolute max, which will not change unless this function
1466 is called again with a new value */
1467 ISAC_inst->ISACenc_obj.maxPayloadBytes = maxPayloadBytes;
1469 /* Set new maximum values for 30 and 60 msec packets */
1470 if (maxPayloadBytes < ISAC_inst->ISACenc_obj.maxRateInBytes) {
1471 ISAC_inst->ISACenc_obj.payloadLimitBytes30 = maxPayloadBytes;
1473 ISAC_inst->ISACenc_obj.payloadLimitBytes30 = ISAC_inst->ISACenc_obj.maxRateInBytes;
1476 if ( maxPayloadBytes < (ISAC_inst->ISACenc_obj.maxRateInBytes << 1)) {
1477 ISAC_inst->ISACenc_obj.payloadLimitBytes60 = maxPayloadBytes;
1479 ISAC_inst->ISACenc_obj.payloadLimitBytes60 = (ISAC_inst->ISACenc_obj.maxRateInBytes << 1);
1486 /****************************************************************************
1487 * WebRtcIsacfix_SetMaxRate(...)
1489 * This function sets the maximum rate which the codec may not exceed for a
1490 * singel packet. The maximum rate is set in bits per second.
1491 * The codec has an absolute maximum rate of 53400 bits per second (200 bytes
1493 * It is possible to set a maximum rate between 32000 and 53400 bits per second.
1495 * The rate limit is valid until next time the function is called.
1497 * NOTE! Packet size will never go above the value set if calling
1498 * WebRtcIsacfix_SetMaxPayloadSize() (default max packet size is 400 bytes).
1501 * - ISAC_main_inst : iSAC instance
1502 * - maxRateInBytes : maximum rate in bits per second,
1503 * valid values are 32000 to 53400 bits
1505 * Return value : 0 if sucessful
1506 * -1 if error happens
1509 int16_t WebRtcIsacfix_SetMaxRate(ISACFIX_MainStruct *ISAC_main_inst,
1512 ISACFIX_SubStruct *ISAC_inst;
1513 int16_t maxRateInBytes;
1515 /* typecast pointer to real structure */
1516 ISAC_inst = (ISACFIX_SubStruct *)ISAC_main_inst;
1518 if((maxRate < 32000) || (maxRate > 53400))
1520 /* maxRate is out of valid range */
1525 /* Calculate maximum number of bytes per 30 msec packets for the given
1526 maximum rate. Multiply with 30/1000 to get number of bits per 30 msec,
1527 divide by 8 to get number of bytes per 30 msec:
1528 maxRateInBytes = floor((maxRate * 30/1000) / 8); */
1529 maxRateInBytes = (int16_t)( WebRtcSpl_DivW32W16ResW16(WEBRTC_SPL_MUL(maxRate, 3), 800) );
1531 /* Store the value for usage in the WebRtcIsacfix_SetMaxPayloadSize-function */
1532 ISAC_inst->ISACenc_obj.maxRateInBytes = maxRateInBytes;
1534 /* For 30 msec packets: if the new limit is below the maximum
1535 payload size, set a new limit */
1536 if (maxRateInBytes < ISAC_inst->ISACenc_obj.maxPayloadBytes) {
1537 ISAC_inst->ISACenc_obj.payloadLimitBytes30 = maxRateInBytes;
1539 ISAC_inst->ISACenc_obj.payloadLimitBytes30 = ISAC_inst->ISACenc_obj.maxPayloadBytes;
1542 /* For 60 msec packets: if the new limit (times 2) is below the
1543 maximum payload size, set a new limit */
1544 if ( (maxRateInBytes << 1) < ISAC_inst->ISACenc_obj.maxPayloadBytes) {
1545 ISAC_inst->ISACenc_obj.payloadLimitBytes60 = (maxRateInBytes << 1);
1547 ISAC_inst->ISACenc_obj.payloadLimitBytes60 = ISAC_inst->ISACenc_obj.maxPayloadBytes;
1556 /****************************************************************************
1557 * WebRtcIsacfix_version(...)
1559 * This function returns the version number.
1562 * - version : Pointer to character string
1566 void WebRtcIsacfix_version(char *version)
1568 strcpy(version, "3.6.0");