Update to current webrtc library
This is from the upstream library commit id 3326535126e435f1ba647885ce43a8f0f3d317eb, corresponding to Chromium 88.0.4290.1.
This commit is contained in:
		| @@ -8,8 +8,8 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "arith_routines.h" | ||||
| #include "settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/arith_routines.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
|  | ||||
| /* | ||||
|   | ||||
| @@ -15,49 +15,53 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ARITH_ROUTINES_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ARITH_ROUTINES_H_ | ||||
|  | ||||
| #include "structs.h" | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ARITH_ROUTINES_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ARITH_ROUTINES_H_ | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
|  | ||||
| int WebRtcIsac_EncLogisticMulti2( | ||||
|     Bitstr *streamdata,              /* in-/output struct containing bitstream */ | ||||
|     int16_t *dataQ7,           /* input: data vector */ | ||||
|     const uint16_t *env,       /* input: side info vector defining the width of the pdf */ | ||||
|     const int N,                     /* input: data vector length */ | ||||
|     Bitstr* streamdata, /* in-/output struct containing bitstream */ | ||||
|     int16_t* dataQ7,    /* input: data vector */ | ||||
|     const uint16_t* | ||||
|         env,     /* input: side info vector defining the width of the pdf */ | ||||
|     const int N, /* input: data vector length */ | ||||
|     const int16_t isSWB12kHz); /* if the codec is working in 12kHz bandwidth */ | ||||
|  | ||||
| /* returns the number of bytes in the stream */ | ||||
| int WebRtcIsac_EncTerminate(Bitstr *streamdata); /* in-/output struct containing bitstream */ | ||||
| int WebRtcIsac_EncTerminate( | ||||
|     Bitstr* streamdata); /* in-/output struct containing bitstream */ | ||||
|  | ||||
| /* returns the number of bytes in the stream so far */ | ||||
| int WebRtcIsac_DecLogisticMulti2( | ||||
|     int16_t *data,             /* output: data vector */ | ||||
|     Bitstr *streamdata,              /* in-/output struct containing bitstream */ | ||||
|     const uint16_t *env,       /* input: side info vector defining the width of the pdf */ | ||||
|     const int16_t *dither,     /* input: dither vector */ | ||||
|     const int N,                     /* input: data vector length */ | ||||
|     int16_t* data,      /* output: data vector */ | ||||
|     Bitstr* streamdata, /* in-/output struct containing bitstream */ | ||||
|     const uint16_t* | ||||
|         env, /* input: side info vector defining the width of the pdf */ | ||||
|     const int16_t* dither,     /* input: dither vector */ | ||||
|     const int N,               /* input: data vector length */ | ||||
|     const int16_t isSWB12kHz); /* if the codec is working in 12kHz bandwidth */ | ||||
|  | ||||
| void WebRtcIsac_EncHistMulti( | ||||
|     Bitstr *streamdata,         /* in-/output struct containing bitstream */ | ||||
|     const int *data,            /* input: data vector */ | ||||
|     const uint16_t **cdf, /* input: array of cdf arrays */ | ||||
|     Bitstr* streamdata,         /* in-/output struct containing bitstream */ | ||||
|     const int* data,            /* input: data vector */ | ||||
|     const uint16_t* const* cdf, /* input: array of cdf arrays */ | ||||
|     const int N);               /* input: data vector length */ | ||||
|  | ||||
| int WebRtcIsac_DecHistBisectMulti( | ||||
|     int *data,                      /* output: data vector */ | ||||
|     Bitstr *streamdata,             /* in-/output struct containing bitstream */ | ||||
|     const uint16_t **cdf,     /* input: array of cdf arrays */ | ||||
|     const uint16_t *cdf_size, /* input: array of cdf table sizes+1 (power of two: 2^k) */ | ||||
|     const int N);                   /* input: data vector length */ | ||||
|     int* data,                  /* output: data vector */ | ||||
|     Bitstr* streamdata,         /* in-/output struct containing bitstream */ | ||||
|     const uint16_t* const* cdf, /* input: array of cdf arrays */ | ||||
|     const uint16_t* | ||||
|         cdf_size, /* input: array of cdf table sizes+1 (power of two: 2^k) */ | ||||
|     const int N); /* input: data vector length */ | ||||
|  | ||||
| int WebRtcIsac_DecHistOneStepMulti( | ||||
|     int *data,                       /* output: data vector */ | ||||
|     Bitstr *streamdata,              /* in-/output struct containing bitstream */ | ||||
|     const uint16_t **cdf,      /* input: array of cdf arrays */ | ||||
|     const uint16_t *init_index,/* input: vector of initial cdf table search entries */ | ||||
|     const int N);                    /* input: data vector length */ | ||||
|     int* data,                  /* output: data vector */ | ||||
|     Bitstr* streamdata,         /* in-/output struct containing bitstream */ | ||||
|     const uint16_t* const* cdf, /* input: array of cdf arrays */ | ||||
|     const uint16_t* | ||||
|         init_index, /* input: vector of initial cdf table search entries */ | ||||
|     const int N);   /* input: data vector length */ | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ARITH_ROUTINES_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ARITH_ROUTINES_H_ */ | ||||
|   | ||||
| @@ -8,8 +8,8 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "settings.h" | ||||
| #include "arith_routines.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/arith_routines.h" | ||||
|  | ||||
|  | ||||
| /* | ||||
| @@ -17,7 +17,7 @@ | ||||
|  */ | ||||
| void WebRtcIsac_EncHistMulti(Bitstr *streamdata, /* in-/output struct containing bitstream */ | ||||
|                              const int *data,  /* input: data vector */ | ||||
|                              const uint16_t **cdf, /* input: array of cdf arrays */ | ||||
|                              const uint16_t *const *cdf, /* input: array of cdf arrays */ | ||||
|                              const int N)   /* input: data vector length */ | ||||
| { | ||||
|   uint32_t W_lower, W_upper; | ||||
| @@ -84,7 +84,7 @@ void WebRtcIsac_EncHistMulti(Bitstr *streamdata, /* in-/output struct containing | ||||
|  */ | ||||
| int WebRtcIsac_DecHistBisectMulti(int *data,     /* output: data vector */ | ||||
|                                   Bitstr *streamdata,   /* in-/output struct containing bitstream */ | ||||
|                                   const uint16_t **cdf,  /* input: array of cdf arrays */ | ||||
|                                   const uint16_t *const *cdf,  /* input: array of cdf arrays */ | ||||
|                                   const uint16_t *cdf_size, /* input: array of cdf table sizes+1 (power of two: 2^k) */ | ||||
|                                   const int N)    /* input: data vector length */ | ||||
| { | ||||
| @@ -192,7 +192,7 @@ int WebRtcIsac_DecHistBisectMulti(int *data,     /* output: data vector */ | ||||
|  */ | ||||
| int WebRtcIsac_DecHistOneStepMulti(int *data,        /* output: data vector */ | ||||
|                                    Bitstr *streamdata,      /* in-/output struct containing bitstream */ | ||||
|                                    const uint16_t **cdf,   /* input: array of cdf arrays */ | ||||
|                                    const uint16_t *const *cdf,   /* input: array of cdf arrays */ | ||||
|                                    const uint16_t *init_index, /* input: vector of initial cdf table search entries */ | ||||
|                                    const int N)     /* input: data vector length */ | ||||
| { | ||||
| @@ -214,10 +214,10 @@ int WebRtcIsac_DecHistOneStepMulti(int *data,        /* output: data vector */ | ||||
|   if (streamdata->stream_index == 0)   /* first time decoder is called for this stream */ | ||||
|   { | ||||
|     /* read first word from bytestream */ | ||||
|     streamval = *stream_ptr << 24; | ||||
|     streamval |= *++stream_ptr << 16; | ||||
|     streamval |= *++stream_ptr << 8; | ||||
|     streamval |= *++stream_ptr; | ||||
|     streamval = (uint32_t)(*stream_ptr) << 24; | ||||
|     streamval |= (uint32_t)(*++stream_ptr) << 16; | ||||
|     streamval |= (uint32_t)(*++stream_ptr) << 8; | ||||
|     streamval |= (uint32_t)(*++stream_ptr); | ||||
|   } else { | ||||
|     streamval = streamdata->streamval; | ||||
|   } | ||||
|   | ||||
| @@ -17,7 +17,7 @@ | ||||
|  */ | ||||
|  | ||||
|  | ||||
| #include "arith_routines.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/arith_routines.h" | ||||
|  | ||||
|  | ||||
|  | ||||
| @@ -185,11 +185,18 @@ int WebRtcIsac_DecLogisticMulti2( | ||||
|   int16_t     candQ7; | ||||
|   int             k; | ||||
|  | ||||
|   // Position just past the end of the stream. STREAM_SIZE_MAX_60 instead of | ||||
|   // STREAM_SIZE_MAX (which is the size of the allocated buffer) because that's | ||||
|   // the limit to how much data is filled in. | ||||
|   const uint8_t* const stream_end = streamdata->stream + STREAM_SIZE_MAX_60; | ||||
|  | ||||
|   stream_ptr = streamdata->stream + streamdata->stream_index; | ||||
|   W_upper = streamdata->W_upper; | ||||
|   if (streamdata->stream_index == 0)   /* first time decoder is called for this stream */ | ||||
|   { | ||||
|     /* read first word from bytestream */ | ||||
|     if (stream_ptr + 3 >= stream_end) | ||||
|       return -1;  // Would read out of bounds. Malformed input? | ||||
|     streamval = *stream_ptr << 24; | ||||
|     streamval |= *++stream_ptr << 16; | ||||
|     streamval |= *++stream_ptr << 8; | ||||
| @@ -277,6 +284,8 @@ int WebRtcIsac_DecLogisticMulti2( | ||||
|     while ( !(W_upper & 0xFF000000) )    /* W_upper < 2^24 */ | ||||
|     { | ||||
|       /* read next byte from stream */ | ||||
|       if (stream_ptr + 1 >= stream_end) | ||||
|         return -1;  // Would read out of bounds. Malformed input? | ||||
|       streamval = (streamval << 8) | *++stream_ptr; | ||||
|       W_upper <<= 8; | ||||
|     } | ||||
|   | ||||
| @@ -8,9 +8,9 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h" | ||||
|  | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/audio_decoder_isac_t_impl.h" | ||||
| #include "modules/audio_coding/codecs/isac/audio_decoder_isac_t_impl.h" | ||||
|  | ||||
| namespace webrtc { | ||||
|  | ||||
|   | ||||
| @@ -8,9 +8,9 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h" | ||||
|  | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h" | ||||
| #include "modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h" | ||||
|  | ||||
| namespace webrtc { | ||||
|  | ||||
|   | ||||
| @@ -16,14 +16,14 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include "bandwidth_estimator.h" | ||||
| #include "settings.h" | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/include/isac.h" | ||||
|  | ||||
| #include <assert.h> | ||||
| #include <math.h> | ||||
| #include <string.h> | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/include/isac.h" | ||||
| #include "rtc_base/checks.h" | ||||
|  | ||||
| /* array of quantization levels for bottle neck info; Matlab code: */ | ||||
| /* sprintf('%4.1ff, ', logspace(log10(5000), log10(40000), 12)) */ | ||||
| static const float kQRateTableWb[12] = | ||||
| @@ -159,7 +159,7 @@ int16_t WebRtcIsac_UpdateBandwidthEstimator( | ||||
|   int immediate_set = 0; | ||||
|   int num_pkts_expected; | ||||
|  | ||||
|   assert(!bwest_str->external_bw_info.in_use); | ||||
|   RTC_DCHECK(!bwest_str->external_bw_info.in_use); | ||||
|  | ||||
|   // We have to adjust the header-rate if the first packet has a | ||||
|   // frame-size different than the initialized value. | ||||
| @@ -514,7 +514,7 @@ int16_t WebRtcIsac_UpdateUplinkBwImpl( | ||||
|     int16_t               index, | ||||
|     enum IsacSamplingRate encoderSamplingFreq) | ||||
| { | ||||
|   assert(!bwest_str->external_bw_info.in_use); | ||||
|   RTC_DCHECK(!bwest_str->external_bw_info.in_use); | ||||
|  | ||||
|   if((index < 0) || (index > 23)) | ||||
|   { | ||||
| @@ -572,7 +572,7 @@ int16_t WebRtcIsac_UpdateUplinkJitter( | ||||
|     BwEstimatorstr*              bwest_str, | ||||
|     int32_t                  index) | ||||
| { | ||||
|   assert(!bwest_str->external_bw_info.in_use); | ||||
|   RTC_DCHECK(!bwest_str->external_bw_info.in_use); | ||||
|  | ||||
|   if((index < 0) || (index > 23)) | ||||
|   { | ||||
| @@ -711,7 +711,7 @@ int32_t WebRtcIsac_GetDownlinkBandwidth( const BwEstimatorstr *bwest_str) | ||||
|   float   jitter_sign; | ||||
|   float   bw_adjust; | ||||
|  | ||||
|   assert(!bwest_str->external_bw_info.in_use); | ||||
|   RTC_DCHECK(!bwest_str->external_bw_info.in_use); | ||||
|  | ||||
|   /* create a value between -1.0 and 1.0 indicating "average sign" of jitter */ | ||||
|   jitter_sign = bwest_str->rec_jitter_short_term / | ||||
| @@ -741,7 +741,7 @@ WebRtcIsac_GetDownlinkMaxDelay(const BwEstimatorstr *bwest_str) | ||||
| { | ||||
|   int32_t rec_max_delay; | ||||
|  | ||||
|   assert(!bwest_str->external_bw_info.in_use); | ||||
|   RTC_DCHECK(!bwest_str->external_bw_info.in_use); | ||||
|  | ||||
|   rec_max_delay = (int32_t)(bwest_str->rec_max_delay); | ||||
|  | ||||
| @@ -759,7 +759,7 @@ WebRtcIsac_GetDownlinkMaxDelay(const BwEstimatorstr *bwest_str) | ||||
|  | ||||
| /* Clamp val to the closed interval [min,max]. */ | ||||
| static int32_t clamp(int32_t val, int32_t min, int32_t max) { | ||||
|   assert(min <= max); | ||||
|   RTC_DCHECK_LE(min, max); | ||||
|   return val < min ? min : (val > max ? max : val); | ||||
| } | ||||
|  | ||||
| @@ -775,24 +775,6 @@ int32_t WebRtcIsac_GetUplinkMaxDelay(const BwEstimatorstr* bwest_str) { | ||||
|              : clamp(bwest_str->send_max_delay_avg, MIN_ISAC_MD, MAX_ISAC_MD); | ||||
| } | ||||
|  | ||||
| void WebRtcIsacBw_GetBandwidthInfo(BwEstimatorstr* bwest_str, | ||||
|                                    enum IsacSamplingRate decoder_sample_rate_hz, | ||||
|                                    IsacBandwidthInfo* bwinfo) { | ||||
|   assert(!bwest_str->external_bw_info.in_use); | ||||
|   bwinfo->in_use = 1; | ||||
|   bwinfo->send_bw_avg = WebRtcIsac_GetUplinkBandwidth(bwest_str); | ||||
|   bwinfo->send_max_delay_avg = WebRtcIsac_GetUplinkMaxDelay(bwest_str); | ||||
|   WebRtcIsac_GetDownlinkBwJitIndexImpl(bwest_str, &bwinfo->bottleneck_idx, | ||||
|                                        &bwinfo->jitter_info, | ||||
|                                        decoder_sample_rate_hz); | ||||
| } | ||||
|  | ||||
| void WebRtcIsacBw_SetBandwidthInfo(BwEstimatorstr* bwest_str, | ||||
|                                    const IsacBandwidthInfo* bwinfo) { | ||||
|   memcpy(&bwest_str->external_bw_info, bwinfo, | ||||
|          sizeof bwest_str->external_bw_info); | ||||
| } | ||||
|  | ||||
| /* | ||||
|  * update long-term average bitrate and amount of data in buffer | ||||
|  * returns minimum payload size (bytes) | ||||
|   | ||||
| @@ -16,169 +16,150 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ | ||||
|  | ||||
| #include "structs.h" | ||||
| #include "settings.h" | ||||
| #include <stddef.h> | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
|  | ||||
| #define MIN_ISAC_BW     10000 | ||||
| #define MIN_ISAC_BW_LB  10000 | ||||
| #define MIN_ISAC_BW_UB  25000 | ||||
| #define MIN_ISAC_BW 10000 | ||||
| #define MIN_ISAC_BW_LB 10000 | ||||
| #define MIN_ISAC_BW_UB 25000 | ||||
|  | ||||
| #define MAX_ISAC_BW     56000 | ||||
| #define MAX_ISAC_BW_UB  32000 | ||||
| #define MAX_ISAC_BW_LB  32000 | ||||
| #define MAX_ISAC_BW 56000 | ||||
| #define MAX_ISAC_BW_UB 32000 | ||||
| #define MAX_ISAC_BW_LB 32000 | ||||
|  | ||||
| #define MIN_ISAC_MD     5 | ||||
| #define MAX_ISAC_MD     25 | ||||
| #define MIN_ISAC_MD 5 | ||||
| #define MAX_ISAC_MD 25 | ||||
|  | ||||
| // assumed header size, in bytes; we don't know the exact number | ||||
| // (header compression may be used) | ||||
| #define HEADER_SIZE        35 | ||||
| #define HEADER_SIZE 35 | ||||
|  | ||||
| // Initial Frame-Size, in ms, for Wideband & Super-Wideband Mode | ||||
| #define INIT_FRAME_LEN_WB  60 | ||||
| #define INIT_FRAME_LEN_WB 60 | ||||
| #define INIT_FRAME_LEN_SWB 30 | ||||
|  | ||||
| // Initial Bottleneck Estimate, in bits/sec, for | ||||
| // Wideband & Super-wideband mode | ||||
| #define INIT_BN_EST_WB     20e3f | ||||
| #define INIT_BN_EST_SWB    56e3f | ||||
| #define INIT_BN_EST_WB 20e3f | ||||
| #define INIT_BN_EST_SWB 56e3f | ||||
|  | ||||
| // Initial Header rate (header rate depends on frame-size), | ||||
| // in bits/sec, for Wideband & Super-Wideband mode. | ||||
| #define INIT_HDR_RATE_WB                                                \ | ||||
| #define INIT_HDR_RATE_WB \ | ||||
|   ((float)HEADER_SIZE * 8.0f * 1000.0f / (float)INIT_FRAME_LEN_WB) | ||||
| #define INIT_HDR_RATE_SWB                                               \ | ||||
| #define INIT_HDR_RATE_SWB \ | ||||
|   ((float)HEADER_SIZE * 8.0f * 1000.0f / (float)INIT_FRAME_LEN_SWB) | ||||
|  | ||||
| // number of packets in a row for a high rate burst | ||||
| #define BURST_LEN       3 | ||||
| #define BURST_LEN 3 | ||||
|  | ||||
| // ms, max time between two full bursts | ||||
| #define BURST_INTERVAL  500 | ||||
| #define BURST_INTERVAL 500 | ||||
|  | ||||
| // number of packets in a row for initial high rate burst | ||||
| #define INIT_BURST_LEN  5 | ||||
| #define INIT_BURST_LEN 5 | ||||
|  | ||||
| // bits/s, rate for the first BURST_LEN packets | ||||
| #define INIT_RATE_WB       INIT_BN_EST_WB | ||||
| #define INIT_RATE_SWB      INIT_BN_EST_SWB | ||||
|  | ||||
| #define INIT_RATE_WB INIT_BN_EST_WB | ||||
| #define INIT_RATE_SWB INIT_BN_EST_SWB | ||||
|  | ||||
| #if defined(__cplusplus) | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
|   /* This function initializes the struct                    */ | ||||
|   /* to be called before using the struct for anything else  */ | ||||
|   /* returns 0 if everything went fine, -1 otherwise         */ | ||||
|   int32_t WebRtcIsac_InitBandwidthEstimator( | ||||
|       BwEstimatorstr*           bwest_str, | ||||
|       enum IsacSamplingRate encoderSampRate, | ||||
|       enum IsacSamplingRate decoderSampRate); | ||||
| /* This function initializes the struct                    */ | ||||
| /* to be called before using the struct for anything else  */ | ||||
| /* returns 0 if everything went fine, -1 otherwise         */ | ||||
| int32_t WebRtcIsac_InitBandwidthEstimator( | ||||
|     BwEstimatorstr* bwest_str, | ||||
|     enum IsacSamplingRate encoderSampRate, | ||||
|     enum IsacSamplingRate decoderSampRate); | ||||
|  | ||||
|   /* This function updates the receiving estimate                                                      */ | ||||
|   /* Parameters:                                                                                       */ | ||||
|   /* rtp_number    - value from RTP packet, from NetEq                                                 */ | ||||
|   /* frame length  - length of signal frame in ms, from iSAC decoder                                   */ | ||||
|   /* send_ts       - value in RTP header giving send time in samples                                   */ | ||||
|   /* arr_ts        - value given by timeGetTime() time of arrival in samples of packet from NetEq      */ | ||||
|   /* pksize        - size of packet in bytes, from NetEq                                               */ | ||||
|   /* Index         - integer (range 0...23) indicating bottle neck & jitter as estimated by other side */ | ||||
|   /* returns 0 if everything went fine, -1 otherwise                                                   */ | ||||
|   int16_t WebRtcIsac_UpdateBandwidthEstimator( | ||||
|       BwEstimatorstr* bwest_str, | ||||
|       const uint16_t rtp_number, | ||||
|       const int32_t frame_length, | ||||
|       const uint32_t send_ts, | ||||
|       const uint32_t arr_ts, | ||||
|       const size_t pksize); | ||||
| /* This function updates the receiving estimate */ | ||||
| /* Parameters: */ | ||||
| /* rtp_number    - value from RTP packet, from NetEq */ | ||||
| /* frame length  - length of signal frame in ms, from iSAC decoder */ | ||||
| /* send_ts       - value in RTP header giving send time in samples */ | ||||
| /* arr_ts        - value given by timeGetTime() time of arrival in samples of | ||||
|  * packet from NetEq      */ | ||||
| /* pksize        - size of packet in bytes, from NetEq */ | ||||
| /* Index         - integer (range 0...23) indicating bottle neck & jitter as | ||||
|  * estimated by other side */ | ||||
| /* returns 0 if everything went fine, -1 otherwise */ | ||||
| int16_t WebRtcIsac_UpdateBandwidthEstimator(BwEstimatorstr* bwest_str, | ||||
|                                             const uint16_t rtp_number, | ||||
|                                             const int32_t frame_length, | ||||
|                                             const uint32_t send_ts, | ||||
|                                             const uint32_t arr_ts, | ||||
|                                             const size_t pksize); | ||||
|  | ||||
|   /* Update receiving estimates. Used when we only receive BWE index, no iSAC data packet. */ | ||||
|   int16_t WebRtcIsac_UpdateUplinkBwImpl( | ||||
|       BwEstimatorstr*           bwest_str, | ||||
|       int16_t               Index, | ||||
|       enum IsacSamplingRate encoderSamplingFreq); | ||||
| /* Update receiving estimates. Used when we only receive BWE index, no iSAC data | ||||
|  * packet. */ | ||||
| int16_t WebRtcIsac_UpdateUplinkBwImpl( | ||||
|     BwEstimatorstr* bwest_str, | ||||
|     int16_t Index, | ||||
|     enum IsacSamplingRate encoderSamplingFreq); | ||||
|  | ||||
|   /* Returns the bandwidth/jitter estimation code (integer 0...23) to put in the sending iSAC payload */ | ||||
|   void WebRtcIsac_GetDownlinkBwJitIndexImpl( | ||||
|       BwEstimatorstr* bwest_str, | ||||
|       int16_t* bottleneckIndex, | ||||
|       int16_t* jitterInfo, | ||||
|       enum IsacSamplingRate decoderSamplingFreq); | ||||
| /* Returns the bandwidth/jitter estimation code (integer 0...23) to put in the | ||||
|  * sending iSAC payload */ | ||||
| void WebRtcIsac_GetDownlinkBwJitIndexImpl( | ||||
|     BwEstimatorstr* bwest_str, | ||||
|     int16_t* bottleneckIndex, | ||||
|     int16_t* jitterInfo, | ||||
|     enum IsacSamplingRate decoderSamplingFreq); | ||||
|  | ||||
|   /* Returns the bandwidth estimation (in bps) */ | ||||
|   int32_t WebRtcIsac_GetDownlinkBandwidth( | ||||
|       const BwEstimatorstr *bwest_str); | ||||
| /* Returns the bandwidth estimation (in bps) */ | ||||
| int32_t WebRtcIsac_GetDownlinkBandwidth(const BwEstimatorstr* bwest_str); | ||||
|  | ||||
|   /* Returns the max delay (in ms) */ | ||||
|   int32_t WebRtcIsac_GetDownlinkMaxDelay( | ||||
|       const BwEstimatorstr *bwest_str); | ||||
| /* Returns the max delay (in ms) */ | ||||
| int32_t WebRtcIsac_GetDownlinkMaxDelay(const BwEstimatorstr* bwest_str); | ||||
|  | ||||
|   /* Returns the bandwidth that iSAC should send with in bps */ | ||||
|   int32_t WebRtcIsac_GetUplinkBandwidth(const BwEstimatorstr* bwest_str); | ||||
| /* Returns the bandwidth that iSAC should send with in bps */ | ||||
| int32_t WebRtcIsac_GetUplinkBandwidth(const BwEstimatorstr* bwest_str); | ||||
|  | ||||
|   /* Returns the max delay value from the other side in ms */ | ||||
|   int32_t WebRtcIsac_GetUplinkMaxDelay( | ||||
|       const BwEstimatorstr *bwest_str); | ||||
| /* Returns the max delay value from the other side in ms */ | ||||
| int32_t WebRtcIsac_GetUplinkMaxDelay(const BwEstimatorstr* bwest_str); | ||||
|  | ||||
|   /* Fills in an IsacExternalBandwidthInfo struct. */ | ||||
|   void WebRtcIsacBw_GetBandwidthInfo( | ||||
|       BwEstimatorstr* bwest_str, | ||||
|       enum IsacSamplingRate decoder_sample_rate_hz, | ||||
|       IsacBandwidthInfo* bwinfo); | ||||
| /* | ||||
|  * update amount of data in bottle neck buffer and burst handling | ||||
|  * returns minimum payload size (bytes) | ||||
|  */ | ||||
| int WebRtcIsac_GetMinBytes( | ||||
|     RateModel* State, | ||||
|     int StreamSize,            /* bytes in bitstream */ | ||||
|     const int FrameLen,        /* ms per frame */ | ||||
|     const double BottleNeck,   /* bottle neck rate; excl headers (bps) */ | ||||
|     const double DelayBuildUp, /* max delay from bottleneck buffering (ms) */ | ||||
|     enum ISACBandwidth bandwidth | ||||
|     /*,int16_t        frequentLargePackets*/); | ||||
|  | ||||
|   /* Uses the values from an IsacExternalBandwidthInfo struct. */ | ||||
|   void WebRtcIsacBw_SetBandwidthInfo(BwEstimatorstr* bwest_str, | ||||
|                                      const IsacBandwidthInfo* bwinfo); | ||||
| /* | ||||
|  * update long-term average bitrate and amount of data in buffer | ||||
|  */ | ||||
| void WebRtcIsac_UpdateRateModel( | ||||
|     RateModel* State, | ||||
|     int StreamSize,           /* bytes in bitstream */ | ||||
|     const int FrameSamples,   /* samples per frame */ | ||||
|     const double BottleNeck); /* bottle neck rate; excl headers (bps) */ | ||||
|  | ||||
|   /* | ||||
|    * update amount of data in bottle neck buffer and burst handling | ||||
|    * returns minimum payload size (bytes) | ||||
|    */ | ||||
|   int WebRtcIsac_GetMinBytes( | ||||
|       RateModel*         State, | ||||
|       int                StreamSize,    /* bytes in bitstream */ | ||||
|       const int          FrameLen,      /* ms per frame */ | ||||
|       const double       BottleNeck,    /* bottle neck rate; excl headers (bps) */ | ||||
|       const double       DelayBuildUp,  /* max delay from bottleneck buffering (ms) */ | ||||
|       enum ISACBandwidth bandwidth | ||||
|       /*,int16_t        frequentLargePackets*/); | ||||
| void WebRtcIsac_InitRateModel(RateModel* State); | ||||
|  | ||||
|   /* | ||||
|    * update long-term average bitrate and amount of data in buffer | ||||
|    */ | ||||
|   void WebRtcIsac_UpdateRateModel( | ||||
|       RateModel*   State, | ||||
|       int          StreamSize,                /* bytes in bitstream */ | ||||
|       const int    FrameSamples,        /* samples per frame */ | ||||
|       const double BottleNeck);       /* bottle neck rate; excl headers (bps) */ | ||||
| /* Returns the new framelength value (input argument: bottle_neck) */ | ||||
| int WebRtcIsac_GetNewFrameLength(double bottle_neck, int current_framelength); | ||||
|  | ||||
| /* Returns the new SNR value (input argument: bottle_neck) */ | ||||
| double WebRtcIsac_GetSnr(double bottle_neck, int new_framelength); | ||||
|  | ||||
|   void WebRtcIsac_InitRateModel( | ||||
|       RateModel *State); | ||||
|  | ||||
|   /* Returns the new framelength value (input argument: bottle_neck) */ | ||||
|   int WebRtcIsac_GetNewFrameLength( | ||||
|       double bottle_neck, | ||||
|       int    current_framelength); | ||||
|  | ||||
|   /* Returns the new SNR value (input argument: bottle_neck) */ | ||||
|   double WebRtcIsac_GetSnr( | ||||
|       double bottle_neck, | ||||
|       int    new_framelength); | ||||
|  | ||||
|  | ||||
|   int16_t WebRtcIsac_UpdateUplinkJitter( | ||||
|       BwEstimatorstr*              bwest_str, | ||||
|       int32_t                  index); | ||||
| int16_t WebRtcIsac_UpdateUplinkJitter(BwEstimatorstr* bwest_str, int32_t index); | ||||
|  | ||||
| #if defined(__cplusplus) | ||||
| } | ||||
| #endif | ||||
|  | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ \ | ||||
|         */ | ||||
|   | ||||
| @@ -16,18 +16,22 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ | ||||
|  | ||||
| #include "structs.h" | ||||
| #include <stddef.h> | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
| #include "modules/third_party/fft/fft.h" | ||||
|  | ||||
| void WebRtcIsac_ResetBitstream(Bitstr* bit_stream); | ||||
|  | ||||
| int WebRtcIsac_EstimateBandwidth(BwEstimatorstr* bwest_str, Bitstr* streamdata, | ||||
| int WebRtcIsac_EstimateBandwidth(BwEstimatorstr* bwest_str, | ||||
|                                  Bitstr* streamdata, | ||||
|                                  size_t packet_size, | ||||
|                                  uint16_t rtp_seq_number, | ||||
|                                  uint32_t send_ts, uint32_t arr_ts, | ||||
|                                  uint32_t send_ts, | ||||
|                                  uint32_t arr_ts, | ||||
|                                  enum IsacSamplingRate encoderSampRate, | ||||
|                                  enum IsacSamplingRate decoderSampRate); | ||||
|  | ||||
| @@ -37,7 +41,8 @@ int WebRtcIsac_DecodeLb(const TransformTables* transform_tables, | ||||
|                         int16_t* current_framesamples, | ||||
|                         int16_t isRCUPayload); | ||||
|  | ||||
| int WebRtcIsac_DecodeRcuLb(float* signal_out, ISACLBDecStruct* ISACdec_obj, | ||||
| int WebRtcIsac_DecodeRcuLb(float* signal_out, | ||||
|                            ISACLBDecStruct* ISACdec_obj, | ||||
|                            int16_t* current_framesamples); | ||||
|  | ||||
| int WebRtcIsac_EncodeLb(const TransformTables* transform_tables, | ||||
| @@ -47,15 +52,20 @@ int WebRtcIsac_EncodeLb(const TransformTables* transform_tables, | ||||
|                         int16_t bottleneckIndex); | ||||
|  | ||||
| int WebRtcIsac_EncodeStoredDataLb(const IsacSaveEncoderData* ISACSavedEnc_obj, | ||||
|                                   Bitstr* ISACBitStr_obj, int BWnumber, | ||||
|                                   Bitstr* ISACBitStr_obj, | ||||
|                                   int BWnumber, | ||||
|                                   float scale); | ||||
|  | ||||
| int WebRtcIsac_EncodeStoredDataUb( | ||||
|     const ISACUBSaveEncDataStruct* ISACSavedEnc_obj, Bitstr* bitStream, | ||||
|     int32_t jitterInfo, float scale, enum ISACBandwidth bandwidth); | ||||
|     const ISACUBSaveEncDataStruct* ISACSavedEnc_obj, | ||||
|     Bitstr* bitStream, | ||||
|     int32_t jitterInfo, | ||||
|     float scale, | ||||
|     enum ISACBandwidth bandwidth); | ||||
|  | ||||
| int16_t WebRtcIsac_GetRedPayloadUb( | ||||
|     const ISACUBSaveEncDataStruct* ISACSavedEncObj, Bitstr* bitStreamObj, | ||||
|     const ISACUBSaveEncDataStruct* ISACSavedEncObj, | ||||
|     Bitstr* bitStreamObj, | ||||
|     enum ISACBandwidth bandwidth); | ||||
|  | ||||
| /****************************************************************************** | ||||
| @@ -81,7 +91,6 @@ int16_t WebRtcIsac_RateAllocation(int32_t inRateBitPerSec, | ||||
|                                   double* rateUBBitPerSec, | ||||
|                                   enum ISACBandwidth* bandwidthKHz); | ||||
|  | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_DecodeUb16() | ||||
|  * | ||||
| @@ -166,15 +175,8 @@ int WebRtcIsac_EncodeUb12(const TransformTables* transform_tables, | ||||
|  | ||||
| void WebRtcIsac_InitMasking(MaskFiltstr* maskdata); | ||||
|  | ||||
| void WebRtcIsac_InitPreFilterbank(PreFiltBankstr* prefiltdata); | ||||
|  | ||||
| void WebRtcIsac_InitPostFilterbank(PostFiltBankstr* postfiltdata); | ||||
|  | ||||
| void WebRtcIsac_InitPitchFilter(PitchFiltstr* pitchfiltdata); | ||||
|  | ||||
| void WebRtcIsac_InitPitchAnalysis(PitchAnalysisStruct* State); | ||||
|  | ||||
|  | ||||
| /**************************** transform functions ****************************/ | ||||
|  | ||||
| void WebRtcIsac_InitTransform(TransformTables* tables); | ||||
| @@ -193,41 +195,29 @@ void WebRtcIsac_Spec2time(const TransformTables* tables, | ||||
|                           double* outre2, | ||||
|                           FFTstr* fftstr_obj); | ||||
|  | ||||
| /******************************* filter functions ****************************/ | ||||
|  | ||||
| void WebRtcIsac_AllPoleFilter(double* InOut, double* Coef, size_t lengthInOut, | ||||
|                               int orderCoef); | ||||
|  | ||||
| void WebRtcIsac_AllZeroFilter(double* In, double* Coef, size_t lengthInOut, | ||||
|                               int orderCoef, double* Out); | ||||
|  | ||||
| void WebRtcIsac_ZeroPoleFilter(double* In, double* ZeroCoef, double* PoleCoef, | ||||
|                                size_t lengthInOut, int orderCoef, double* Out); | ||||
|  | ||||
|  | ||||
| /***************************** filterbank functions **************************/ | ||||
|  | ||||
| void WebRtcIsac_SplitAndFilterFloat(float* in, float* LP, float* HP, | ||||
|                                     double* LP_la, double* HP_la, | ||||
|                                     PreFiltBankstr* prefiltdata); | ||||
|  | ||||
|  | ||||
| void WebRtcIsac_FilterAndCombineFloat(float* InLP, float* InHP, float* Out, | ||||
| void WebRtcIsac_FilterAndCombineFloat(float* InLP, | ||||
|                                       float* InHP, | ||||
|                                       float* Out, | ||||
|                                       PostFiltBankstr* postfiltdata); | ||||
|  | ||||
|  | ||||
| /************************* normalized lattice filters ************************/ | ||||
|  | ||||
| void WebRtcIsac_NormLatticeFilterMa(int orderCoef, float* stateF, float* stateG, | ||||
|                                     float* lat_in, double* filtcoeflo, | ||||
| void WebRtcIsac_NormLatticeFilterMa(int orderCoef, | ||||
|                                     float* stateF, | ||||
|                                     float* stateG, | ||||
|                                     float* lat_in, | ||||
|                                     double* filtcoeflo, | ||||
|                                     double* lat_out); | ||||
|  | ||||
| void WebRtcIsac_NormLatticeFilterAr(int orderCoef, float* stateF, float* stateG, | ||||
|                                     double* lat_in, double* lo_filt_coef, | ||||
| void WebRtcIsac_NormLatticeFilterAr(int orderCoef, | ||||
|                                     float* stateF, | ||||
|                                     float* stateG, | ||||
|                                     double* lat_in, | ||||
|                                     double* lo_filt_coef, | ||||
|                                     float* lat_out); | ||||
|  | ||||
| void WebRtcIsac_Dir2Lat(double* a, int orderCoef, float* sth, float* cth); | ||||
|  | ||||
| void WebRtcIsac_AutoCorr(double* r, const double* x, size_t N, size_t order); | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ */ | ||||
|   | ||||
| @@ -8,9 +8,10 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "crc.h" | ||||
| #include <stdlib.h> | ||||
| #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/crc.h" | ||||
| #include "common_audio/signal_processing/include/signal_processing_library.h" | ||||
|  | ||||
| #define POLYNOMIAL 0x04c11db7L | ||||
|  | ||||
|   | ||||
| @@ -15,10 +15,10 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ | ||||
|  | ||||
| #include "webrtc/typedefs.h" | ||||
| #include <stdint.h> | ||||
|  | ||||
| /**************************************************************************** | ||||
|  * WebRtcIsac_GetCrc(...) | ||||
| @@ -36,11 +36,6 @@ | ||||
|  *                   -1 - Error | ||||
|  */ | ||||
|  | ||||
| int WebRtcIsac_GetCrc( | ||||
|     const int16_t* encoded, | ||||
|     int no_of_word8s, | ||||
|     uint32_t* crc); | ||||
| int WebRtcIsac_GetCrc(const int16_t* encoded, int no_of_word8s, uint32_t* crc); | ||||
|  | ||||
|  | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ */ | ||||
|   | ||||
| @@ -18,18 +18,17 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
|  | ||||
| #include "codec.h" | ||||
| #include "entropy_coding.h" | ||||
| #include "pitch_estimator.h" | ||||
| #include "bandwidth_estimator.h" | ||||
| #include "structs.h" | ||||
| #include "settings.h" | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/codec.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_estimator.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_filter.h" | ||||
|  | ||||
| /* | ||||
|  * function to decode the bitstream | ||||
|   | ||||
| @@ -8,10 +8,10 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "structs.h" | ||||
| #include "bandwidth_estimator.h" | ||||
| #include "entropy_coding.h" | ||||
| #include "codec.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/codec.h" | ||||
|  | ||||
|  | ||||
| int | ||||
|   | ||||
| @@ -21,20 +21,22 @@ | ||||
| #include <string.h> | ||||
| #include <stdio.h> | ||||
|  | ||||
| #include "structs.h" | ||||
| #include "codec.h" | ||||
| #include "pitch_estimator.h" | ||||
| #include "entropy_coding.h" | ||||
| #include "arith_routines.h" | ||||
| #include "pitch_gain_tables.h" | ||||
| #include "pitch_lag_tables.h" | ||||
| #include "spectrum_ar_model_tables.h" | ||||
| #include "lpc_tables.h" | ||||
| #include "lpc_analysis.h" | ||||
| #include "bandwidth_estimator.h" | ||||
| #include "lpc_shape_swb12_tables.h" | ||||
| #include "lpc_shape_swb16_tables.h" | ||||
| #include "lpc_gain_swb_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/codec.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_estimator.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/arith_routines.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_analysis.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/isac_vad.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_filter.h" | ||||
|  | ||||
|  | ||||
| #define UB_LOOKAHEAD 24 | ||||
|   | ||||
| @@ -16,17 +16,15 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include "encode_lpc_swb.h" | ||||
|  | ||||
| #include <math.h> | ||||
| #include <stdio.h> | ||||
| #include <string.h> | ||||
|  | ||||
| #include "lpc_gain_swb_tables.h" | ||||
| #include "lpc_shape_swb12_tables.h" | ||||
| #include "lpc_shape_swb16_tables.h" | ||||
| #include "settings.h" | ||||
| #include "webrtc/typedefs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_RemoveLarMean() | ||||
|   | ||||
| @@ -16,12 +16,11 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_ | ||||
|  | ||||
| #include "settings.h" | ||||
| #include "structs.h" | ||||
| #include "webrtc/typedefs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_RemoveLarMean() | ||||
| @@ -39,9 +38,7 @@ | ||||
|  * | ||||
|  * | ||||
|  */ | ||||
| int16_t WebRtcIsac_RemoveLarMean( | ||||
|     double*     lar, | ||||
|     int16_t bandwidth); | ||||
| int16_t WebRtcIsac_RemoveLarMean(double* lar, int16_t bandwidth); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_DecorrelateIntraVec() | ||||
| @@ -59,11 +56,9 @@ int16_t WebRtcIsac_RemoveLarMean( | ||||
|  * Output: | ||||
|  *      -out                : decorrelated LAR vectors. | ||||
|  */ | ||||
| int16_t WebRtcIsac_DecorrelateIntraVec( | ||||
|     const double* inLAR, | ||||
|     double*       out, | ||||
|     int16_t   bandwidth); | ||||
|  | ||||
| int16_t WebRtcIsac_DecorrelateIntraVec(const double* inLAR, | ||||
|                                        double* out, | ||||
|                                        int16_t bandwidth); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_DecorrelateInterVec() | ||||
| @@ -82,11 +77,9 @@ int16_t WebRtcIsac_DecorrelateIntraVec( | ||||
|  * Output: | ||||
|  *      -out                : decorrelated LAR vectors. | ||||
|  */ | ||||
| int16_t WebRtcIsac_DecorrelateInterVec( | ||||
|     const double* data, | ||||
|     double*       out, | ||||
|     int16_t   bandwidth); | ||||
|  | ||||
| int16_t WebRtcIsac_DecorrelateInterVec(const double* data, | ||||
|                                        double* out, | ||||
|                                        int16_t bandwidth); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_QuantizeUncorrLar() | ||||
| @@ -102,11 +95,7 @@ int16_t WebRtcIsac_DecorrelateInterVec( | ||||
|  *      -data               : quantized version of the input. | ||||
|  *      -idx                : pointer to quantization indices. | ||||
|  */ | ||||
| double WebRtcIsac_QuantizeUncorrLar( | ||||
|     double*     data, | ||||
|     int*        idx, | ||||
|     int16_t bandwidth); | ||||
|  | ||||
| double WebRtcIsac_QuantizeUncorrLar(double* data, int* idx, int16_t bandwidth); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_CorrelateIntraVec() | ||||
| @@ -121,11 +110,9 @@ double WebRtcIsac_QuantizeUncorrLar( | ||||
|  * Output: | ||||
|  *      -out                : correlated parametrs. | ||||
|  */ | ||||
| int16_t WebRtcIsac_CorrelateIntraVec( | ||||
|     const double* data, | ||||
|     double*       out, | ||||
|     int16_t   bandwidth); | ||||
|  | ||||
| int16_t WebRtcIsac_CorrelateIntraVec(const double* data, | ||||
|                                      double* out, | ||||
|                                      int16_t bandwidth); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_CorrelateInterVec() | ||||
| @@ -140,17 +127,15 @@ int16_t WebRtcIsac_CorrelateIntraVec( | ||||
|  * Output: | ||||
|  *      -out                : correlated parametrs. | ||||
|  */ | ||||
| int16_t WebRtcIsac_CorrelateInterVec( | ||||
|     const double* data, | ||||
|     double*       out, | ||||
|     int16_t   bandwidth); | ||||
|  | ||||
| int16_t WebRtcIsac_CorrelateInterVec(const double* data, | ||||
|                                      double* out, | ||||
|                                      int16_t bandwidth); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_AddLarMean() | ||||
|  * | ||||
|  * This is the inverse of WebRtcIsac_RemoveLarMean() | ||||
|  *  | ||||
|  * | ||||
|  * Input: | ||||
|  *      -data               : pointer to mean-removed LAR:s. | ||||
|  *      -bandwidth          : indicates if the given LAR vectors belong | ||||
| @@ -159,10 +144,7 @@ int16_t WebRtcIsac_CorrelateInterVec( | ||||
|  * Output: | ||||
|  *      -data               : pointer to LARs. | ||||
|  */ | ||||
| int16_t WebRtcIsac_AddLarMean( | ||||
|     double*     data, | ||||
|     int16_t bandwidth); | ||||
|  | ||||
| int16_t WebRtcIsac_AddLarMean(double* data, int16_t bandwidth); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_DequantizeLpcParam() | ||||
| @@ -177,11 +159,9 @@ int16_t WebRtcIsac_AddLarMean( | ||||
|  * Output: | ||||
|  *      -out                : pointer to quantized values. | ||||
|  */ | ||||
| int16_t WebRtcIsac_DequantizeLpcParam( | ||||
|     const int*  idx, | ||||
|     double*     out, | ||||
|     int16_t bandwidth); | ||||
|  | ||||
| int16_t WebRtcIsac_DequantizeLpcParam(const int* idx, | ||||
|                                       double* out, | ||||
|                                       int16_t bandwidth); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_ToLogDomainRemoveMean() | ||||
| @@ -194,9 +174,7 @@ int16_t WebRtcIsac_DequantizeLpcParam( | ||||
|  * Output: | ||||
|  *      -lpcGain            : mean-removed in log domain. | ||||
|  */ | ||||
| int16_t WebRtcIsac_ToLogDomainRemoveMean( | ||||
|     double* lpGains); | ||||
|  | ||||
| int16_t WebRtcIsac_ToLogDomainRemoveMean(double* lpGains); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_DecorrelateLPGain() | ||||
| @@ -210,16 +188,13 @@ int16_t WebRtcIsac_ToLogDomainRemoveMean( | ||||
|  * Output: | ||||
|  *      -out                : decorrelated parameters. | ||||
|  */ | ||||
| int16_t WebRtcIsac_DecorrelateLPGain( | ||||
|     const double* data, | ||||
|     double*       out); | ||||
|  | ||||
| int16_t WebRtcIsac_DecorrelateLPGain(const double* data, double* out); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_QuantizeLpcGain() | ||||
|  * | ||||
|  * Quantize the decorrelated log-domain gains. | ||||
|  *  | ||||
|  * | ||||
|  * Input: | ||||
|  *      -lpcGain            : uncorrelated LPC gains. | ||||
|  * | ||||
| @@ -227,10 +202,7 @@ int16_t WebRtcIsac_DecorrelateLPGain( | ||||
|  *      -idx                : quantization indices | ||||
|  *      -lpcGain            : quantized value of the inpt. | ||||
|  */ | ||||
| double WebRtcIsac_QuantizeLpcGain( | ||||
|     double* lpGains, | ||||
|     int*    idx); | ||||
|  | ||||
| double WebRtcIsac_QuantizeLpcGain(double* lpGains, int* idx); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_DequantizeLpcGain() | ||||
| @@ -243,10 +215,7 @@ double WebRtcIsac_QuantizeLpcGain( | ||||
|  * Output: | ||||
|  *      -lpcGains           : quantized values of the given parametes. | ||||
|  */ | ||||
| int16_t WebRtcIsac_DequantizeLpcGain( | ||||
|     const int* idx, | ||||
|     double*    lpGains); | ||||
|  | ||||
| int16_t WebRtcIsac_DequantizeLpcGain(const int* idx, double* lpGains); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_CorrelateLpcGain() | ||||
| @@ -259,10 +228,7 @@ int16_t WebRtcIsac_DequantizeLpcGain( | ||||
|  * Output: | ||||
|  *      -out                : correlated parameters. | ||||
|  */ | ||||
| int16_t WebRtcIsac_CorrelateLpcGain( | ||||
|     const double* data, | ||||
|     double*       out); | ||||
|  | ||||
| int16_t WebRtcIsac_CorrelateLpcGain(const double* data, double* out); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_AddMeanToLinearDomain() | ||||
| @@ -275,8 +241,6 @@ int16_t WebRtcIsac_CorrelateLpcGain( | ||||
|  * Output: | ||||
|  *      -lpcGain            : LPC gain in normal domain. | ||||
|  */ | ||||
| int16_t WebRtcIsac_AddMeanToLinearDomain( | ||||
|     double* lpcGains); | ||||
| int16_t WebRtcIsac_AddMeanToLinearDomain(double* lpcGains); | ||||
|  | ||||
|  | ||||
| #endif  // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_ | ||||
| #endif  // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_ | ||||
|   | ||||
| @@ -17,19 +17,19 @@ | ||||
|  */ | ||||
|  | ||||
|  | ||||
| #include "entropy_coding.h" | ||||
| #include "settings.h" | ||||
| #include "arith_routines.h" | ||||
| #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" | ||||
| #include "spectrum_ar_model_tables.h" | ||||
| #include "lpc_tables.h" | ||||
| #include "pitch_gain_tables.h" | ||||
| #include "pitch_lag_tables.h" | ||||
| #include "encode_lpc_swb.h" | ||||
| #include "lpc_shape_swb12_tables.h" | ||||
| #include "lpc_shape_swb16_tables.h" | ||||
| #include "lpc_gain_swb_tables.h" | ||||
| #include "os_specific_inline.h" | ||||
| #include "common_audio/signal_processing/include/signal_processing_library.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/arith_routines.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/os_specific_inline.h" | ||||
|  | ||||
| #include <math.h> | ||||
| #include <string.h> | ||||
| @@ -42,7 +42,7 @@ static const uint16_t kOneBitEqualProbCdf[3] = { | ||||
|     0, 32768, 65535 }; | ||||
|  | ||||
| /* Pointer to cdf array for encoder bandwidth (12 vs 16 kHz) indicator. */ | ||||
| static const uint16_t* kOneBitEqualProbCdf_ptr[1] = { | ||||
| static const uint16_t* const kOneBitEqualProbCdf_ptr[1] = { | ||||
|     kOneBitEqualProbCdf }; | ||||
|  | ||||
| /* | ||||
| @@ -96,7 +96,7 @@ static void FindInvArSpec(const int16_t* ARCoefQ12, | ||||
|                           const int32_t gainQ10, | ||||
|                           int32_t* CurveQ16) { | ||||
|   int32_t CorrQ11[AR_ORDER + 1]; | ||||
|   int32_t sum, tmpGain; | ||||
|   int64_t sum, tmpGain; | ||||
|   int32_t diffQ16[FRAMESAMPLES / 8]; | ||||
|   const int16_t* CS_ptrQ9; | ||||
|   int k, n; | ||||
| @@ -162,9 +162,9 @@ static void FindInvArSpec(const int16_t* ARCoefQ12, | ||||
|   } | ||||
|  | ||||
|   for (k = 0; k < FRAMESAMPLES / 8; k++) { | ||||
|     CurveQ16[FRAMESAMPLES_QUARTER - 1 - k] = CurveQ16[k] - | ||||
|         (diffQ16[k] << shftVal); | ||||
|     CurveQ16[k] += diffQ16[k] << shftVal; | ||||
|     int32_t diff_q16_shifted = (int32_t)((uint32_t)(diffQ16[k]) << shftVal); | ||||
|     CurveQ16[FRAMESAMPLES_QUARTER - 1 - k] = CurveQ16[k] - diff_q16_shifted; | ||||
|     CurveQ16[k] += diff_q16_shifted; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @@ -182,13 +182,13 @@ static void GenerateDitherQ7Lb(int16_t* bufQ7, uint32_t seed, | ||||
|  | ||||
|       /* Fixed-point dither sample between -64 and 64 (Q7). */ | ||||
|       /* dither = seed * 128 / 4294967295 */ | ||||
|       dither1_Q7 = (int16_t)(((int)seed + 16777216) >> 25); | ||||
|       dither1_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25); | ||||
|  | ||||
|       /* New random unsigned int. */ | ||||
|       seed = (seed * 196314165) + 907633515; | ||||
|  | ||||
|       /* Fixed-point dither sample between -64 and 64. */ | ||||
|       dither2_Q7 = (int16_t)(((int)seed + 16777216) >> 25); | ||||
|       dither2_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25); | ||||
|  | ||||
|       shft = (seed >> 25) & 15; | ||||
|       if (shft < 5) { | ||||
| @@ -214,7 +214,7 @@ static void GenerateDitherQ7Lb(int16_t* bufQ7, uint32_t seed, | ||||
|       seed = (seed * 196314165) + 907633515; | ||||
|  | ||||
|       /* Fixed-point dither sample between -64 and 64. */ | ||||
|       dither1_Q7 = (int16_t)(((int)seed + 16777216) >> 25); | ||||
|       dither1_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25); | ||||
|  | ||||
|       /* Dither sample is placed in either even or odd index. */ | ||||
|       shft = (seed >> 25) & 1;     /* Either 0 or 1 */ | ||||
| @@ -254,7 +254,7 @@ static void GenerateDitherQ7LbUB( | ||||
|  | ||||
|     /* Fixed-point dither sample between -64 and 64 (Q7). */ | ||||
|     /* bufQ7 = seed * 128 / 4294967295 */ | ||||
|     bufQ7[k] = (int16_t)(((int)seed + 16777216) >> 25); | ||||
|     bufQ7[k] = (int16_t)(((int32_t)(seed + 16777216)) >> 25); | ||||
|  | ||||
|     /* Scale by 0.35. */ | ||||
|     bufQ7[k] = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(bufQ7[k], 2048, 13); | ||||
| @@ -1843,7 +1843,7 @@ static const uint16_t kBwCdf[25] = { | ||||
|     62804, 65535 }; | ||||
|  | ||||
| /* pointer to cdf array for estimated bandwidth */ | ||||
| static const uint16_t* kBwCdfPtr[1] = { kBwCdf }; | ||||
| static const uint16_t* const kBwCdfPtr[1] = { kBwCdf }; | ||||
|  | ||||
| /* initial cdf index for decoder of estimated bandwidth*/ | ||||
| static const uint16_t kBwInitIndex[1] = { 7 }; | ||||
|   | ||||
| @@ -16,11 +16,11 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_ | ||||
|  | ||||
| #include "settings.h" | ||||
| #include "structs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_DecodeSpec() | ||||
| @@ -46,8 +46,11 @@ | ||||
|  * Return value             : < 0 if an error occures | ||||
|  *                              0 if succeeded. | ||||
|  */ | ||||
| int WebRtcIsac_DecodeSpec(Bitstr* streamdata, int16_t AvgPitchGain_Q12, | ||||
|                           enum ISACBand band, double* fr, double* fi); | ||||
| int WebRtcIsac_DecodeSpec(Bitstr* streamdata, | ||||
|                           int16_t AvgPitchGain_Q12, | ||||
|                           enum ISACBand band, | ||||
|                           double* fr, | ||||
|                           double* fi); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_EncodeSpec() | ||||
| @@ -72,24 +75,31 @@ int WebRtcIsac_DecodeSpec(Bitstr* streamdata, int16_t AvgPitchGain_Q12, | ||||
|  * Return value             : < 0 if an error occures | ||||
|  *                              0 if succeeded. | ||||
|  */ | ||||
| int WebRtcIsac_EncodeSpec(const int16_t* fr, const int16_t* fi, | ||||
|                           int16_t AvgPitchGain_Q12, enum ISACBand band, | ||||
| int WebRtcIsac_EncodeSpec(const int16_t* fr, | ||||
|                           const int16_t* fi, | ||||
|                           int16_t AvgPitchGain_Q12, | ||||
|                           enum ISACBand band, | ||||
|                           Bitstr* streamdata); | ||||
|  | ||||
| /* decode & dequantize LPC Coef */ | ||||
| int WebRtcIsac_DecodeLpcCoef(Bitstr* streamdata, double* LPCCoef); | ||||
| int WebRtcIsac_DecodeLpcCoefUB(Bitstr* streamdata, double* lpcVecs, | ||||
| int WebRtcIsac_DecodeLpcCoefUB(Bitstr* streamdata, | ||||
|                                double* lpcVecs, | ||||
|                                double* percepFilterGains, | ||||
|                                int16_t bandwidth); | ||||
|  | ||||
| int WebRtcIsac_DecodeLpc(Bitstr* streamdata, double* LPCCoef_lo, | ||||
| int WebRtcIsac_DecodeLpc(Bitstr* streamdata, | ||||
|                          double* LPCCoef_lo, | ||||
|                          double* LPCCoef_hi); | ||||
|  | ||||
| /* quantize & code LPC Coef */ | ||||
| void WebRtcIsac_EncodeLpcLb(double* LPCCoef_lo, double* LPCCoef_hi, | ||||
|                             Bitstr* streamdata, IsacSaveEncoderData* encData); | ||||
| void WebRtcIsac_EncodeLpcLb(double* LPCCoef_lo, | ||||
|                             double* LPCCoef_hi, | ||||
|                             Bitstr* streamdata, | ||||
|                             IsacSaveEncoderData* encData); | ||||
|  | ||||
| void WebRtcIsac_EncodeLpcGainLb(double* LPCCoef_lo, double* LPCCoef_hi, | ||||
| void WebRtcIsac_EncodeLpcGainLb(double* LPCCoef_lo, | ||||
|                                 double* LPCCoef_hi, | ||||
|                                 Bitstr* streamdata, | ||||
|                                 IsacSaveEncoderData* encData); | ||||
|  | ||||
| @@ -126,7 +136,8 @@ void WebRtcIsac_EncodeLpcGainLb(double* LPCCoef_lo, double* LPCCoef_hi, | ||||
|  * Return value             : 0 if encoding is successful, | ||||
|  *                           <0 if failed to encode. | ||||
|  */ | ||||
| int16_t WebRtcIsac_EncodeLpcUB(double* lpcCoeff, Bitstr* streamdata, | ||||
| int16_t WebRtcIsac_EncodeLpcUB(double* lpcCoeff, | ||||
|                                Bitstr* streamdata, | ||||
|                                double* interpolLPCCoeff, | ||||
|                                int16_t bandwidth, | ||||
|                                ISACUBSaveEncDataStruct* encData); | ||||
| @@ -184,9 +195,9 @@ void WebRtcIsac_EncodePitchLag(double* PitchLags, | ||||
|                                Bitstr* streamdata, | ||||
|                                IsacSaveEncoderData* encData); | ||||
|  | ||||
| int WebRtcIsac_DecodePitchGain(Bitstr* streamdata, | ||||
|                                int16_t* PitchGain_Q12); | ||||
| int WebRtcIsac_DecodePitchLag(Bitstr* streamdata, int16_t* PitchGain_Q12, | ||||
| int WebRtcIsac_DecodePitchGain(Bitstr* streamdata, int16_t* PitchGain_Q12); | ||||
| int WebRtcIsac_DecodePitchLag(Bitstr* streamdata, | ||||
|                               int16_t* PitchGain_Q12, | ||||
|                               double* PitchLag); | ||||
|  | ||||
| int WebRtcIsac_DecodeFrameLen(Bitstr* streamdata, int16_t* framelength); | ||||
| @@ -200,10 +211,10 @@ void WebRtcIsac_Poly2Rc(double* a, int N, double* RC); | ||||
| /* Step-up */ | ||||
| void WebRtcIsac_Rc2Poly(double* RC, int N, double* a); | ||||
|  | ||||
| void WebRtcIsac_TranscodeLPCCoef(double* LPCCoef_lo, double* LPCCoef_hi, | ||||
| void WebRtcIsac_TranscodeLPCCoef(double* LPCCoef_lo, | ||||
|                                  double* LPCCoef_hi, | ||||
|                                  int* index_g); | ||||
|  | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_EncodeLpcGainUb() | ||||
|  * Encode LPC gains of sub-Frames. | ||||
| @@ -220,10 +231,10 @@ void WebRtcIsac_TranscodeLPCCoef(double* LPCCoef_lo, double* LPCCoef_hi, | ||||
|  *  - lpcGainIndex          : quantization indices for lpc gains, these will | ||||
|  *                            be stored to be used  for FEC. | ||||
|  */ | ||||
| void WebRtcIsac_EncodeLpcGainUb(double* lpGains, Bitstr* streamdata, | ||||
| void WebRtcIsac_EncodeLpcGainUb(double* lpGains, | ||||
|                                 Bitstr* streamdata, | ||||
|                                 int* lpcGainIndex); | ||||
|  | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_EncodeLpcGainUb() | ||||
|  * Store LPC gains of sub-Frames in 'streamdata'. | ||||
| @@ -239,7 +250,6 @@ void WebRtcIsac_EncodeLpcGainUb(double* lpGains, Bitstr* streamdata, | ||||
|  */ | ||||
| void WebRtcIsac_StoreLpcGainUb(double* lpGains, Bitstr* streamdata); | ||||
|  | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_DecodeLpcGainUb() | ||||
|  * Decode the LPC gain of sub-frames. | ||||
| @@ -257,7 +267,6 @@ void WebRtcIsac_StoreLpcGainUb(double* lpGains, Bitstr* streamdata); | ||||
|  */ | ||||
| int16_t WebRtcIsac_DecodeLpcGainUb(double* lpGains, Bitstr* streamdata); | ||||
|  | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_EncodeBandwidth() | ||||
|  * Encode if the bandwidth of encoded audio is 0-12 kHz or 0-16 kHz. | ||||
| @@ -277,7 +286,6 @@ int16_t WebRtcIsac_DecodeLpcGainUb(double* lpGains, Bitstr* streamdata); | ||||
| int16_t WebRtcIsac_EncodeBandwidth(enum ISACBandwidth bandwidth, | ||||
|                                    Bitstr* streamData); | ||||
|  | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_DecodeBandwidth() | ||||
|  * Decode the bandwidth of the encoded audio, i.e. if the bandwidth is 0-12 kHz | ||||
| @@ -298,7 +306,6 @@ int16_t WebRtcIsac_EncodeBandwidth(enum ISACBandwidth bandwidth, | ||||
| int16_t WebRtcIsac_DecodeBandwidth(Bitstr* streamData, | ||||
|                                    enum ISACBandwidth* bandwidth); | ||||
|  | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_EncodeJitterInfo() | ||||
|  * Decode the jitter information. | ||||
| @@ -316,9 +323,7 @@ int16_t WebRtcIsac_DecodeBandwidth(Bitstr* streamData, | ||||
|  * Return value             : 0 if succeeded. | ||||
|  *                           <0 if failed. | ||||
|  */ | ||||
| int16_t WebRtcIsac_EncodeJitterInfo(int32_t jitterIndex, | ||||
|                                     Bitstr* streamData); | ||||
|  | ||||
| int16_t WebRtcIsac_EncodeJitterInfo(int32_t jitterIndex, Bitstr* streamData); | ||||
|  | ||||
| /****************************************************************************** | ||||
|  * WebRtcIsac_DecodeJitterInfo() | ||||
| @@ -337,7 +342,6 @@ int16_t WebRtcIsac_EncodeJitterInfo(int32_t jitterIndex, | ||||
|  * Return value             : 0 if succeeded. | ||||
|  *                           <0 if failed. | ||||
|  */ | ||||
| int16_t WebRtcIsac_DecodeJitterInfo(Bitstr* streamData, | ||||
|                                     int32_t* jitterInfo); | ||||
| int16_t WebRtcIsac_DecodeJitterInfo(Bitstr* streamData, int32_t* jitterInfo); | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_ */ | ||||
|   | ||||
| @@ -1,943 +0,0 @@ | ||||
| /* | ||||
|  * Copyright(c)1995,97 Mark Olesen <olesen@me.QueensU.CA> | ||||
|  *    Queen's Univ at Kingston (Canada) | ||||
|  * | ||||
|  * Permission to use, copy, modify, and distribute this software for | ||||
|  * any purpose without fee is hereby granted, provided that this | ||||
|  * entire notice is included in all copies of any software which is | ||||
|  * or includes a copy or modification of this software and in all | ||||
|  * copies of the supporting documentation for such software. | ||||
|  * | ||||
|  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR | ||||
|  * IMPLIED WARRANTY.  IN PARTICULAR, NEITHER THE AUTHOR NOR QUEEN'S | ||||
|  * UNIVERSITY AT KINGSTON MAKES ANY REPRESENTATION OR WARRANTY OF ANY | ||||
|  * KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS | ||||
|  * FITNESS FOR ANY PARTICULAR PURPOSE. | ||||
|  * | ||||
|  * All of which is to say that you can do what you like with this | ||||
|  * source code provided you don't try to sell it as your own and you | ||||
|  * include an unaltered copy of this message (including the | ||||
|  * copyright). | ||||
|  * | ||||
|  * It is also implicitly understood that bug fixes and improvements | ||||
|  * should make their way back to the general Internet community so | ||||
|  * that everyone benefits. | ||||
|  * | ||||
|  * Changes: | ||||
|  *   Trivial type modifications by the WebRTC authors. | ||||
|  */ | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * File: | ||||
|  * WebRtcIsac_Fftn.c | ||||
|  * | ||||
|  * Public: | ||||
|  * WebRtcIsac_Fftn / fftnf (); | ||||
|  * | ||||
|  * Private: | ||||
|  * WebRtcIsac_Fftradix / fftradixf (); | ||||
|  * | ||||
|  * Descript: | ||||
|  * multivariate complex Fourier transform, computed in place | ||||
|  * using mixed-radix Fast Fourier Transform algorithm. | ||||
|  * | ||||
|  * Fortran code by: | ||||
|  * RC Singleton, Stanford Research Institute, Sept. 1968 | ||||
|  * | ||||
|  * translated by f2c (version 19950721). | ||||
|  * | ||||
|  * int WebRtcIsac_Fftn (int ndim, const int dims[], REAL Re[], REAL Im[], | ||||
|  *     int iSign, double scaling); | ||||
|  * | ||||
|  * NDIM = the total number dimensions | ||||
|  * DIMS = a vector of array sizes | ||||
|  * if NDIM is zero then DIMS must be zero-terminated | ||||
|  * | ||||
|  * RE and IM hold the real and imaginary components of the data, and return | ||||
|  * the resulting real and imaginary Fourier coefficients.  Multidimensional | ||||
|  * data *must* be allocated contiguously.  There is no limit on the number | ||||
|  * of dimensions. | ||||
|  * | ||||
|  * ISIGN = the sign of the complex exponential (ie, forward or inverse FFT) | ||||
|  * the magnitude of ISIGN (normally 1) is used to determine the | ||||
|  * correct indexing increment (see below). | ||||
|  * | ||||
|  * SCALING = normalizing constant by which the final result is *divided* | ||||
|  * if SCALING == -1, normalize by total dimension of the transform | ||||
|  * if SCALING <  -1, normalize by the square-root of the total dimension | ||||
|  * | ||||
|  * example: | ||||
|  * tri-variate transform with Re[n1][n2][n3], Im[n1][n2][n3] | ||||
|  * | ||||
|  * int dims[3] = {n1,n2,n3} | ||||
|  * WebRtcIsac_Fftn (3, dims, Re, Im, 1, scaling); | ||||
|  * | ||||
|  *-----------------------------------------------------------------------* | ||||
|  * int WebRtcIsac_Fftradix (REAL Re[], REAL Im[], size_t nTotal, size_t nPass, | ||||
|  *   size_t nSpan, int iSign, size_t max_factors, | ||||
|  *   size_t max_perm); | ||||
|  * | ||||
|  * RE, IM - see above documentation | ||||
|  * | ||||
|  * Although there is no limit on the number of dimensions, WebRtcIsac_Fftradix() must | ||||
|  * be called once for each dimension, but the calls may be in any order. | ||||
|  * | ||||
|  * NTOTAL = the total number of complex data values | ||||
|  * NPASS  = the dimension of the current variable | ||||
|  * NSPAN/NPASS = the spacing of consecutive data values while indexing the | ||||
|  * current variable | ||||
|  * ISIGN - see above documentation | ||||
|  * | ||||
|  * example: | ||||
|  * tri-variate transform with Re[n1][n2][n3], Im[n1][n2][n3] | ||||
|  * | ||||
|  * WebRtcIsac_Fftradix (Re, Im, n1*n2*n3, n1,       n1, 1, maxf, maxp); | ||||
|  * WebRtcIsac_Fftradix (Re, Im, n1*n2*n3, n2,    n1*n2, 1, maxf, maxp); | ||||
|  * WebRtcIsac_Fftradix (Re, Im, n1*n2*n3, n3, n1*n2*n3, 1, maxf, maxp); | ||||
|  * | ||||
|  * single-variate transform, | ||||
|  *    NTOTAL = N = NSPAN = (number of complex data values), | ||||
|  * | ||||
|  * WebRtcIsac_Fftradix (Re, Im, n, n, n, 1, maxf, maxp); | ||||
|  * | ||||
|  * The data can also be stored in a single array with alternating real and | ||||
|  * imaginary parts, the magnitude of ISIGN is changed to 2 to give correct | ||||
|  * indexing increment, and data [0] and data [1] used to pass the initial | ||||
|  * addresses for the sequences of real and imaginary values, | ||||
|  * | ||||
|  * example: | ||||
|  * REAL data [2*NTOTAL]; | ||||
|  * WebRtcIsac_Fftradix ( &data[0], &data[1], NTOTAL, nPass, nSpan, 2, maxf, maxp); | ||||
|  * | ||||
|  * for temporary allocation: | ||||
|  * | ||||
|  * MAX_FACTORS >= the maximum prime factor of NPASS | ||||
|  * MAX_PERM >= the number of prime factors of NPASS.  In addition, | ||||
|  * if the square-free portion K of NPASS has two or more prime | ||||
|  * factors, then MAX_PERM >= (K-1) | ||||
|  * | ||||
|  * storage in FACTOR for a maximum of 15 prime factors of NPASS. if NPASS | ||||
|  * has more than one square-free factor, the product of the square-free | ||||
|  * factors must be <= 210 array storage for maximum prime factor of 23 the | ||||
|  * following two constants should agree with the array dimensions. | ||||
|  * | ||||
|  *----------------------------------------------------------------------*/ | ||||
| #include "fft.h" | ||||
|  | ||||
| #include <stdlib.h> | ||||
| #include <math.h> | ||||
|  | ||||
|  | ||||
|  | ||||
| /* double precision routine */ | ||||
| static int | ||||
| WebRtcIsac_Fftradix (double Re[], double Im[], | ||||
|                     size_t nTotal, size_t nPass, size_t nSpan, int isign, | ||||
|                     int max_factors, unsigned int max_perm, | ||||
|                     FFTstr *fftstate); | ||||
|  | ||||
|  | ||||
|  | ||||
| #ifndef M_PI | ||||
| # define M_PI 3.14159265358979323846264338327950288 | ||||
| #endif | ||||
|  | ||||
| #ifndef SIN60 | ||||
| # define SIN60 0.86602540378443865 /* sin(60 deg) */ | ||||
| # define COS72 0.30901699437494742 /* cos(72 deg) */ | ||||
| # define SIN72 0.95105651629515357 /* sin(72 deg) */ | ||||
| #endif | ||||
|  | ||||
| # define REAL  double | ||||
| # define FFTN  WebRtcIsac_Fftn | ||||
| # define FFTNS  "fftn" | ||||
| # define FFTRADIX WebRtcIsac_Fftradix | ||||
| # define FFTRADIXS "fftradix" | ||||
|  | ||||
|  | ||||
| int  WebRtcIsac_Fftns(unsigned int ndim, const int dims[], | ||||
|                      double Re[], | ||||
|                      double Im[], | ||||
|                      int iSign, | ||||
|                      double scaling, | ||||
|                      FFTstr *fftstate) | ||||
| { | ||||
|  | ||||
|   size_t nSpan, nPass, nTotal; | ||||
|   unsigned int i; | ||||
|   int ret, max_factors, max_perm; | ||||
|  | ||||
|   /* | ||||
|    * tally the number of elements in the data array | ||||
|    * and determine the number of dimensions | ||||
|    */ | ||||
|   nTotal = 1; | ||||
|   if (ndim && dims [0]) | ||||
|   { | ||||
|     for (i = 0; i < ndim; i++) | ||||
|     { | ||||
|       if (dims [i] <= 0) | ||||
|       { | ||||
|         return -1; | ||||
|       } | ||||
|       nTotal *= dims [i]; | ||||
|     } | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     ndim = 0; | ||||
|     for (i = 0; dims [i]; i++) | ||||
|     { | ||||
|       if (dims [i] <= 0) | ||||
|       { | ||||
|         return -1; | ||||
|       } | ||||
|       nTotal *= dims [i]; | ||||
|       ndim++; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /* determine maximum number of factors and permuations */ | ||||
| #if 1 | ||||
|   /* | ||||
|    * follow John Beale's example, just use the largest dimension and don't | ||||
|    * worry about excess allocation.  May be someone else will do it? | ||||
|    */ | ||||
|   max_factors = max_perm = 1; | ||||
|   for (i = 0; i < ndim; i++) | ||||
|   { | ||||
|     nSpan = dims [i]; | ||||
|     if ((int)nSpan > max_factors) | ||||
|     { | ||||
|       max_factors = (int)nSpan; | ||||
|     } | ||||
|     if ((int)nSpan > max_perm)  | ||||
|     { | ||||
|       max_perm = (int)nSpan; | ||||
|     } | ||||
|   } | ||||
| #else | ||||
|   /* use the constants used in the original Fortran code */ | ||||
|   max_factors = 23; | ||||
|   max_perm = 209; | ||||
| #endif | ||||
|   /* loop over the dimensions: */ | ||||
|   nPass = 1; | ||||
|   for (i = 0; i < ndim; i++) | ||||
|   { | ||||
|     nSpan = dims [i]; | ||||
|     nPass *= nSpan; | ||||
|     ret = FFTRADIX (Re, Im, nTotal, nSpan, nPass, iSign, | ||||
|                     max_factors, max_perm, fftstate); | ||||
|     /* exit, clean-up already done */ | ||||
|     if (ret) | ||||
|       return ret; | ||||
|   } | ||||
|  | ||||
|   /* Divide through by the normalizing constant: */ | ||||
|   if (scaling && scaling != 1.0) | ||||
|   { | ||||
|     if (iSign < 0) iSign = -iSign; | ||||
|     if (scaling < 0.0) | ||||
|     { | ||||
|       scaling = (double)nTotal; | ||||
|       if (scaling < -1.0) | ||||
|         scaling = sqrt (scaling); | ||||
|     } | ||||
|     scaling = 1.0 / scaling; /* multiply is often faster */ | ||||
|     for (i = 0; i < nTotal; i += iSign) | ||||
|     { | ||||
|       Re [i] *= scaling; | ||||
|       Im [i] *= scaling; | ||||
|     } | ||||
|   } | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
| /* | ||||
|  * singleton's mixed radix routine | ||||
|  * | ||||
|  * could move allocation out to WebRtcIsac_Fftn(), but leave it here so that it's | ||||
|  * possible to make this a standalone function | ||||
|  */ | ||||
|  | ||||
| static int   FFTRADIX (REAL Re[], | ||||
|                        REAL Im[], | ||||
|                        size_t nTotal, | ||||
|                        size_t nPass, | ||||
|                        size_t nSpan, | ||||
|                        int iSign, | ||||
|                        int max_factors, | ||||
|                        unsigned int max_perm, | ||||
|                        FFTstr *fftstate) | ||||
| { | ||||
|   int ii, mfactor, kspan, ispan, inc; | ||||
|   int j, jc, jf, jj, k, k1, k2, k3, k4, kk, kt, nn, ns, nt; | ||||
|  | ||||
|  | ||||
|   REAL radf; | ||||
|   REAL c1, c2, c3, cd, aa, aj, ak, ajm, ajp, akm, akp; | ||||
|   REAL s1, s2, s3, sd, bb, bj, bk, bjm, bjp, bkm, bkp; | ||||
|  | ||||
|   REAL *Rtmp = NULL; /* temp space for real part*/ | ||||
|   REAL *Itmp = NULL; /* temp space for imaginary part */ | ||||
|   REAL *Cos = NULL; /* Cosine values */ | ||||
|   REAL *Sin = NULL; /* Sine values */ | ||||
|  | ||||
|   REAL s60 = SIN60;  /* sin(60 deg) */ | ||||
|   REAL c72 = COS72;  /* cos(72 deg) */ | ||||
|   REAL s72 = SIN72;  /* sin(72 deg) */ | ||||
|   REAL pi2 = M_PI;  /* use PI first, 2 PI later */ | ||||
|  | ||||
|  | ||||
|   fftstate->SpaceAlloced = 0; | ||||
|   fftstate->MaxPermAlloced = 0; | ||||
|  | ||||
|  | ||||
|   // initialize to avoid warnings | ||||
|   k3 = c2 = c3 = s2 = s3 = 0.0; | ||||
|  | ||||
|   if (nPass < 2) | ||||
|     return 0; | ||||
|  | ||||
|   /*  allocate storage */ | ||||
|   if (fftstate->SpaceAlloced < max_factors * sizeof (REAL)) | ||||
|   { | ||||
| #ifdef SUN_BROKEN_REALLOC | ||||
|     if (!fftstate->SpaceAlloced) /* first time */ | ||||
|     { | ||||
|       fftstate->SpaceAlloced = max_factors * sizeof (REAL); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
| #endif | ||||
|       fftstate->SpaceAlloced = max_factors * sizeof (REAL); | ||||
| #ifdef SUN_BROKEN_REALLOC | ||||
|     } | ||||
| #endif | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     /* allow full use of alloc'd space */ | ||||
|     max_factors = fftstate->SpaceAlloced / sizeof (REAL); | ||||
|   } | ||||
|   if (fftstate->MaxPermAlloced < max_perm) | ||||
|   { | ||||
| #ifdef SUN_BROKEN_REALLOC | ||||
|     if (!fftstate->MaxPermAlloced) /* first time */ | ||||
|     else | ||||
| #endif | ||||
|       fftstate->MaxPermAlloced = max_perm; | ||||
|   } | ||||
|   else | ||||
|   { | ||||
|     /* allow full use of alloc'd space */ | ||||
|     max_perm = fftstate->MaxPermAlloced; | ||||
|   } | ||||
|  | ||||
|   /* assign pointers */ | ||||
|   Rtmp = (REAL *) fftstate->Tmp0; | ||||
|   Itmp = (REAL *) fftstate->Tmp1; | ||||
|   Cos  = (REAL *) fftstate->Tmp2; | ||||
|   Sin  = (REAL *) fftstate->Tmp3; | ||||
|  | ||||
|   /* | ||||
|    * Function Body | ||||
|    */ | ||||
|   inc = iSign; | ||||
|   if (iSign < 0) { | ||||
|     s72 = -s72; | ||||
|     s60 = -s60; | ||||
|     pi2 = -pi2; | ||||
|     inc = -inc;  /* absolute value */ | ||||
|   } | ||||
|  | ||||
|   /* adjust for strange increments */ | ||||
|   nt = inc * (int)nTotal; | ||||
|   ns = inc * (int)nSpan; | ||||
|   kspan = ns; | ||||
|  | ||||
|   nn = nt - inc; | ||||
|   jc = ns / (int)nPass; | ||||
|   radf = pi2 * (double) jc; | ||||
|   pi2 *= 2.0;   /* use 2 PI from here on */ | ||||
|  | ||||
|   ii = 0; | ||||
|   jf = 0; | ||||
|   /*  determine the factors of n */ | ||||
|   mfactor = 0; | ||||
|   k = (int)nPass; | ||||
|   while (k % 16 == 0) { | ||||
|     mfactor++; | ||||
|     fftstate->factor [mfactor - 1] = 4; | ||||
|     k /= 16; | ||||
|   } | ||||
|   j = 3; | ||||
|   jj = 9; | ||||
|   do { | ||||
|     while (k % jj == 0) { | ||||
|       mfactor++; | ||||
|       fftstate->factor [mfactor - 1] = j; | ||||
|       k /= jj; | ||||
|     } | ||||
|     j += 2; | ||||
|     jj = j * j; | ||||
|   } while (jj <= k); | ||||
|   if (k <= 4) { | ||||
|     kt = mfactor; | ||||
|     fftstate->factor [mfactor] = k; | ||||
|     if (k != 1) | ||||
|       mfactor++; | ||||
|   } else { | ||||
|     if (k - (k / 4 << 2) == 0) { | ||||
|       mfactor++; | ||||
|       fftstate->factor [mfactor - 1] = 2; | ||||
|       k /= 4; | ||||
|     } | ||||
|     kt = mfactor; | ||||
|     j = 2; | ||||
|     do { | ||||
|       if (k % j == 0) { | ||||
|         mfactor++; | ||||
|         fftstate->factor [mfactor - 1] = j; | ||||
|         k /= j; | ||||
|       } | ||||
|       j = ((j + 1) / 2 << 1) + 1; | ||||
|     } while (j <= k); | ||||
|   } | ||||
|   if (kt) { | ||||
|     j = kt; | ||||
|     do { | ||||
|       mfactor++; | ||||
|       fftstate->factor [mfactor - 1] = fftstate->factor [j - 1]; | ||||
|       j--; | ||||
|     } while (j); | ||||
|   } | ||||
|  | ||||
|   /* test that mfactors is in range */ | ||||
|   if (mfactor > NFACTOR) | ||||
|   { | ||||
|     return -1; | ||||
|   } | ||||
|  | ||||
|   /* compute fourier transform */ | ||||
|   for (;;) { | ||||
|     sd = radf / (double) kspan; | ||||
|     cd = sin(sd); | ||||
|     cd = 2.0 * cd * cd; | ||||
|     sd = sin(sd + sd); | ||||
|     kk = 0; | ||||
|     ii++; | ||||
|  | ||||
|     switch (fftstate->factor [ii - 1]) { | ||||
|       case 2: | ||||
|         /* transform for factor of 2 (including rotation factor) */ | ||||
|         kspan /= 2; | ||||
|         k1 = kspan + 2; | ||||
|         do { | ||||
|           do { | ||||
|             k2 = kk + kspan; | ||||
|             ak = Re [k2]; | ||||
|             bk = Im [k2]; | ||||
|             Re [k2] = Re [kk] - ak; | ||||
|             Im [k2] = Im [kk] - bk; | ||||
|             Re [kk] += ak; | ||||
|             Im [kk] += bk; | ||||
|             kk = k2 + kspan; | ||||
|           } while (kk < nn); | ||||
|           kk -= nn; | ||||
|         } while (kk < jc); | ||||
|         if (kk >= kspan) | ||||
|           goto Permute_Results_Label;  /* exit infinite loop */ | ||||
|         do { | ||||
|           c1 = 1.0 - cd; | ||||
|           s1 = sd; | ||||
|           do { | ||||
|             do { | ||||
|               do { | ||||
|                 k2 = kk + kspan; | ||||
|                 ak = Re [kk] - Re [k2]; | ||||
|                 bk = Im [kk] - Im [k2]; | ||||
|                 Re [kk] += Re [k2]; | ||||
|                 Im [kk] += Im [k2]; | ||||
|                 Re [k2] = c1 * ak - s1 * bk; | ||||
|                 Im [k2] = s1 * ak + c1 * bk; | ||||
|                 kk = k2 + kspan; | ||||
|               } while (kk < (nt-1)); | ||||
|               k2 = kk - nt; | ||||
|               c1 = -c1; | ||||
|               kk = k1 - k2; | ||||
|             } while (kk > k2); | ||||
|             ak = c1 - (cd * c1 + sd * s1); | ||||
|             s1 = sd * c1 - cd * s1 + s1; | ||||
|             c1 = 2.0 - (ak * ak + s1 * s1); | ||||
|             s1 *= c1; | ||||
|             c1 *= ak; | ||||
|             kk += jc; | ||||
|           } while (kk < k2); | ||||
|           k1 += inc + inc; | ||||
|           kk = (k1 - kspan + 1) / 2 + jc - 1; | ||||
|         } while (kk < (jc + jc)); | ||||
|         break; | ||||
|  | ||||
|       case 4:   /* transform for factor of 4 */ | ||||
|         ispan = kspan; | ||||
|         kspan /= 4; | ||||
|  | ||||
|         do { | ||||
|           c1 = 1.0; | ||||
|           s1 = 0.0; | ||||
|           do { | ||||
|             do { | ||||
|               k1 = kk + kspan; | ||||
|               k2 = k1 + kspan; | ||||
|               k3 = k2 + kspan; | ||||
|               akp = Re [kk] + Re [k2]; | ||||
|               akm = Re [kk] - Re [k2]; | ||||
|               ajp = Re [k1] + Re [k3]; | ||||
|               ajm = Re [k1] - Re [k3]; | ||||
|               bkp = Im [kk] + Im [k2]; | ||||
|               bkm = Im [kk] - Im [k2]; | ||||
|               bjp = Im [k1] + Im [k3]; | ||||
|               bjm = Im [k1] - Im [k3]; | ||||
|               Re [kk] = akp + ajp; | ||||
|               Im [kk] = bkp + bjp; | ||||
|               ajp = akp - ajp; | ||||
|               bjp = bkp - bjp; | ||||
|               if (iSign < 0) { | ||||
|                 akp = akm + bjm; | ||||
|                 bkp = bkm - ajm; | ||||
|                 akm -= bjm; | ||||
|                 bkm += ajm; | ||||
|               } else { | ||||
|                 akp = akm - bjm; | ||||
|                 bkp = bkm + ajm; | ||||
|                 akm += bjm; | ||||
|                 bkm -= ajm; | ||||
|               } | ||||
|               /* avoid useless multiplies */ | ||||
|               if (s1 == 0.0) { | ||||
|                 Re [k1] = akp; | ||||
|                 Re [k2] = ajp; | ||||
|                 Re [k3] = akm; | ||||
|                 Im [k1] = bkp; | ||||
|                 Im [k2] = bjp; | ||||
|                 Im [k3] = bkm; | ||||
|               } else { | ||||
|                 Re [k1] = akp * c1 - bkp * s1; | ||||
|                 Re [k2] = ajp * c2 - bjp * s2; | ||||
|                 Re [k3] = akm * c3 - bkm * s3; | ||||
|                 Im [k1] = akp * s1 + bkp * c1; | ||||
|                 Im [k2] = ajp * s2 + bjp * c2; | ||||
|                 Im [k3] = akm * s3 + bkm * c3; | ||||
|               } | ||||
|               kk = k3 + kspan; | ||||
|             } while (kk < nt); | ||||
|  | ||||
|             c2 = c1 - (cd * c1 + sd * s1); | ||||
|             s1 = sd * c1 - cd * s1 + s1; | ||||
|             c1 = 2.0 - (c2 * c2 + s1 * s1); | ||||
|             s1 *= c1; | ||||
|             c1 *= c2; | ||||
|             /* values of c2, c3, s2, s3 that will get used next time */ | ||||
|             c2 = c1 * c1 - s1 * s1; | ||||
|             s2 = 2.0 * c1 * s1; | ||||
|             c3 = c2 * c1 - s2 * s1; | ||||
|             s3 = c2 * s1 + s2 * c1; | ||||
|             kk = kk - nt + jc; | ||||
|           } while (kk < kspan); | ||||
|           kk = kk - kspan + inc; | ||||
|         } while (kk < jc); | ||||
|         if (kspan == jc) | ||||
|           goto Permute_Results_Label;  /* exit infinite loop */ | ||||
|         break; | ||||
|  | ||||
|       default: | ||||
|         /*  transform for odd factors */ | ||||
| #ifdef FFT_RADIX4 | ||||
|         return -1; | ||||
|         break; | ||||
| #else /* FFT_RADIX4 */ | ||||
|         k = fftstate->factor [ii - 1]; | ||||
|         ispan = kspan; | ||||
|         kspan /= k; | ||||
|  | ||||
|         switch (k) { | ||||
|           case 3: /* transform for factor of 3 (optional code) */ | ||||
|             do { | ||||
|               do { | ||||
|                 k1 = kk + kspan; | ||||
|                 k2 = k1 + kspan; | ||||
|                 ak = Re [kk]; | ||||
|                 bk = Im [kk]; | ||||
|                 aj = Re [k1] + Re [k2]; | ||||
|                 bj = Im [k1] + Im [k2]; | ||||
|                 Re [kk] = ak + aj; | ||||
|                 Im [kk] = bk + bj; | ||||
|                 ak -= 0.5 * aj; | ||||
|                 bk -= 0.5 * bj; | ||||
|                 aj = (Re [k1] - Re [k2]) * s60; | ||||
|                 bj = (Im [k1] - Im [k2]) * s60; | ||||
|                 Re [k1] = ak - bj; | ||||
|                 Re [k2] = ak + bj; | ||||
|                 Im [k1] = bk + aj; | ||||
|                 Im [k2] = bk - aj; | ||||
|                 kk = k2 + kspan; | ||||
|               } while (kk < (nn - 1)); | ||||
|               kk -= nn; | ||||
|             } while (kk < kspan); | ||||
|             break; | ||||
|  | ||||
|           case 5: /*  transform for factor of 5 (optional code) */ | ||||
|             c2 = c72 * c72 - s72 * s72; | ||||
|             s2 = 2.0 * c72 * s72; | ||||
|             do { | ||||
|               do { | ||||
|                 k1 = kk + kspan; | ||||
|                 k2 = k1 + kspan; | ||||
|                 k3 = k2 + kspan; | ||||
|                 k4 = k3 + kspan; | ||||
|                 akp = Re [k1] + Re [k4]; | ||||
|                 akm = Re [k1] - Re [k4]; | ||||
|                 bkp = Im [k1] + Im [k4]; | ||||
|                 bkm = Im [k1] - Im [k4]; | ||||
|                 ajp = Re [k2] + Re [k3]; | ||||
|                 ajm = Re [k2] - Re [k3]; | ||||
|                 bjp = Im [k2] + Im [k3]; | ||||
|                 bjm = Im [k2] - Im [k3]; | ||||
|                 aa = Re [kk]; | ||||
|                 bb = Im [kk]; | ||||
|                 Re [kk] = aa + akp + ajp; | ||||
|                 Im [kk] = bb + bkp + bjp; | ||||
|                 ak = akp * c72 + ajp * c2 + aa; | ||||
|                 bk = bkp * c72 + bjp * c2 + bb; | ||||
|                 aj = akm * s72 + ajm * s2; | ||||
|                 bj = bkm * s72 + bjm * s2; | ||||
|                 Re [k1] = ak - bj; | ||||
|                 Re [k4] = ak + bj; | ||||
|                 Im [k1] = bk + aj; | ||||
|                 Im [k4] = bk - aj; | ||||
|                 ak = akp * c2 + ajp * c72 + aa; | ||||
|                 bk = bkp * c2 + bjp * c72 + bb; | ||||
|                 aj = akm * s2 - ajm * s72; | ||||
|                 bj = bkm * s2 - bjm * s72; | ||||
|                 Re [k2] = ak - bj; | ||||
|                 Re [k3] = ak + bj; | ||||
|                 Im [k2] = bk + aj; | ||||
|                 Im [k3] = bk - aj; | ||||
|                 kk = k4 + kspan; | ||||
|               } while (kk < (nn-1)); | ||||
|               kk -= nn; | ||||
|             } while (kk < kspan); | ||||
|             break; | ||||
|  | ||||
|           default: | ||||
|             if (k != jf) { | ||||
|               jf = k; | ||||
|               s1 = pi2 / (double) k; | ||||
|               c1 = cos(s1); | ||||
|               s1 = sin(s1); | ||||
|               if (jf > max_factors){ | ||||
|                 return -1; | ||||
|               } | ||||
|               Cos [jf - 1] = 1.0; | ||||
|               Sin [jf - 1] = 0.0; | ||||
|               j = 1; | ||||
|               do { | ||||
|                 Cos [j - 1] = Cos [k - 1] * c1 + Sin [k - 1] * s1; | ||||
|                 Sin [j - 1] = Cos [k - 1] * s1 - Sin [k - 1] * c1; | ||||
|                 k--; | ||||
|                 Cos [k - 1] = Cos [j - 1]; | ||||
|                 Sin [k - 1] = -Sin [j - 1]; | ||||
|                 j++; | ||||
|               } while (j < k); | ||||
|             } | ||||
|             do { | ||||
|               do { | ||||
|                 k1 = kk; | ||||
|                 k2 = kk + ispan; | ||||
|                 ak = aa = Re [kk]; | ||||
|                 bk = bb = Im [kk]; | ||||
|                 j = 1; | ||||
|                 k1 += kspan; | ||||
|                 do { | ||||
|                   k2 -= kspan; | ||||
|                   j++; | ||||
|                   Rtmp [j - 1] = Re [k1] + Re [k2]; | ||||
|                   ak += Rtmp [j - 1]; | ||||
|                   Itmp [j - 1] = Im [k1] + Im [k2]; | ||||
|                   bk += Itmp [j - 1]; | ||||
|                   j++; | ||||
|                   Rtmp [j - 1] = Re [k1] - Re [k2]; | ||||
|                   Itmp [j - 1] = Im [k1] - Im [k2]; | ||||
|                   k1 += kspan; | ||||
|                 } while (k1 < k2); | ||||
|                 Re [kk] = ak; | ||||
|                 Im [kk] = bk; | ||||
|                 k1 = kk; | ||||
|                 k2 = kk + ispan; | ||||
|                 j = 1; | ||||
|                 do { | ||||
|                   k1 += kspan; | ||||
|                   k2 -= kspan; | ||||
|                   jj = j; | ||||
|                   ak = aa; | ||||
|                   bk = bb; | ||||
|                   aj = 0.0; | ||||
|                   bj = 0.0; | ||||
|                   k = 1; | ||||
|                   do { | ||||
|                     k++; | ||||
|                     ak += Rtmp [k - 1] * Cos [jj - 1]; | ||||
|                     bk += Itmp [k - 1] * Cos [jj - 1]; | ||||
|                     k++; | ||||
|                     aj += Rtmp [k - 1] * Sin [jj - 1]; | ||||
|                     bj += Itmp [k - 1] * Sin [jj - 1]; | ||||
|                     jj += j; | ||||
|                     if (jj > jf) { | ||||
|                       jj -= jf; | ||||
|                     } | ||||
|                   } while (k < jf); | ||||
|                   k = jf - j; | ||||
|                   Re [k1] = ak - bj; | ||||
|                   Im [k1] = bk + aj; | ||||
|                   Re [k2] = ak + bj; | ||||
|                   Im [k2] = bk - aj; | ||||
|                   j++; | ||||
|                 } while (j < k); | ||||
|                 kk += ispan; | ||||
|               } while (kk < nn); | ||||
|               kk -= nn; | ||||
|             } while (kk < kspan); | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         /*  multiply by rotation factor (except for factors of 2 and 4) */ | ||||
|         if (ii == mfactor) | ||||
|           goto Permute_Results_Label;  /* exit infinite loop */ | ||||
|         kk = jc; | ||||
|         do { | ||||
|           c2 = 1.0 - cd; | ||||
|           s1 = sd; | ||||
|           do { | ||||
|             c1 = c2; | ||||
|             s2 = s1; | ||||
|             kk += kspan; | ||||
|             do { | ||||
|               do { | ||||
|                 ak = Re [kk]; | ||||
|                 Re [kk] = c2 * ak - s2 * Im [kk]; | ||||
|                 Im [kk] = s2 * ak + c2 * Im [kk]; | ||||
|                 kk += ispan; | ||||
|               } while (kk < nt); | ||||
|               ak = s1 * s2; | ||||
|               s2 = s1 * c2 + c1 * s2; | ||||
|               c2 = c1 * c2 - ak; | ||||
|               kk = kk - nt + kspan; | ||||
|             } while (kk < ispan); | ||||
|             c2 = c1 - (cd * c1 + sd * s1); | ||||
|             s1 += sd * c1 - cd * s1; | ||||
|             c1 = 2.0 - (c2 * c2 + s1 * s1); | ||||
|             s1 *= c1; | ||||
|             c2 *= c1; | ||||
|             kk = kk - ispan + jc; | ||||
|           } while (kk < kspan); | ||||
|           kk = kk - kspan + jc + inc; | ||||
|         } while (kk < (jc + jc)); | ||||
|         break; | ||||
| #endif /* FFT_RADIX4 */ | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /*  permute the results to normal order---done in two stages */ | ||||
|   /*  permutation for square factors of n */ | ||||
| Permute_Results_Label: | ||||
|   fftstate->Perm [0] = ns; | ||||
|   if (kt) { | ||||
|     k = kt + kt + 1; | ||||
|     if (mfactor < k) | ||||
|       k--; | ||||
|     j = 1; | ||||
|     fftstate->Perm [k] = jc; | ||||
|     do { | ||||
|       fftstate->Perm [j] = fftstate->Perm [j - 1] / fftstate->factor [j - 1]; | ||||
|       fftstate->Perm [k - 1] = fftstate->Perm [k] * fftstate->factor [j - 1]; | ||||
|       j++; | ||||
|       k--; | ||||
|     } while (j < k); | ||||
|     k3 = fftstate->Perm [k]; | ||||
|     kspan = fftstate->Perm [1]; | ||||
|     kk = jc; | ||||
|     k2 = kspan; | ||||
|     j = 1; | ||||
|     if (nPass != nTotal) { | ||||
|       /*  permutation for multivariate transform */ | ||||
|    Permute_Multi_Label: | ||||
|       do { | ||||
|         do { | ||||
|           k = kk + jc; | ||||
|           do { | ||||
|             /* swap Re [kk] <> Re [k2], Im [kk] <> Im [k2] */ | ||||
|             ak = Re [kk]; Re [kk] = Re [k2]; Re [k2] = ak; | ||||
|             bk = Im [kk]; Im [kk] = Im [k2]; Im [k2] = bk; | ||||
|             kk += inc; | ||||
|             k2 += inc; | ||||
|           } while (kk < (k-1)); | ||||
|           kk += ns - jc; | ||||
|           k2 += ns - jc; | ||||
|         } while (kk < (nt-1)); | ||||
|         k2 = k2 - nt + kspan; | ||||
|         kk = kk - nt + jc; | ||||
|       } while (k2 < (ns-1)); | ||||
|       do { | ||||
|         do { | ||||
|           k2 -= fftstate->Perm [j - 1]; | ||||
|           j++; | ||||
|           k2 = fftstate->Perm [j] + k2; | ||||
|         } while (k2 > fftstate->Perm [j - 1]); | ||||
|         j = 1; | ||||
|         do { | ||||
|           if (kk < (k2-1)) | ||||
|             goto Permute_Multi_Label; | ||||
|           kk += jc; | ||||
|           k2 += kspan; | ||||
|         } while (k2 < (ns-1)); | ||||
|       } while (kk < (ns-1)); | ||||
|     } else { | ||||
|       /*  permutation for single-variate transform (optional code) */ | ||||
|    Permute_Single_Label: | ||||
|       do { | ||||
|         /* swap Re [kk] <> Re [k2], Im [kk] <> Im [k2] */ | ||||
|         ak = Re [kk]; Re [kk] = Re [k2]; Re [k2] = ak; | ||||
|         bk = Im [kk]; Im [kk] = Im [k2]; Im [k2] = bk; | ||||
|         kk += inc; | ||||
|         k2 += kspan; | ||||
|       } while (k2 < (ns-1)); | ||||
|       do { | ||||
|         do { | ||||
|           k2 -= fftstate->Perm [j - 1]; | ||||
|           j++; | ||||
|           k2 = fftstate->Perm [j] + k2; | ||||
|         } while (k2 >= fftstate->Perm [j - 1]); | ||||
|         j = 1; | ||||
|         do { | ||||
|           if (kk < k2) | ||||
|             goto Permute_Single_Label; | ||||
|           kk += inc; | ||||
|           k2 += kspan; | ||||
|         } while (k2 < (ns-1)); | ||||
|       } while (kk < (ns-1)); | ||||
|     } | ||||
|     jc = k3; | ||||
|   } | ||||
|  | ||||
|   if ((kt << 1) + 1 >= mfactor) | ||||
|     return 0; | ||||
|   ispan = fftstate->Perm [kt]; | ||||
|   /* permutation for square-free factors of n */ | ||||
|   j = mfactor - kt; | ||||
|   fftstate->factor [j] = 1; | ||||
|   do { | ||||
|     fftstate->factor [j - 1] *= fftstate->factor [j]; | ||||
|     j--; | ||||
|   } while (j != kt); | ||||
|   kt++; | ||||
|   nn = fftstate->factor [kt - 1] - 1; | ||||
|   if (nn > (int) max_perm) { | ||||
|     return -1; | ||||
|   } | ||||
|   j = jj = 0; | ||||
|   for (;;) { | ||||
|     k = kt + 1; | ||||
|     k2 = fftstate->factor [kt - 1]; | ||||
|     kk = fftstate->factor [k - 1]; | ||||
|     j++; | ||||
|     if (j > nn) | ||||
|       break;    /* exit infinite loop */ | ||||
|     jj += kk; | ||||
|     while (jj >= k2) { | ||||
|       jj -= k2; | ||||
|       k2 = kk; | ||||
|       k++; | ||||
|       kk = fftstate->factor [k - 1]; | ||||
|       jj += kk; | ||||
|     } | ||||
|     fftstate->Perm [j - 1] = jj; | ||||
|   } | ||||
|   /*  determine the permutation cycles of length greater than 1 */ | ||||
|   j = 0; | ||||
|   for (;;) { | ||||
|     do { | ||||
|       j++; | ||||
|       kk = fftstate->Perm [j - 1]; | ||||
|     } while (kk < 0); | ||||
|     if (kk != j) { | ||||
|       do { | ||||
|         k = kk; | ||||
|         kk = fftstate->Perm [k - 1]; | ||||
|         fftstate->Perm [k - 1] = -kk; | ||||
|       } while (kk != j); | ||||
|       k3 = kk; | ||||
|     } else { | ||||
|       fftstate->Perm [j - 1] = -j; | ||||
|       if (j == nn) | ||||
|         break;  /* exit infinite loop */ | ||||
|     } | ||||
|   } | ||||
|   max_factors *= inc; | ||||
|   /*  reorder a and b, following the permutation cycles */ | ||||
|   for (;;) { | ||||
|     j = k3 + 1; | ||||
|     nt -= ispan; | ||||
|     ii = nt - inc + 1; | ||||
|     if (nt < 0) | ||||
|       break;   /* exit infinite loop */ | ||||
|     do { | ||||
|       do { | ||||
|         j--; | ||||
|       } while (fftstate->Perm [j - 1] < 0); | ||||
|       jj = jc; | ||||
|       do { | ||||
|         kspan = jj; | ||||
|         if (jj > max_factors) { | ||||
|           kspan = max_factors; | ||||
|         } | ||||
|         jj -= kspan; | ||||
|         k = fftstate->Perm [j - 1]; | ||||
|         kk = jc * k + ii + jj; | ||||
|         k1 = kk + kspan - 1; | ||||
|         k2 = 0; | ||||
|         do { | ||||
|           k2++; | ||||
|           Rtmp [k2 - 1] = Re [k1]; | ||||
|           Itmp [k2 - 1] = Im [k1]; | ||||
|           k1 -= inc; | ||||
|         } while (k1 != (kk-1)); | ||||
|         do { | ||||
|           k1 = kk + kspan - 1; | ||||
|           k2 = k1 - jc * (k + fftstate->Perm [k - 1]); | ||||
|           k = -fftstate->Perm [k - 1]; | ||||
|           do { | ||||
|             Re [k1] = Re [k2]; | ||||
|             Im [k1] = Im [k2]; | ||||
|             k1 -= inc; | ||||
|             k2 -= inc; | ||||
|           } while (k1 != (kk-1)); | ||||
|           kk = k2 + 1; | ||||
|         } while (k != j); | ||||
|         k1 = kk + kspan - 1; | ||||
|         k2 = 0; | ||||
|         do { | ||||
|           k2++; | ||||
|           Re [k1] = Rtmp [k2 - 1]; | ||||
|           Im [k1] = Itmp [k2 - 1]; | ||||
|           k1 -= inc; | ||||
|         } while (k1 != (kk-1)); | ||||
|       } while (jj); | ||||
|     } while (j != 1); | ||||
|   } | ||||
|   return 0;   /* exit point here */ | ||||
| } | ||||
| /* ---------------------- end-of-file (c source) ---------------------- */ | ||||
|  | ||||
| @@ -1,45 +0,0 @@ | ||||
| /* | ||||
|  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | ||||
|  * | ||||
|  *  Use of this source code is governed by a BSD-style license | ||||
|  *  that can be found in the LICENSE file in the root of the source | ||||
|  *  tree. An additional intellectual property rights grant can be found | ||||
|  *  in the file PATENTS.  All contributing project authors may | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| /*--------------------------------*-C-*---------------------------------* | ||||
|  * File: | ||||
|  *       fftn.h | ||||
|  * ---------------------------------------------------------------------* | ||||
|  * Re[]:        real value array | ||||
|  * Im[]:        imaginary value array | ||||
|  * nTotal:      total number of complex values | ||||
|  * nPass:       number of elements involved in this pass of transform | ||||
|  * nSpan:       nspan/nPass = number of bytes to increment pointer | ||||
|  *              in Re[] and Im[] | ||||
|  * isign: exponent: +1 = forward  -1 = reverse | ||||
|  * scaling: normalizing constant by which the final result is *divided* | ||||
|  * scaling == -1, normalize by total dimension of the transform | ||||
|  * scaling <  -1, normalize by the square-root of the total dimension | ||||
|  * | ||||
|  * ---------------------------------------------------------------------- | ||||
|  * See the comments in the code for correct usage! | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FFT_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FFT_H_ | ||||
|  | ||||
|  | ||||
| #include "structs.h" | ||||
|  | ||||
|  | ||||
| /* double precision routine */ | ||||
|  | ||||
|  | ||||
| int WebRtcIsac_Fftns (unsigned int ndim, const int dims[], double Re[], double Im[], | ||||
|                      int isign, double scaling, FFTstr *fftstate); | ||||
|  | ||||
|  | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FFT_H_ */ | ||||
| @@ -13,16 +13,14 @@ | ||||
| #ifdef WEBRTC_ANDROID | ||||
| #include <stdlib.h> | ||||
| #endif | ||||
| #include "pitch_estimator.h" | ||||
| #include "lpc_analysis.h" | ||||
| #include "codec.h" | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_estimator.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/isac_vad.h" | ||||
|  | ||||
|  | ||||
| void WebRtcIsac_AllPoleFilter(double* InOut, | ||||
|                               double* Coef, | ||||
|                               size_t lengthInOut, | ||||
|                               int orderCoef) { | ||||
| static void WebRtcIsac_AllPoleFilter(double* InOut, | ||||
|                                      double* Coef, | ||||
|                                      size_t lengthInOut, | ||||
|                                      int orderCoef) { | ||||
|   /* the state of filter is assumed to be in InOut[-1] to InOut[-orderCoef] */ | ||||
|   double scal; | ||||
|   double sum; | ||||
| @@ -55,12 +53,11 @@ void WebRtcIsac_AllPoleFilter(double* InOut, | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| void WebRtcIsac_AllZeroFilter(double* In, | ||||
|                               double* Coef, | ||||
|                               size_t lengthInOut, | ||||
|                               int orderCoef, | ||||
|                               double* Out) { | ||||
| static void WebRtcIsac_AllZeroFilter(double* In, | ||||
|                                      double* Coef, | ||||
|                                      size_t lengthInOut, | ||||
|                                      int orderCoef, | ||||
|                                      double* Out) { | ||||
|   /* the state of filter is assumed to be in In[-1] to In[-orderCoef] */ | ||||
|  | ||||
|   size_t n; | ||||
| @@ -80,13 +77,12 @@ void WebRtcIsac_AllZeroFilter(double* In, | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| void WebRtcIsac_ZeroPoleFilter(double* In, | ||||
|                                double* ZeroCoef, | ||||
|                                double* PoleCoef, | ||||
|                                size_t lengthInOut, | ||||
|                                int orderCoef, | ||||
|                                double* Out) { | ||||
| static void WebRtcIsac_ZeroPoleFilter(double* In, | ||||
|                                       double* ZeroCoef, | ||||
|                                       double* PoleCoef, | ||||
|                                       size_t lengthInOut, | ||||
|                                       int orderCoef, | ||||
|                                       double* Out) { | ||||
|   /* the state of the zero section is assumed to be in In[-1] to In[-orderCoef] */ | ||||
|   /* the state of the pole section is assumed to be in Out[-1] to Out[-orderCoef] */ | ||||
|  | ||||
| @@ -115,8 +111,10 @@ void WebRtcIsac_AutoCorr(double* r, const double* x, size_t N, size_t order) { | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
| void WebRtcIsac_BwExpand(double* out, double* in, double coef, size_t length) { | ||||
| static void WebRtcIsac_BwExpand(double* out, | ||||
|                                 double* in, | ||||
|                                 double coef, | ||||
|                                 size_t length) { | ||||
|   size_t i; | ||||
|   double  chirp; | ||||
|  | ||||
| @@ -195,69 +193,3 @@ void WebRtcIsac_WeightingFilter(const double* in, | ||||
|   memcpy(weiout, weoutbuf+PITCH_WLPCORDER, sizeof(double) * PITCH_FRAME_LEN); | ||||
|   memcpy(whiout, whoutbuf+PITCH_WLPCORDER, sizeof(double) * PITCH_FRAME_LEN); | ||||
| } | ||||
|  | ||||
|  | ||||
| static const double APupper[ALLPASSSECTIONS] = {0.0347, 0.3826}; | ||||
| static const double APlower[ALLPASSSECTIONS] = {0.1544, 0.744}; | ||||
|  | ||||
|  | ||||
| void WebRtcIsac_AllpassFilterForDec(double* InOut, | ||||
|                                     const double* APSectionFactors, | ||||
|                                     size_t lengthInOut, | ||||
|                                     double* FilterState) { | ||||
|   //This performs all-pass filtering--a series of first order all-pass sections are used | ||||
|   //to filter the input in a cascade manner. | ||||
|   size_t n,j; | ||||
|   double temp; | ||||
|   for (j=0; j<ALLPASSSECTIONS; j++){ | ||||
|     for (n=0;n<lengthInOut;n+=2){ | ||||
|       temp = InOut[n]; //store input | ||||
|       InOut[n] = FilterState[j] + APSectionFactors[j]*temp; | ||||
|       FilterState[j] = -APSectionFactors[j]*InOut[n] + temp; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| void WebRtcIsac_DecimateAllpass(const double* in, | ||||
|                                 double* state_in, | ||||
|                                 size_t N, | ||||
|                                 double* out) { | ||||
|   size_t n; | ||||
|   double data_vec[PITCH_FRAME_LEN]; | ||||
|  | ||||
|   /* copy input */ | ||||
|   memcpy(data_vec+1, in, sizeof(double) * (N-1)); | ||||
|  | ||||
|   data_vec[0] = state_in[2*ALLPASSSECTIONS];   //the z^(-1) state | ||||
|   state_in[2*ALLPASSSECTIONS] = in[N-1]; | ||||
|  | ||||
|   WebRtcIsac_AllpassFilterForDec(data_vec+1, APupper, N, state_in); | ||||
|   WebRtcIsac_AllpassFilterForDec(data_vec, APlower, N, state_in+ALLPASSSECTIONS); | ||||
|  | ||||
|   for (n=0;n<N/2;n++) | ||||
|     out[n] = data_vec[2*n] + data_vec[2*n+1]; | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
| /* create high-pass filter ocefficients | ||||
|  * z = 0.998 * exp(j*2*pi*35/8000); | ||||
|  * p = 0.94 * exp(j*2*pi*140/8000); | ||||
|  * HP_b = [1, -2*real(z), abs(z)^2]; | ||||
|  * HP_a = [1, -2*real(p), abs(p)^2]; */ | ||||
| static const double a_coef[2] = { 1.86864659625574, -0.88360000000000}; | ||||
| static const double b_coef[2] = {-1.99524591718270,  0.99600400000000}; | ||||
|  | ||||
| /* second order high-pass filter */ | ||||
| void WebRtcIsac_Highpass(const double* in, | ||||
|                          double* out, | ||||
|                          double* state, | ||||
|                          size_t N) { | ||||
|   size_t k; | ||||
|  | ||||
|   for (k=0; k<N; k++) { | ||||
|     *out = *in + state[1]; | ||||
|     state[1] = state[0] + b_coef[0] * *in + a_coef[0] * *out; | ||||
|     state[0] = b_coef[1] * *in++ + a_coef[1] * *out++; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,23 @@ | ||||
| /* | ||||
|  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. | ||||
|  * | ||||
|  *  Use of this source code is governed by a BSD-style license | ||||
|  *  that can be found in the LICENSE file in the root of the source | ||||
|  *  tree. An additional intellectual property rights grant can be found | ||||
|  *  in the file PATENTS.  All contributing project authors may | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FILTER_FUNCTIONS_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FILTER_FUNCTIONS_H_ | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
|  | ||||
| void WebRtcIsac_AutoCorr(double* r, const double* x, size_t N, size_t order); | ||||
|  | ||||
| void WebRtcIsac_WeightingFilter(const double* in, | ||||
|                                 double* weiout, | ||||
|                                 double* whiout, | ||||
|                                 WeightFiltstr* wfdata); | ||||
|  | ||||
| #endif  // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FILTER_FUNCTIONS_H_ | ||||
| @@ -1,37 +0,0 @@ | ||||
| /* | ||||
|  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | ||||
|  * | ||||
|  *  Use of this source code is governed by a BSD-style license | ||||
|  *  that can be found in the LICENSE file in the root of the source | ||||
|  *  tree. An additional intellectual property rights grant can be found | ||||
|  *  in the file PATENTS.  All contributing project authors may | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| /* filterbank_tables.c*/ | ||||
| /* This file contains variables that are used in filterbanks.c*/ | ||||
|  | ||||
| #include "filterbank_tables.h" | ||||
| #include "settings.h" | ||||
|  | ||||
| /* The composite all-pass filter factors */ | ||||
| const float WebRtcIsac_kCompositeApFactorsFloat[4] = { | ||||
|  0.03470000000000f,  0.15440000000000f,  0.38260000000000f,  0.74400000000000f}; | ||||
|  | ||||
| /* The upper channel all-pass filter factors */ | ||||
| const float WebRtcIsac_kUpperApFactorsFloat[2] = { | ||||
|  0.03470000000000f,  0.38260000000000f}; | ||||
|  | ||||
| /* The lower channel all-pass filter factors */ | ||||
| const float WebRtcIsac_kLowerApFactorsFloat[2] = { | ||||
|  0.15440000000000f,  0.74400000000000f}; | ||||
|  | ||||
| /* The matrix for transforming the backward composite state to upper channel state */ | ||||
| const float WebRtcIsac_kTransform1Float[8] = { | ||||
|   -0.00158678506084f,  0.00127157815343f, -0.00104805672709f,  0.00084837248079f, | ||||
|   0.00134467983258f, -0.00107756549387f,  0.00088814793277f, -0.00071893072525f}; | ||||
|  | ||||
| /* The matrix for transforming the backward composite state to lower channel state */ | ||||
| const float WebRtcIsac_kTransform2Float[8] = { | ||||
|  -0.00170686041697f,  0.00136780109829f, -0.00112736532350f,  0.00091257055385f, | ||||
|   0.00103094281812f, -0.00082615076557f,  0.00068092756088f, -0.00055119165484f}; | ||||
| @@ -1,46 +0,0 @@ | ||||
| /* | ||||
|  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | ||||
|  * | ||||
|  *  Use of this source code is governed by a BSD-style license | ||||
|  *  that can be found in the LICENSE file in the root of the source | ||||
|  *  tree. An additional intellectual property rights grant can be found | ||||
|  *  in the file PATENTS.  All contributing project authors may | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| /* | ||||
|  * filterbank_tables.h | ||||
|  * | ||||
|  * Header file for variables that are defined in | ||||
|  * filterbank_tables.c. | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FILTERBANK_TABLES_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FILTERBANK_TABLES_H_ | ||||
|  | ||||
| #include "structs.h" | ||||
|  | ||||
| /********************* Coefficient Tables ************************/ | ||||
| /* The number of composite all-pass filter factors */ | ||||
| #define NUMBEROFCOMPOSITEAPSECTIONS 4 | ||||
|  | ||||
| /* The number of all-pass filter factors in an upper or lower channel*/ | ||||
| #define NUMBEROFCHANNELAPSECTIONS 2 | ||||
|  | ||||
| /* The composite all-pass filter factors */ | ||||
| extern const float WebRtcIsac_kCompositeApFactorsFloat[4]; | ||||
|  | ||||
| /* The upper channel all-pass filter factors */ | ||||
| extern const float WebRtcIsac_kUpperApFactorsFloat[2]; | ||||
|  | ||||
| /* The lower channel all-pass filter factors */ | ||||
| extern const float WebRtcIsac_kLowerApFactorsFloat[2]; | ||||
|  | ||||
| /* The matrix for transforming the backward composite state to upper channel state */ | ||||
| extern const float WebRtcIsac_kTransform1Float[8]; | ||||
|  | ||||
| /* The matrix for transforming the backward composite state to lower channel state */ | ||||
| extern const float WebRtcIsac_kTransform2Float[8]; | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_FILTERBANK_TABLES_H_ */ | ||||
| @@ -18,241 +18,9 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include "settings.h" | ||||
| #include "filterbank_tables.h" | ||||
| #include "codec.h" | ||||
|  | ||||
| /* This function performs all-pass filtering--a series of first order all-pass | ||||
|  * sections are used to filter the input in a cascade manner. | ||||
|  * The input is overwritten!! | ||||
|  */ | ||||
| static void WebRtcIsac_AllPassFilter2Float(float *InOut, const float *APSectionFactors, | ||||
|                                            int lengthInOut, int NumberOfSections, | ||||
|                                            float *FilterState) | ||||
| { | ||||
|   int n, j; | ||||
|   float temp; | ||||
|   for (j=0; j<NumberOfSections; j++){ | ||||
|     for (n=0;n<lengthInOut;n++){ | ||||
|       temp = FilterState[j] + APSectionFactors[j] * InOut[n]; | ||||
|       FilterState[j] = -APSectionFactors[j] * temp + InOut[n]; | ||||
|       InOut[n] = temp; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* HPstcoeff_in = {a1, a2, b1 - b0 * a1, b2 - b0 * a2}; */ | ||||
| static const float kHpStCoefInFloat[4] = | ||||
| {-1.94895953203325f, 0.94984516000000f, -0.05101826139794f, 0.05015484000000f}; | ||||
|  | ||||
| /* Function WebRtcIsac_SplitAndFilter | ||||
|  * This function creates low-pass and high-pass decimated versions of part of | ||||
|  the input signal, and part of the signal in the input 'lookahead buffer'. | ||||
|  | ||||
|  INPUTS: | ||||
|  in: a length FRAMESAMPLES array of input samples | ||||
|  prefiltdata: input data structure containing the filterbank states | ||||
|  and lookahead samples from the previous encoding | ||||
|  iteration. | ||||
|  OUTPUTS: | ||||
|  LP: a FRAMESAMPLES_HALF array of low-pass filtered samples that | ||||
|  have been phase equalized.  The first QLOOKAHEAD samples are | ||||
|  based on the samples in the two prefiltdata->INLABUFx arrays | ||||
|  each of length QLOOKAHEAD. | ||||
|  The remaining FRAMESAMPLES_HALF-QLOOKAHEAD samples are based | ||||
|  on the first FRAMESAMPLES_HALF-QLOOKAHEAD samples of the input | ||||
|  array in[]. | ||||
|  HP: a FRAMESAMPLES_HALF array of high-pass filtered samples that | ||||
|  have been phase equalized.  The first QLOOKAHEAD samples are | ||||
|  based on the samples in the two prefiltdata->INLABUFx arrays | ||||
|  each of length QLOOKAHEAD. | ||||
|  The remaining FRAMESAMPLES_HALF-QLOOKAHEAD samples are based | ||||
|  on the first FRAMESAMPLES_HALF-QLOOKAHEAD samples of the input | ||||
|  array in[]. | ||||
|  | ||||
|  LP_la: a FRAMESAMPLES_HALF array of low-pass filtered samples. | ||||
|  These samples are not phase equalized. They are computed | ||||
|  from the samples in the in[] array. | ||||
|  HP_la: a FRAMESAMPLES_HALF array of high-pass filtered samples | ||||
|  that are not phase equalized. They are computed from | ||||
|  the in[] vector. | ||||
|  prefiltdata: this input data structure's filterbank state and | ||||
|  lookahead sample buffers are updated for the next | ||||
|  encoding iteration. | ||||
| */ | ||||
| void WebRtcIsac_SplitAndFilterFloat(float *pin, float *LP, float *HP, | ||||
|                                     double *LP_la, double *HP_la, | ||||
|                                     PreFiltBankstr *prefiltdata) | ||||
| { | ||||
|   int k,n; | ||||
|   float CompositeAPFilterState[NUMBEROFCOMPOSITEAPSECTIONS]; | ||||
|   float ForTransform_CompositeAPFilterState[NUMBEROFCOMPOSITEAPSECTIONS]; | ||||
|   float ForTransform_CompositeAPFilterState2[NUMBEROFCOMPOSITEAPSECTIONS]; | ||||
|   float tempinoutvec[FRAMESAMPLES+MAX_AR_MODEL_ORDER]; | ||||
|   float tempin_ch1[FRAMESAMPLES+MAX_AR_MODEL_ORDER]; | ||||
|   float tempin_ch2[FRAMESAMPLES+MAX_AR_MODEL_ORDER]; | ||||
|   float in[FRAMESAMPLES]; | ||||
|   float ftmp; | ||||
|  | ||||
|  | ||||
|   /* High pass filter */ | ||||
|  | ||||
|   for (k=0;k<FRAMESAMPLES;k++) { | ||||
|     in[k] = pin[k] + kHpStCoefInFloat[2] * prefiltdata->HPstates_float[0] + | ||||
|         kHpStCoefInFloat[3] * prefiltdata->HPstates_float[1]; | ||||
|     ftmp = pin[k] - kHpStCoefInFloat[0] * prefiltdata->HPstates_float[0] - | ||||
|         kHpStCoefInFloat[1] * prefiltdata->HPstates_float[1]; | ||||
|     prefiltdata->HPstates_float[1] = prefiltdata->HPstates_float[0]; | ||||
|     prefiltdata->HPstates_float[0] = ftmp; | ||||
|   } | ||||
|  | ||||
|   /* | ||||
|     % backwards all-pass filtering to obtain zero-phase | ||||
|     [tmp1(N2+LA:-1:LA+1, 1), state1] = filter(Q.coef, Q.coef(end:-1:1), in(N:-2:2)); | ||||
|     tmp1(LA:-1:1) = filter(Q.coef, Q.coef(end:-1:1), Q.LookAheadBuf1, state1); | ||||
|     Q.LookAheadBuf1 = in(N:-2:N-2*LA+2); | ||||
|   */ | ||||
|   /*Backwards all-pass filter the odd samples of the input (upper channel) | ||||
|     to eventually obtain zero phase.  The composite all-pass filter (comprised of both | ||||
|     the upper and lower channel all-pass filsters in series) is used for the | ||||
|     filtering. */ | ||||
|  | ||||
|   /* First Channel */ | ||||
|  | ||||
|   /*initial state of composite filter is zero */ | ||||
|   for (k=0;k<NUMBEROFCOMPOSITEAPSECTIONS;k++){ | ||||
|     CompositeAPFilterState[k] = 0.0; | ||||
|   } | ||||
|   /* put every other sample of input into a temporary vector in reverse (backward) order*/ | ||||
|   for (k=0;k<FRAMESAMPLES_HALF;k++) { | ||||
|     tempinoutvec[k] = in[FRAMESAMPLES-1-2*k]; | ||||
|   } | ||||
|  | ||||
|   /* now all-pass filter the backwards vector.  Output values overwrite the input vector. */ | ||||
|   WebRtcIsac_AllPassFilter2Float(tempinoutvec, WebRtcIsac_kCompositeApFactorsFloat, | ||||
|                                  FRAMESAMPLES_HALF, NUMBEROFCOMPOSITEAPSECTIONS, CompositeAPFilterState); | ||||
|  | ||||
|   /* save the backwards filtered output for later forward filtering, | ||||
|      but write it in forward order*/ | ||||
|   for (k=0;k<FRAMESAMPLES_HALF;k++) { | ||||
|     tempin_ch1[FRAMESAMPLES_HALF+QLOOKAHEAD-1-k] = tempinoutvec[k]; | ||||
|   } | ||||
|  | ||||
|   /* save the backwards filter state  becaue it will be transformed | ||||
|      later into a forward state */ | ||||
|   for (k=0; k<NUMBEROFCOMPOSITEAPSECTIONS; k++) { | ||||
|     ForTransform_CompositeAPFilterState[k] = CompositeAPFilterState[k]; | ||||
|   } | ||||
|  | ||||
|   /* now backwards filter the samples in the lookahead buffer. The samples were | ||||
|      placed there in the encoding of the previous frame.  The output samples | ||||
|      overwrite the input samples */ | ||||
|   WebRtcIsac_AllPassFilter2Float(prefiltdata->INLABUF1_float, | ||||
|                                  WebRtcIsac_kCompositeApFactorsFloat, QLOOKAHEAD, | ||||
|                                  NUMBEROFCOMPOSITEAPSECTIONS, CompositeAPFilterState); | ||||
|  | ||||
|   /* save the output, but write it in forward order */ | ||||
|   /* write the lookahead samples for the next encoding iteration. Every other | ||||
|      sample at the end of the input frame is written in reverse order for the | ||||
|      lookahead length. Exported in the prefiltdata structure. */ | ||||
|   for (k=0;k<QLOOKAHEAD;k++) { | ||||
|     tempin_ch1[QLOOKAHEAD-1-k]=prefiltdata->INLABUF1_float[k]; | ||||
|     prefiltdata->INLABUF1_float[k]=in[FRAMESAMPLES-1-2*k]; | ||||
|   } | ||||
|  | ||||
|   /* Second Channel.  This is exactly like the first channel, except that the | ||||
|      even samples are now filtered instead (lower channel). */ | ||||
|   for (k=0;k<NUMBEROFCOMPOSITEAPSECTIONS;k++){ | ||||
|     CompositeAPFilterState[k] = 0.0; | ||||
|   } | ||||
|  | ||||
|   for (k=0;k<FRAMESAMPLES_HALF;k++) { | ||||
|     tempinoutvec[k] = in[FRAMESAMPLES-2-2*k]; | ||||
|   } | ||||
|  | ||||
|   WebRtcIsac_AllPassFilter2Float(tempinoutvec, WebRtcIsac_kCompositeApFactorsFloat, | ||||
|                                  FRAMESAMPLES_HALF, NUMBEROFCOMPOSITEAPSECTIONS, CompositeAPFilterState); | ||||
|  | ||||
|   for (k=0;k<FRAMESAMPLES_HALF;k++) { | ||||
|     tempin_ch2[FRAMESAMPLES_HALF+QLOOKAHEAD-1-k] = tempinoutvec[k]; | ||||
|   } | ||||
|  | ||||
|   for (k=0; k<NUMBEROFCOMPOSITEAPSECTIONS; k++) { | ||||
|     ForTransform_CompositeAPFilterState2[k] = CompositeAPFilterState[k]; | ||||
|   } | ||||
|  | ||||
|  | ||||
|   WebRtcIsac_AllPassFilter2Float(prefiltdata->INLABUF2_float, | ||||
|                                  WebRtcIsac_kCompositeApFactorsFloat, QLOOKAHEAD,NUMBEROFCOMPOSITEAPSECTIONS, | ||||
|                                  CompositeAPFilterState); | ||||
|  | ||||
|   for (k=0;k<QLOOKAHEAD;k++) { | ||||
|     tempin_ch2[QLOOKAHEAD-1-k]=prefiltdata->INLABUF2_float[k]; | ||||
|     prefiltdata->INLABUF2_float[k]=in[FRAMESAMPLES-2-2*k]; | ||||
|   } | ||||
|  | ||||
|   /* Transform filter states from backward to forward */ | ||||
|   /*At this point, each of the states of the backwards composite filters for the | ||||
|     two channels are transformed into forward filtering states for the corresponding | ||||
|     forward channel filters.  Each channel's forward filtering state from the previous | ||||
|     encoding iteration is added to the transformed state to get a proper forward state */ | ||||
|  | ||||
|   /* So the existing NUMBEROFCOMPOSITEAPSECTIONS x 1 (4x1) state vector is multiplied by a | ||||
|      NUMBEROFCHANNELAPSECTIONSxNUMBEROFCOMPOSITEAPSECTIONS (2x4) transform matrix to get the | ||||
|      new state that is added to the previous 2x1 input state */ | ||||
|  | ||||
|   for (k=0;k<NUMBEROFCHANNELAPSECTIONS;k++){ /* k is row variable */ | ||||
|     for (n=0; n<NUMBEROFCOMPOSITEAPSECTIONS;n++){/* n is column variable */ | ||||
|       prefiltdata->INSTAT1_float[k] += ForTransform_CompositeAPFilterState[n]* | ||||
|           WebRtcIsac_kTransform1Float[k*NUMBEROFCHANNELAPSECTIONS+n]; | ||||
|       prefiltdata->INSTAT2_float[k] += ForTransform_CompositeAPFilterState2[n]* | ||||
|           WebRtcIsac_kTransform2Float[k*NUMBEROFCHANNELAPSECTIONS+n]; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /*obtain polyphase components by forward all-pass filtering through each channel */ | ||||
|   /* the backward filtered samples are now forward filtered with the corresponding channel filters */ | ||||
|   /* The all pass filtering automatically updates the filter states which are exported in the | ||||
|      prefiltdata structure */ | ||||
|   WebRtcIsac_AllPassFilter2Float(tempin_ch1,WebRtcIsac_kUpperApFactorsFloat, | ||||
|                                  FRAMESAMPLES_HALF, NUMBEROFCHANNELAPSECTIONS, prefiltdata->INSTAT1_float); | ||||
|   WebRtcIsac_AllPassFilter2Float(tempin_ch2,WebRtcIsac_kLowerApFactorsFloat, | ||||
|                                  FRAMESAMPLES_HALF, NUMBEROFCHANNELAPSECTIONS, prefiltdata->INSTAT2_float); | ||||
|  | ||||
|   /* Now Construct low-pass and high-pass signals as combinations of polyphase components */ | ||||
|   for (k=0; k<FRAMESAMPLES_HALF; k++) { | ||||
|     LP[k] = 0.5f*(tempin_ch1[k] + tempin_ch2[k]);/* low pass signal*/ | ||||
|     HP[k] = 0.5f*(tempin_ch1[k] - tempin_ch2[k]);/* high pass signal*/ | ||||
|   } | ||||
|  | ||||
|   /* Lookahead LP and HP signals */ | ||||
|   /* now create low pass and high pass signals of the input vector.  However, no | ||||
|      backwards filtering is performed, and hence no phase equalization is involved. | ||||
|      Also, the input contains some samples that are lookahead samples.  The high pass | ||||
|      and low pass signals that are created are used outside this function for analysis | ||||
|      (not encoding) purposes */ | ||||
|  | ||||
|   /* set up input */ | ||||
|   for (k=0; k<FRAMESAMPLES_HALF; k++) { | ||||
|     tempin_ch1[k]=in[2*k+1]; | ||||
|     tempin_ch2[k]=in[2*k]; | ||||
|   } | ||||
|  | ||||
|   /* the input filter states are passed in and updated by the all-pass filtering routine and | ||||
|      exported in the prefiltdata structure*/ | ||||
|   WebRtcIsac_AllPassFilter2Float(tempin_ch1,WebRtcIsac_kUpperApFactorsFloat, | ||||
|                                  FRAMESAMPLES_HALF, NUMBEROFCHANNELAPSECTIONS, prefiltdata->INSTATLA1_float); | ||||
|   WebRtcIsac_AllPassFilter2Float(tempin_ch2,WebRtcIsac_kLowerApFactorsFloat, | ||||
|                                  FRAMESAMPLES_HALF, NUMBEROFCHANNELAPSECTIONS, prefiltdata->INSTATLA2_float); | ||||
|  | ||||
|   for (k=0; k<FRAMESAMPLES_HALF; k++) { | ||||
|     LP_la[k] = (float)(0.5f*(tempin_ch1[k] + tempin_ch2[k])); /*low pass */ | ||||
|     HP_la[k] = (double)(0.5f*(tempin_ch1[k] - tempin_ch2[k])); /* high pass */ | ||||
|   } | ||||
|  | ||||
|  | ||||
| }/*end of WebRtcIsac_SplitAndFilter */ | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/codec.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/isac_vad.h" | ||||
|  | ||||
| /* Combining */ | ||||
|  | ||||
|   | ||||
| @@ -10,12 +10,12 @@ | ||||
|  | ||||
| /* encode.c  - Encoding function for the iSAC coder */ | ||||
|  | ||||
| #include "structs.h" | ||||
| #include "codec.h" | ||||
| #include "pitch_estimator.h" | ||||
|  | ||||
| #include <math.h> | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/codec.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_estimator.h" | ||||
|  | ||||
| void WebRtcIsac_InitMasking(MaskFiltstr *maskdata) { | ||||
|  | ||||
|   int k; | ||||
| @@ -43,39 +43,6 @@ void WebRtcIsac_InitMasking(MaskFiltstr *maskdata) { | ||||
|   return; | ||||
| } | ||||
|  | ||||
| void WebRtcIsac_InitPreFilterbank(PreFiltBankstr *prefiltdata) | ||||
| { | ||||
|   int k; | ||||
|  | ||||
|   for (k = 0; k < QLOOKAHEAD; k++) { | ||||
|     prefiltdata->INLABUF1[k] = 0; | ||||
|     prefiltdata->INLABUF2[k] = 0; | ||||
|  | ||||
|     prefiltdata->INLABUF1_float[k] = 0; | ||||
|     prefiltdata->INLABUF2_float[k] = 0; | ||||
|   } | ||||
|   for (k = 0; k < 2*(QORDER-1); k++) { | ||||
|     prefiltdata->INSTAT1[k] = 0; | ||||
|     prefiltdata->INSTAT2[k] = 0; | ||||
|     prefiltdata->INSTATLA1[k] = 0; | ||||
|     prefiltdata->INSTATLA2[k] = 0; | ||||
|  | ||||
|     prefiltdata->INSTAT1_float[k] = 0; | ||||
|     prefiltdata->INSTAT2_float[k] = 0; | ||||
|     prefiltdata->INSTATLA1_float[k] = 0; | ||||
|     prefiltdata->INSTATLA2_float[k] = 0; | ||||
|   } | ||||
|  | ||||
|   /* High pass filter states */ | ||||
|   prefiltdata->HPstates[0] = 0.0; | ||||
|   prefiltdata->HPstates[1] = 0.0; | ||||
|  | ||||
|   prefiltdata->HPstates_float[0] = 0.0f; | ||||
|   prefiltdata->HPstates_float[1] = 0.0f; | ||||
|  | ||||
|   return; | ||||
| } | ||||
|  | ||||
| void WebRtcIsac_InitPostFilterbank(PostFiltBankstr *postfiltdata) | ||||
| { | ||||
|   int k; | ||||
| @@ -103,69 +70,3 @@ void WebRtcIsac_InitPostFilterbank(PostFiltBankstr *postfiltdata) | ||||
|  | ||||
|   return; | ||||
| } | ||||
|  | ||||
|  | ||||
| void WebRtcIsac_InitPitchFilter(PitchFiltstr *pitchfiltdata) | ||||
| { | ||||
|   int k; | ||||
|  | ||||
|   for (k = 0; k < PITCH_BUFFSIZE; k++) { | ||||
|     pitchfiltdata->ubuf[k] = 0.0; | ||||
|   } | ||||
|   pitchfiltdata->ystate[0] = 0.0; | ||||
|   for (k = 1; k < (PITCH_DAMPORDER); k++) { | ||||
|     pitchfiltdata->ystate[k] = 0.0; | ||||
|   } | ||||
|   pitchfiltdata->oldlagp[0] = 50.0; | ||||
|   pitchfiltdata->oldgainp[0] = 0.0; | ||||
| } | ||||
|  | ||||
| void WebRtcIsac_InitWeightingFilter(WeightFiltstr *wfdata) | ||||
| { | ||||
|   int k; | ||||
|   double t, dtmp, dtmp2, denum, denum2; | ||||
|  | ||||
|   for (k=0;k<PITCH_WLPCBUFLEN;k++) | ||||
|     wfdata->buffer[k]=0.0; | ||||
|  | ||||
|   for (k=0;k<PITCH_WLPCORDER;k++) { | ||||
|     wfdata->istate[k]=0.0; | ||||
|     wfdata->weostate[k]=0.0; | ||||
|     wfdata->whostate[k]=0.0; | ||||
|   } | ||||
|  | ||||
|   /* next part should be in Matlab, writing to a global table */ | ||||
|   t = 0.5; | ||||
|   denum = 1.0 / ((double) PITCH_WLPCWINLEN); | ||||
|   denum2 = denum * denum; | ||||
|   for (k=0;k<PITCH_WLPCWINLEN;k++) { | ||||
|     dtmp = PITCH_WLPCASYM * t * denum + (1-PITCH_WLPCASYM) * t * t * denum2; | ||||
|     dtmp *= 3.14159265; | ||||
|     dtmp2 = sin(dtmp); | ||||
|     wfdata->window[k] = dtmp2 * dtmp2; | ||||
|     t++; | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* clear all buffers */ | ||||
| void WebRtcIsac_InitPitchAnalysis(PitchAnalysisStruct *State) | ||||
| { | ||||
|   int k; | ||||
|  | ||||
|   for (k = 0; k < PITCH_CORR_LEN2+PITCH_CORR_STEP2+PITCH_MAX_LAG/2-PITCH_FRAME_LEN/2+2; k++) | ||||
|     State->dec_buffer[k] = 0.0; | ||||
|   for (k = 0; k < 2*ALLPASSSECTIONS+1; k++) | ||||
|     State->decimator_state[k] = 0.0; | ||||
|   for (k = 0; k < 2; k++) | ||||
|     State->hp_state[k] = 0.0; | ||||
|   for (k = 0; k < QLOOKAHEAD; k++) | ||||
|     State->whitened_buf[k] = 0.0; | ||||
|   for (k = 0; k < QLOOKAHEAD; k++) | ||||
|     State->inbuf[k] = 0.0; | ||||
|  | ||||
|   WebRtcIsac_InitPitchFilter(&(State->PFstr_wght)); | ||||
|  | ||||
|   WebRtcIsac_InitPitchFilter(&(State->PFstr)); | ||||
|  | ||||
|   WebRtcIsac_InitWeightingFilter(&(State->Wghtstr)); | ||||
| } | ||||
|   | ||||
| @@ -15,22 +15,24 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/include/isac.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/include/isac.h" | ||||
|  | ||||
| #include <assert.h> | ||||
| #include <math.h> | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
|  | ||||
| #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h" | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/source/codec.h" | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/source/crc.h" | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.h" | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h" | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/source/os_specific_inline.h" | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
| #include "rtc_base/checks.h" | ||||
| #include "common_audio/signal_processing/include/signal_processing_library.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/codec.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/crc.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/os_specific_inline.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/isac_vad.h" | ||||
| #include "rtc_base/system/arch.h" | ||||
|  | ||||
| #define BIT_MASK_DEC_INIT 0x0001 | ||||
| #define BIT_MASK_ENC_INIT 0x0002 | ||||
| @@ -204,62 +206,6 @@ static void GetSendBandwidthInfo(ISACMainStruct* instISAC, | ||||
| } | ||||
|  | ||||
|  | ||||
| /**************************************************************************** | ||||
|  * WebRtcIsac_AssignSize(...) | ||||
|  * | ||||
|  * This function returns the size of the ISAC instance, so that the instance | ||||
|  * can be created out side iSAC. | ||||
|  * | ||||
|  * Output: | ||||
|  *        - sizeinbytes       : number of bytes needed to allocate for the | ||||
|  *                              instance. | ||||
|  * | ||||
|  * Return value               : 0 - Ok | ||||
|  *                             -1 - Error | ||||
|  */ | ||||
| int16_t WebRtcIsac_AssignSize(int* sizeInBytes) { | ||||
|   *sizeInBytes = sizeof(ISACMainStruct) * 2 / sizeof(int16_t); | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
| /**************************************************************************** | ||||
|  * WebRtcIsac_Assign(...) | ||||
|  * | ||||
|  * This function assigns the memory already created to the ISAC instance. | ||||
|  * | ||||
|  * Input: | ||||
|  *        - ISAC_main_inst    : address of the pointer to the coder instance. | ||||
|  *        - instISAC_Addr     : the already allocated memory, where we put the | ||||
|  *                              iSAC structure. | ||||
|  * | ||||
|  * Return value               : 0 - Ok | ||||
|  *                             -1 - Error | ||||
|  */ | ||||
| int16_t WebRtcIsac_Assign(ISACStruct** ISAC_main_inst, | ||||
|                           void* instISAC_Addr) { | ||||
|   if (instISAC_Addr != NULL) { | ||||
|     ISACMainStruct* instISAC = (ISACMainStruct*)instISAC_Addr; | ||||
|     instISAC->errorCode = 0; | ||||
|     instISAC->initFlag = 0; | ||||
|  | ||||
|     /* Assign the address. */ | ||||
|     *ISAC_main_inst = (ISACStruct*)instISAC_Addr; | ||||
|  | ||||
|     /* Default is wideband. */ | ||||
|     instISAC->encoderSamplingRateKHz = kIsacWideband; | ||||
|     instISAC->decoderSamplingRateKHz = kIsacWideband; | ||||
|     instISAC->bandwidthKHz           = isac8kHz; | ||||
|     instISAC->in_sample_rate_hz = 16000; | ||||
|  | ||||
|     WebRtcIsac_InitTransform(&instISAC->transform_tables); | ||||
|     return 0; | ||||
|   } else { | ||||
|     return -1; | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| /**************************************************************************** | ||||
|  * WebRtcIsac_Create(...) | ||||
|  * | ||||
| @@ -1253,10 +1199,23 @@ static int Decode(ISACStruct* ISAC_main_inst, | ||||
|             return -1; | ||||
|         } | ||||
|  | ||||
|         if (numDecodedBytesUB < 0) { | ||||
|           instISAC->errorCode = numDecodedBytesUB; | ||||
|           return -1; | ||||
|         } | ||||
|         if (numDecodedBytesLB + numDecodedBytesUB > lenEncodedBytes) { | ||||
|           // We have supposedly decoded more bytes than we were given. Likely | ||||
|           // caused by bad input data. | ||||
|           instISAC->errorCode = ISAC_LENGTH_MISMATCH; | ||||
|           return -1; | ||||
|         } | ||||
|  | ||||
|         /* It might be less due to garbage. */ | ||||
|         if ((numDecodedBytesUB != lenNextStream) && | ||||
|             (numDecodedBytesUB != (lenNextStream - | ||||
|                 encoded[numDecodedBytesLB + 1 + numDecodedBytesUB]))) { | ||||
|             (numDecodedBytesLB + 1 + numDecodedBytesUB >= lenEncodedBytes || | ||||
|              numDecodedBytesUB != | ||||
|                  (lenNextStream - | ||||
|                   encoded[numDecodedBytesLB + 1 + numDecodedBytesUB]))) { | ||||
|           instISAC->errorCode = ISAC_LENGTH_MISMATCH; | ||||
|           return -1; | ||||
|         } | ||||
| @@ -1539,8 +1498,8 @@ int16_t WebRtcIsac_Control(ISACStruct* ISAC_main_inst, | ||||
| void WebRtcIsac_SetInitialBweBottleneck(ISACStruct* ISAC_main_inst, | ||||
|                                         int bottleneck_bits_per_second) { | ||||
|   ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; | ||||
|   assert(bottleneck_bits_per_second >= 10000 && | ||||
|          bottleneck_bits_per_second <= 32000); | ||||
|   RTC_DCHECK_GE(bottleneck_bits_per_second, 10000); | ||||
|   RTC_DCHECK_LE(bottleneck_bits_per_second, 32000); | ||||
|   instISAC->bwestimator_obj.send_bw_avg = (float)bottleneck_bits_per_second; | ||||
| } | ||||
|  | ||||
| @@ -1760,7 +1719,7 @@ int16_t WebRtcIsac_ReadBwIndex(const uint8_t* encoded, | ||||
|  *        - frameLength       : Length of frame in packet (in samples) | ||||
|  * | ||||
|  */ | ||||
| int16_t WebRtcIsac_ReadFrameLen(ISACStruct* ISAC_main_inst, | ||||
| int16_t WebRtcIsac_ReadFrameLen(const ISACStruct* ISAC_main_inst, | ||||
|                                 const uint8_t* encoded, | ||||
|                                 int16_t* frameLength) { | ||||
|   Bitstr streamdata; | ||||
| @@ -2338,26 +2297,11 @@ uint16_t WebRtcIsac_DecSampRate(ISACStruct* ISAC_main_inst) { | ||||
|   return instISAC->decoderSamplingRateKHz == kIsacWideband ? 16000 : 32000; | ||||
| } | ||||
|  | ||||
| void WebRtcIsac_GetBandwidthInfo(ISACStruct* inst, | ||||
|                                  IsacBandwidthInfo* bwinfo) { | ||||
|   ISACMainStruct* instISAC = (ISACMainStruct*)inst; | ||||
|   assert(instISAC->initFlag & BIT_MASK_DEC_INIT); | ||||
|   WebRtcIsacBw_GetBandwidthInfo(&instISAC->bwestimator_obj, | ||||
|                                 instISAC->decoderSamplingRateKHz, bwinfo); | ||||
| } | ||||
|  | ||||
| void WebRtcIsac_SetBandwidthInfo(ISACStruct* inst, | ||||
|                                  const IsacBandwidthInfo* bwinfo) { | ||||
|   ISACMainStruct* instISAC = (ISACMainStruct*)inst; | ||||
|   assert(instISAC->initFlag & BIT_MASK_ENC_INIT); | ||||
|   WebRtcIsacBw_SetBandwidthInfo(&instISAC->bwestimator_obj, bwinfo); | ||||
| } | ||||
|  | ||||
| void WebRtcIsac_SetEncSampRateInDecoder(ISACStruct* inst, | ||||
|                                         int sample_rate_hz) { | ||||
|   ISACMainStruct* instISAC = (ISACMainStruct*)inst; | ||||
|   assert(instISAC->initFlag & BIT_MASK_DEC_INIT); | ||||
|   assert(!(instISAC->initFlag & BIT_MASK_ENC_INIT)); | ||||
|   assert(sample_rate_hz == 16000 || sample_rate_hz == 32000); | ||||
|   RTC_DCHECK_NE(0, instISAC->initFlag & BIT_MASK_DEC_INIT); | ||||
|   RTC_DCHECK(!(instISAC->initFlag & BIT_MASK_ENC_INIT)); | ||||
|   RTC_DCHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000); | ||||
|   instISAC->encoderSamplingRateKHz = sample_rate_hz / 1000; | ||||
| } | ||||
|   | ||||
| @@ -8,10 +8,10 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_FLOAT_TYPE_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_FLOAT_TYPE_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_FLOAT_TYPE_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_FLOAT_TYPE_H_ | ||||
|  | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/include/isac.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/include/isac.h" | ||||
|  | ||||
| namespace webrtc { | ||||
|  | ||||
| @@ -64,10 +64,6 @@ struct IsacFloat { | ||||
|   static inline int16_t Free(instance_type* inst) { | ||||
|     return WebRtcIsac_Free(inst); | ||||
|   } | ||||
|   static inline void GetBandwidthInfo(instance_type* inst, | ||||
|                                       IsacBandwidthInfo* bwinfo) { | ||||
|     WebRtcIsac_GetBandwidthInfo(inst, bwinfo); | ||||
|   } | ||||
|   static inline int16_t GetErrorCode(instance_type* inst) { | ||||
|     return WebRtcIsac_GetErrorCode(inst); | ||||
|   } | ||||
| @@ -75,10 +71,6 @@ struct IsacFloat { | ||||
|   static inline int16_t GetNewFrameLen(instance_type* inst) { | ||||
|     return WebRtcIsac_GetNewFrameLen(inst); | ||||
|   } | ||||
|   static inline void SetBandwidthInfo(instance_type* inst, | ||||
|                                       const IsacBandwidthInfo* bwinfo) { | ||||
|     WebRtcIsac_SetBandwidthInfo(inst, bwinfo); | ||||
|   } | ||||
|   static inline int16_t SetDecSampRate(instance_type* inst, | ||||
|                                        uint16_t sample_rate_hz) { | ||||
|     return WebRtcIsac_SetDecSampRate(inst, sample_rate_hz); | ||||
| @@ -95,15 +87,6 @@ struct IsacFloat { | ||||
|                                              int bottleneck_bits_per_second) { | ||||
|     WebRtcIsac_SetInitialBweBottleneck(inst, bottleneck_bits_per_second); | ||||
|   } | ||||
|   static inline int16_t UpdateBwEstimate(instance_type* inst, | ||||
|                                          const uint8_t* encoded, | ||||
|                                          size_t packet_size, | ||||
|                                          uint16_t rtp_seq_number, | ||||
|                                          uint32_t send_ts, | ||||
|                                          uint32_t arr_ts) { | ||||
|     return WebRtcIsac_UpdateBwEstimate(inst, encoded, packet_size, | ||||
|                                        rtp_seq_number, send_ts, arr_ts); | ||||
|   } | ||||
|   static inline int16_t SetMaxPayloadSize(instance_type* inst, | ||||
|                                           int16_t max_payload_size_bytes) { | ||||
|     return WebRtcIsac_SetMaxPayloadSize(inst, max_payload_size_bytes); | ||||
| @@ -114,4 +97,4 @@ struct IsacFloat { | ||||
| }; | ||||
|  | ||||
| }  // namespace webrtc | ||||
| #endif  // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_FLOAT_TYPE_H_ | ||||
| #endif  // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_FLOAT_TYPE_H_ | ||||
|   | ||||
							
								
								
									
										409
									
								
								webrtc/modules/audio_coding/codecs/isac/main/source/isac_vad.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										409
									
								
								webrtc/modules/audio_coding/codecs/isac/main/source/isac_vad.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,409 @@ | ||||
| /* | ||||
|  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. | ||||
|  * | ||||
|  *  Use of this source code is governed by a BSD-style license | ||||
|  *  that can be found in the LICENSE file in the root of the source | ||||
|  *  tree. An additional intellectual property rights grant can be found | ||||
|  *  in the file PATENTS.  All contributing project authors may | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/isac_vad.h" | ||||
|  | ||||
| #include <math.h> | ||||
|  | ||||
| void WebRtcIsac_InitPitchFilter(PitchFiltstr* pitchfiltdata) { | ||||
|   int k; | ||||
|  | ||||
|   for (k = 0; k < PITCH_BUFFSIZE; k++) { | ||||
|     pitchfiltdata->ubuf[k] = 0.0; | ||||
|   } | ||||
|   pitchfiltdata->ystate[0] = 0.0; | ||||
|   for (k = 1; k < (PITCH_DAMPORDER); k++) { | ||||
|     pitchfiltdata->ystate[k] = 0.0; | ||||
|   } | ||||
|   pitchfiltdata->oldlagp[0] = 50.0; | ||||
|   pitchfiltdata->oldgainp[0] = 0.0; | ||||
| } | ||||
|  | ||||
| static void WebRtcIsac_InitWeightingFilter(WeightFiltstr* wfdata) { | ||||
|   int k; | ||||
|   double t, dtmp, dtmp2, denum, denum2; | ||||
|  | ||||
|   for (k = 0; k < PITCH_WLPCBUFLEN; k++) | ||||
|     wfdata->buffer[k] = 0.0; | ||||
|  | ||||
|   for (k = 0; k < PITCH_WLPCORDER; k++) { | ||||
|     wfdata->istate[k] = 0.0; | ||||
|     wfdata->weostate[k] = 0.0; | ||||
|     wfdata->whostate[k] = 0.0; | ||||
|   } | ||||
|  | ||||
|   /* next part should be in Matlab, writing to a global table */ | ||||
|   t = 0.5; | ||||
|   denum = 1.0 / ((double)PITCH_WLPCWINLEN); | ||||
|   denum2 = denum * denum; | ||||
|   for (k = 0; k < PITCH_WLPCWINLEN; k++) { | ||||
|     dtmp = PITCH_WLPCASYM * t * denum + (1 - PITCH_WLPCASYM) * t * t * denum2; | ||||
|     dtmp *= 3.14159265; | ||||
|     dtmp2 = sin(dtmp); | ||||
|     wfdata->window[k] = dtmp2 * dtmp2; | ||||
|     t++; | ||||
|   } | ||||
| } | ||||
|  | ||||
| void WebRtcIsac_InitPitchAnalysis(PitchAnalysisStruct* State) { | ||||
|   int k; | ||||
|  | ||||
|   for (k = 0; k < PITCH_CORR_LEN2 + PITCH_CORR_STEP2 + PITCH_MAX_LAG / 2 - | ||||
|                       PITCH_FRAME_LEN / 2 + 2; | ||||
|        k++) | ||||
|     State->dec_buffer[k] = 0.0; | ||||
|   for (k = 0; k < 2 * ALLPASSSECTIONS + 1; k++) | ||||
|     State->decimator_state[k] = 0.0; | ||||
|   for (k = 0; k < 2; k++) | ||||
|     State->hp_state[k] = 0.0; | ||||
|   for (k = 0; k < QLOOKAHEAD; k++) | ||||
|     State->whitened_buf[k] = 0.0; | ||||
|   for (k = 0; k < QLOOKAHEAD; k++) | ||||
|     State->inbuf[k] = 0.0; | ||||
|  | ||||
|   WebRtcIsac_InitPitchFilter(&(State->PFstr_wght)); | ||||
|  | ||||
|   WebRtcIsac_InitPitchFilter(&(State->PFstr)); | ||||
|  | ||||
|   WebRtcIsac_InitWeightingFilter(&(State->Wghtstr)); | ||||
| } | ||||
|  | ||||
| void WebRtcIsac_InitPreFilterbank(PreFiltBankstr* prefiltdata) { | ||||
|   int k; | ||||
|  | ||||
|   for (k = 0; k < QLOOKAHEAD; k++) { | ||||
|     prefiltdata->INLABUF1[k] = 0; | ||||
|     prefiltdata->INLABUF2[k] = 0; | ||||
|  | ||||
|     prefiltdata->INLABUF1_float[k] = 0; | ||||
|     prefiltdata->INLABUF2_float[k] = 0; | ||||
|   } | ||||
|   for (k = 0; k < 2 * (QORDER - 1); k++) { | ||||
|     prefiltdata->INSTAT1[k] = 0; | ||||
|     prefiltdata->INSTAT2[k] = 0; | ||||
|     prefiltdata->INSTATLA1[k] = 0; | ||||
|     prefiltdata->INSTATLA2[k] = 0; | ||||
|  | ||||
|     prefiltdata->INSTAT1_float[k] = 0; | ||||
|     prefiltdata->INSTAT2_float[k] = 0; | ||||
|     prefiltdata->INSTATLA1_float[k] = 0; | ||||
|     prefiltdata->INSTATLA2_float[k] = 0; | ||||
|   } | ||||
|  | ||||
|   /* High pass filter states */ | ||||
|   prefiltdata->HPstates[0] = 0.0; | ||||
|   prefiltdata->HPstates[1] = 0.0; | ||||
|  | ||||
|   prefiltdata->HPstates_float[0] = 0.0f; | ||||
|   prefiltdata->HPstates_float[1] = 0.0f; | ||||
|  | ||||
|   return; | ||||
| } | ||||
|  | ||||
| double WebRtcIsac_LevDurb(double* a, double* k, double* r, size_t order) { | ||||
|   const double LEVINSON_EPS = 1.0e-10; | ||||
|  | ||||
|   double sum, alpha; | ||||
|   size_t m, m_h, i; | ||||
|   alpha = 0;  // warning -DH | ||||
|   a[0] = 1.0; | ||||
|   if (r[0] < LEVINSON_EPS) { /* if r[0] <= 0, set LPC coeff. to zero */ | ||||
|     for (i = 0; i < order; i++) { | ||||
|       k[i] = 0; | ||||
|       a[i + 1] = 0; | ||||
|     } | ||||
|   } else { | ||||
|     a[1] = k[0] = -r[1] / r[0]; | ||||
|     alpha = r[0] + r[1] * k[0]; | ||||
|     for (m = 1; m < order; m++) { | ||||
|       sum = r[m + 1]; | ||||
|       for (i = 0; i < m; i++) { | ||||
|         sum += a[i + 1] * r[m - i]; | ||||
|       } | ||||
|       k[m] = -sum / alpha; | ||||
|       alpha += k[m] * sum; | ||||
|       m_h = (m + 1) >> 1; | ||||
|       for (i = 0; i < m_h; i++) { | ||||
|         sum = a[i + 1] + k[m] * a[m - i]; | ||||
|         a[m - i] += k[m] * a[i + 1]; | ||||
|         a[i + 1] = sum; | ||||
|       } | ||||
|       a[m + 1] = k[m]; | ||||
|     } | ||||
|   } | ||||
|   return alpha; | ||||
| } | ||||
|  | ||||
| /* The upper channel all-pass filter factors */ | ||||
| const float WebRtcIsac_kUpperApFactorsFloat[2] = {0.03470000000000f, | ||||
|                                                   0.38260000000000f}; | ||||
|  | ||||
| /* The lower channel all-pass filter factors */ | ||||
| const float WebRtcIsac_kLowerApFactorsFloat[2] = {0.15440000000000f, | ||||
|                                                   0.74400000000000f}; | ||||
|  | ||||
| /* This function performs all-pass filtering--a series of first order all-pass | ||||
|  * sections are used to filter the input in a cascade manner. | ||||
|  * The input is overwritten!! | ||||
|  */ | ||||
| void WebRtcIsac_AllPassFilter2Float(float* InOut, | ||||
|                                     const float* APSectionFactors, | ||||
|                                     int lengthInOut, | ||||
|                                     int NumberOfSections, | ||||
|                                     float* FilterState) { | ||||
|   int n, j; | ||||
|   float temp; | ||||
|   for (j = 0; j < NumberOfSections; j++) { | ||||
|     for (n = 0; n < lengthInOut; n++) { | ||||
|       temp = FilterState[j] + APSectionFactors[j] * InOut[n]; | ||||
|       FilterState[j] = -APSectionFactors[j] * temp + InOut[n]; | ||||
|       InOut[n] = temp; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| /* The number of composite all-pass filter factors */ | ||||
| #define NUMBEROFCOMPOSITEAPSECTIONS 4 | ||||
|  | ||||
| /* Function WebRtcIsac_SplitAndFilter | ||||
|  * This function creates low-pass and high-pass decimated versions of part of | ||||
|  the input signal, and part of the signal in the input 'lookahead buffer'. | ||||
|  | ||||
|  INPUTS: | ||||
|  in: a length FRAMESAMPLES array of input samples | ||||
|  prefiltdata: input data structure containing the filterbank states | ||||
|  and lookahead samples from the previous encoding | ||||
|  iteration. | ||||
|  OUTPUTS: | ||||
|  LP: a FRAMESAMPLES_HALF array of low-pass filtered samples that | ||||
|  have been phase equalized.  The first QLOOKAHEAD samples are | ||||
|  based on the samples in the two prefiltdata->INLABUFx arrays | ||||
|  each of length QLOOKAHEAD. | ||||
|  The remaining FRAMESAMPLES_HALF-QLOOKAHEAD samples are based | ||||
|  on the first FRAMESAMPLES_HALF-QLOOKAHEAD samples of the input | ||||
|  array in[]. | ||||
|  HP: a FRAMESAMPLES_HALF array of high-pass filtered samples that | ||||
|  have been phase equalized.  The first QLOOKAHEAD samples are | ||||
|  based on the samples in the two prefiltdata->INLABUFx arrays | ||||
|  each of length QLOOKAHEAD. | ||||
|  The remaining FRAMESAMPLES_HALF-QLOOKAHEAD samples are based | ||||
|  on the first FRAMESAMPLES_HALF-QLOOKAHEAD samples of the input | ||||
|  array in[]. | ||||
|  | ||||
|  LP_la: a FRAMESAMPLES_HALF array of low-pass filtered samples. | ||||
|  These samples are not phase equalized. They are computed | ||||
|  from the samples in the in[] array. | ||||
|  HP_la: a FRAMESAMPLES_HALF array of high-pass filtered samples | ||||
|  that are not phase equalized. They are computed from | ||||
|  the in[] vector. | ||||
|  prefiltdata: this input data structure's filterbank state and | ||||
|  lookahead sample buffers are updated for the next | ||||
|  encoding iteration. | ||||
| */ | ||||
| void WebRtcIsac_SplitAndFilterFloat(float* pin, | ||||
|                                     float* LP, | ||||
|                                     float* HP, | ||||
|                                     double* LP_la, | ||||
|                                     double* HP_la, | ||||
|                                     PreFiltBankstr* prefiltdata) { | ||||
|   int k, n; | ||||
|   float CompositeAPFilterState[NUMBEROFCOMPOSITEAPSECTIONS]; | ||||
|   float ForTransform_CompositeAPFilterState[NUMBEROFCOMPOSITEAPSECTIONS]; | ||||
|   float ForTransform_CompositeAPFilterState2[NUMBEROFCOMPOSITEAPSECTIONS]; | ||||
|   float tempinoutvec[FRAMESAMPLES + MAX_AR_MODEL_ORDER]; | ||||
|   float tempin_ch1[FRAMESAMPLES + MAX_AR_MODEL_ORDER]; | ||||
|   float tempin_ch2[FRAMESAMPLES + MAX_AR_MODEL_ORDER]; | ||||
|   float in[FRAMESAMPLES]; | ||||
|   float ftmp; | ||||
|  | ||||
|   /* HPstcoeff_in = {a1, a2, b1 - b0 * a1, b2 - b0 * a2}; */ | ||||
|   static const float kHpStCoefInFloat[4] = { | ||||
|       -1.94895953203325f, 0.94984516000000f, -0.05101826139794f, | ||||
|       0.05015484000000f}; | ||||
|  | ||||
|   /* The composite all-pass filter factors */ | ||||
|   static const float WebRtcIsac_kCompositeApFactorsFloat[4] = { | ||||
|       0.03470000000000f, 0.15440000000000f, 0.38260000000000f, | ||||
|       0.74400000000000f}; | ||||
|  | ||||
|   // The matrix for transforming the backward composite state to upper channel | ||||
|   // state. | ||||
|   static const float WebRtcIsac_kTransform1Float[8] = { | ||||
|       -0.00158678506084f, 0.00127157815343f, -0.00104805672709f, | ||||
|       0.00084837248079f,  0.00134467983258f, -0.00107756549387f, | ||||
|       0.00088814793277f,  -0.00071893072525f}; | ||||
|  | ||||
|   // The matrix for transforming the backward composite state to lower channel | ||||
|   // state. | ||||
|   static const float WebRtcIsac_kTransform2Float[8] = { | ||||
|       -0.00170686041697f, 0.00136780109829f, -0.00112736532350f, | ||||
|       0.00091257055385f,  0.00103094281812f, -0.00082615076557f, | ||||
|       0.00068092756088f,  -0.00055119165484f}; | ||||
|  | ||||
|   /* High pass filter */ | ||||
|  | ||||
|   for (k = 0; k < FRAMESAMPLES; k++) { | ||||
|     in[k] = pin[k] + kHpStCoefInFloat[2] * prefiltdata->HPstates_float[0] + | ||||
|             kHpStCoefInFloat[3] * prefiltdata->HPstates_float[1]; | ||||
|     ftmp = pin[k] - kHpStCoefInFloat[0] * prefiltdata->HPstates_float[0] - | ||||
|            kHpStCoefInFloat[1] * prefiltdata->HPstates_float[1]; | ||||
|     prefiltdata->HPstates_float[1] = prefiltdata->HPstates_float[0]; | ||||
|     prefiltdata->HPstates_float[0] = ftmp; | ||||
|   } | ||||
|  | ||||
|   /* First Channel */ | ||||
|  | ||||
|   /*initial state of composite filter is zero */ | ||||
|   for (k = 0; k < NUMBEROFCOMPOSITEAPSECTIONS; k++) { | ||||
|     CompositeAPFilterState[k] = 0.0; | ||||
|   } | ||||
|   /* put every other sample of input into a temporary vector in reverse | ||||
|    * (backward) order*/ | ||||
|   for (k = 0; k < FRAMESAMPLES_HALF; k++) { | ||||
|     tempinoutvec[k] = in[FRAMESAMPLES - 1 - 2 * k]; | ||||
|   } | ||||
|  | ||||
|   /* now all-pass filter the backwards vector.  Output values overwrite the | ||||
|    * input vector. */ | ||||
|   WebRtcIsac_AllPassFilter2Float( | ||||
|       tempinoutvec, WebRtcIsac_kCompositeApFactorsFloat, FRAMESAMPLES_HALF, | ||||
|       NUMBEROFCOMPOSITEAPSECTIONS, CompositeAPFilterState); | ||||
|  | ||||
|   /* save the backwards filtered output for later forward filtering, | ||||
|      but write it in forward order*/ | ||||
|   for (k = 0; k < FRAMESAMPLES_HALF; k++) { | ||||
|     tempin_ch1[FRAMESAMPLES_HALF + QLOOKAHEAD - 1 - k] = tempinoutvec[k]; | ||||
|   } | ||||
|  | ||||
|   /* save the backwards filter state  becaue it will be transformed | ||||
|      later into a forward state */ | ||||
|   for (k = 0; k < NUMBEROFCOMPOSITEAPSECTIONS; k++) { | ||||
|     ForTransform_CompositeAPFilterState[k] = CompositeAPFilterState[k]; | ||||
|   } | ||||
|  | ||||
|   /* now backwards filter the samples in the lookahead buffer. The samples were | ||||
|      placed there in the encoding of the previous frame.  The output samples | ||||
|      overwrite the input samples */ | ||||
|   WebRtcIsac_AllPassFilter2Float( | ||||
|       prefiltdata->INLABUF1_float, WebRtcIsac_kCompositeApFactorsFloat, | ||||
|       QLOOKAHEAD, NUMBEROFCOMPOSITEAPSECTIONS, CompositeAPFilterState); | ||||
|  | ||||
|   /* save the output, but write it in forward order */ | ||||
|   /* write the lookahead samples for the next encoding iteration. Every other | ||||
|      sample at the end of the input frame is written in reverse order for the | ||||
|      lookahead length. Exported in the prefiltdata structure. */ | ||||
|   for (k = 0; k < QLOOKAHEAD; k++) { | ||||
|     tempin_ch1[QLOOKAHEAD - 1 - k] = prefiltdata->INLABUF1_float[k]; | ||||
|     prefiltdata->INLABUF1_float[k] = in[FRAMESAMPLES - 1 - 2 * k]; | ||||
|   } | ||||
|  | ||||
|   /* Second Channel.  This is exactly like the first channel, except that the | ||||
|      even samples are now filtered instead (lower channel). */ | ||||
|   for (k = 0; k < NUMBEROFCOMPOSITEAPSECTIONS; k++) { | ||||
|     CompositeAPFilterState[k] = 0.0; | ||||
|   } | ||||
|  | ||||
|   for (k = 0; k < FRAMESAMPLES_HALF; k++) { | ||||
|     tempinoutvec[k] = in[FRAMESAMPLES - 2 - 2 * k]; | ||||
|   } | ||||
|  | ||||
|   WebRtcIsac_AllPassFilter2Float( | ||||
|       tempinoutvec, WebRtcIsac_kCompositeApFactorsFloat, FRAMESAMPLES_HALF, | ||||
|       NUMBEROFCOMPOSITEAPSECTIONS, CompositeAPFilterState); | ||||
|  | ||||
|   for (k = 0; k < FRAMESAMPLES_HALF; k++) { | ||||
|     tempin_ch2[FRAMESAMPLES_HALF + QLOOKAHEAD - 1 - k] = tempinoutvec[k]; | ||||
|   } | ||||
|  | ||||
|   for (k = 0; k < NUMBEROFCOMPOSITEAPSECTIONS; k++) { | ||||
|     ForTransform_CompositeAPFilterState2[k] = CompositeAPFilterState[k]; | ||||
|   } | ||||
|  | ||||
|   WebRtcIsac_AllPassFilter2Float( | ||||
|       prefiltdata->INLABUF2_float, WebRtcIsac_kCompositeApFactorsFloat, | ||||
|       QLOOKAHEAD, NUMBEROFCOMPOSITEAPSECTIONS, CompositeAPFilterState); | ||||
|  | ||||
|   for (k = 0; k < QLOOKAHEAD; k++) { | ||||
|     tempin_ch2[QLOOKAHEAD - 1 - k] = prefiltdata->INLABUF2_float[k]; | ||||
|     prefiltdata->INLABUF2_float[k] = in[FRAMESAMPLES - 2 - 2 * k]; | ||||
|   } | ||||
|  | ||||
|   /* Transform filter states from backward to forward */ | ||||
|   /*At this point, each of the states of the backwards composite filters for the | ||||
|     two channels are transformed into forward filtering states for the | ||||
|     corresponding forward channel filters.  Each channel's forward filtering | ||||
|     state from the previous | ||||
|     encoding iteration is added to the transformed state to get a proper forward | ||||
|     state */ | ||||
|  | ||||
|   /* So the existing NUMBEROFCOMPOSITEAPSECTIONS x 1 (4x1) state vector is | ||||
|      multiplied by a NUMBEROFCHANNELAPSECTIONSxNUMBEROFCOMPOSITEAPSECTIONS (2x4) | ||||
|      transform matrix to get the new state that is added to the previous 2x1 | ||||
|      input state */ | ||||
|  | ||||
|   for (k = 0; k < NUMBEROFCHANNELAPSECTIONS; k++) { /* k is row variable */ | ||||
|     for (n = 0; n < NUMBEROFCOMPOSITEAPSECTIONS; | ||||
|          n++) { /* n is column variable */ | ||||
|       prefiltdata->INSTAT1_float[k] += | ||||
|           ForTransform_CompositeAPFilterState[n] * | ||||
|           WebRtcIsac_kTransform1Float[k * NUMBEROFCHANNELAPSECTIONS + n]; | ||||
|       prefiltdata->INSTAT2_float[k] += | ||||
|           ForTransform_CompositeAPFilterState2[n] * | ||||
|           WebRtcIsac_kTransform2Float[k * NUMBEROFCHANNELAPSECTIONS + n]; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /*obtain polyphase components by forward all-pass filtering through each | ||||
|    * channel */ | ||||
|   /* the backward filtered samples are now forward filtered with the | ||||
|    * corresponding channel filters */ | ||||
|   /* The all pass filtering automatically updates the filter states which are | ||||
|      exported in the prefiltdata structure */ | ||||
|   WebRtcIsac_AllPassFilter2Float(tempin_ch1, WebRtcIsac_kUpperApFactorsFloat, | ||||
|                                  FRAMESAMPLES_HALF, NUMBEROFCHANNELAPSECTIONS, | ||||
|                                  prefiltdata->INSTAT1_float); | ||||
|   WebRtcIsac_AllPassFilter2Float(tempin_ch2, WebRtcIsac_kLowerApFactorsFloat, | ||||
|                                  FRAMESAMPLES_HALF, NUMBEROFCHANNELAPSECTIONS, | ||||
|                                  prefiltdata->INSTAT2_float); | ||||
|  | ||||
|   /* Now Construct low-pass and high-pass signals as combinations of polyphase | ||||
|    * components */ | ||||
|   for (k = 0; k < FRAMESAMPLES_HALF; k++) { | ||||
|     LP[k] = 0.5f * (tempin_ch1[k] + tempin_ch2[k]); /* low pass signal*/ | ||||
|     HP[k] = 0.5f * (tempin_ch1[k] - tempin_ch2[k]); /* high pass signal*/ | ||||
|   } | ||||
|  | ||||
|   /* Lookahead LP and HP signals */ | ||||
|   /* now create low pass and high pass signals of the input vector.  However, no | ||||
|      backwards filtering is performed, and hence no phase equalization is | ||||
|      involved. Also, the input contains some samples that are lookahead samples. | ||||
|      The high pass and low pass signals that are created are used outside this | ||||
|      function for analysis (not encoding) purposes */ | ||||
|  | ||||
|   /* set up input */ | ||||
|   for (k = 0; k < FRAMESAMPLES_HALF; k++) { | ||||
|     tempin_ch1[k] = in[2 * k + 1]; | ||||
|     tempin_ch2[k] = in[2 * k]; | ||||
|   } | ||||
|  | ||||
|   /* the input filter states are passed in and updated by the all-pass filtering | ||||
|      routine and exported in the prefiltdata structure*/ | ||||
|   WebRtcIsac_AllPassFilter2Float(tempin_ch1, WebRtcIsac_kUpperApFactorsFloat, | ||||
|                                  FRAMESAMPLES_HALF, NUMBEROFCHANNELAPSECTIONS, | ||||
|                                  prefiltdata->INSTATLA1_float); | ||||
|   WebRtcIsac_AllPassFilter2Float(tempin_ch2, WebRtcIsac_kLowerApFactorsFloat, | ||||
|                                  FRAMESAMPLES_HALF, NUMBEROFCHANNELAPSECTIONS, | ||||
|                                  prefiltdata->INSTATLA2_float); | ||||
|  | ||||
|   for (k = 0; k < FRAMESAMPLES_HALF; k++) { | ||||
|     LP_la[k] = (float)(0.5f * (tempin_ch1[k] + tempin_ch2[k]));  /*low pass */ | ||||
|     HP_la[k] = (double)(0.5f * (tempin_ch1[k] - tempin_ch2[k])); /* high pass */ | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,45 @@ | ||||
| /* | ||||
|  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. | ||||
|  * | ||||
|  *  Use of this source code is governed by a BSD-style license | ||||
|  *  that can be found in the LICENSE file in the root of the source | ||||
|  *  tree. An additional intellectual property rights grant can be found | ||||
|  *  in the file PATENTS.  All contributing project authors may | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_VAD_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_VAD_H_ | ||||
|  | ||||
| #include <stddef.h> | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
|  | ||||
| void WebRtcIsac_InitPitchFilter(PitchFiltstr* pitchfiltdata); | ||||
| void WebRtcIsac_InitPitchAnalysis(PitchAnalysisStruct* state); | ||||
| void WebRtcIsac_InitPreFilterbank(PreFiltBankstr* prefiltdata); | ||||
|  | ||||
| double WebRtcIsac_LevDurb(double* a, double* k, double* r, size_t order); | ||||
|  | ||||
| /* The number of all-pass filter factors in an upper or lower channel*/ | ||||
| #define NUMBEROFCHANNELAPSECTIONS 2 | ||||
|  | ||||
| /* The upper channel all-pass filter factors */ | ||||
| extern const float WebRtcIsac_kUpperApFactorsFloat[2]; | ||||
|  | ||||
| /* The lower channel all-pass filter factors */ | ||||
| extern const float WebRtcIsac_kLowerApFactorsFloat[2]; | ||||
|  | ||||
| void WebRtcIsac_AllPassFilter2Float(float* InOut, | ||||
|                                     const float* APSectionFactors, | ||||
|                                     int lengthInOut, | ||||
|                                     int NumberOfSections, | ||||
|                                     float* FilterState); | ||||
| void WebRtcIsac_SplitAndFilterFloat(float* in, | ||||
|                                     float* LP, | ||||
|                                     float* HP, | ||||
|                                     double* LP_la, | ||||
|                                     double* HP_la, | ||||
|                                     PreFiltBankstr* prefiltdata); | ||||
|  | ||||
| #endif  // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_VAD_H_ | ||||
| @@ -14,8 +14,6 @@ | ||||
|  * contains the normalized lattice filter routines (MA and AR) for iSAC codec | ||||
|  * | ||||
|  */ | ||||
| #include "settings.h" | ||||
| #include "codec.h" | ||||
|  | ||||
| #include <math.h> | ||||
| #include <memory.h> | ||||
| @@ -24,6 +22,9 @@ | ||||
| #include <stdlib.h> | ||||
| #endif | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/codec.h" | ||||
|  | ||||
| /* filter the signal using normalized lattice filter */ | ||||
| /* MA filter */ | ||||
| void WebRtcIsac_NormLatticeFilterMa(int orderCoef, | ||||
|   | ||||
| @@ -8,16 +8,15 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "lpc_analysis.h" | ||||
| #include "settings.h" | ||||
| #include "codec.h" | ||||
| #include "entropy_coding.h" | ||||
|  | ||||
| #include <math.h> | ||||
| #include <string.h> | ||||
|  | ||||
| #define LEVINSON_EPS    1.0e-10 | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_analysis.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/codec.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/filter_functions.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/isac_vad.h" | ||||
|  | ||||
| /* window */ | ||||
| /* Matlab generation code: | ||||
| @@ -75,45 +74,10 @@ static const double kLpcCorrWindow[WINLEN] = { | ||||
|   0.00155690, 0.00124918, 0.00094895, 0.00066112, 0.00039320, 0.00015881 | ||||
| }; | ||||
|  | ||||
| double WebRtcIsac_LevDurb(double *a, double *k, double *r, size_t order) | ||||
| { | ||||
|  | ||||
|   double sum, alpha; | ||||
|   size_t m, m_h, i; | ||||
|   alpha = 0; //warning -DH | ||||
|   a[0] = 1.0; | ||||
|   if (r[0] < LEVINSON_EPS) { /* if r[0] <= 0, set LPC coeff. to zero */ | ||||
|     for (i = 0; i < order; i++) { | ||||
|       k[i] = 0; | ||||
|       a[i+1] = 0; | ||||
|     } | ||||
|   } else { | ||||
|     a[1] = k[0] = -r[1]/r[0]; | ||||
|     alpha = r[0] + r[1] * k[0]; | ||||
|     for (m = 1; m < order; m++){ | ||||
|       sum = r[m + 1]; | ||||
|       for (i = 0; i < m; i++){ | ||||
|         sum += a[i+1] * r[m - i]; | ||||
|       } | ||||
|       k[m] = -sum / alpha; | ||||
|       alpha += k[m] * sum; | ||||
|       m_h = (m + 1) >> 1; | ||||
|       for (i = 0; i < m_h; i++){ | ||||
|         sum = a[i+1] + k[m] * a[m - i]; | ||||
|         a[m - i] += k[m] * a[i+1]; | ||||
|         a[i+1] = sum; | ||||
|       } | ||||
|       a[m+1] = k[m]; | ||||
|     } | ||||
|   } | ||||
|   return alpha; | ||||
| } | ||||
|  | ||||
|  | ||||
| //was static before, but didn't work with MEX file | ||||
| void WebRtcIsac_GetVars(const double *input, const int16_t *pitchGains_Q12, | ||||
|                        double *oldEnergy, double *varscale) | ||||
| { | ||||
| static void WebRtcIsac_GetVars(const double* input, | ||||
|                                const int16_t* pitchGains_Q12, | ||||
|                                double* oldEnergy, | ||||
|                                double* varscale) { | ||||
|   double nrg[4], chng, pg; | ||||
|   int k; | ||||
|  | ||||
| @@ -162,12 +126,9 @@ void WebRtcIsac_GetVars(const double *input, const int16_t *pitchGains_Q12, | ||||
|   *oldEnergy = nrg[3]; | ||||
| } | ||||
|  | ||||
| void | ||||
| WebRtcIsac_GetVarsUB( | ||||
|     const double* input, | ||||
|     double*       oldEnergy, | ||||
|     double*       varscale) | ||||
| { | ||||
| static void WebRtcIsac_GetVarsUB(const double* input, | ||||
|                                  double* oldEnergy, | ||||
|                                  double* varscale) { | ||||
|   double nrg[4], chng; | ||||
|   int k; | ||||
|  | ||||
|   | ||||
| @@ -15,36 +15,32 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_ANALYSIS_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_ANALYSIS_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_ANALYSIS_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_ANALYSIS_H_ | ||||
|  | ||||
| #include "settings.h" | ||||
| #include "structs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
|  | ||||
| double WebRtcIsac_LevDurb(double *a, double *k, double *r, size_t order); | ||||
| void WebRtcIsac_GetLpcCoefLb(double* inLo, | ||||
|                              double* inHi, | ||||
|                              MaskFiltstr* maskdata, | ||||
|                              double signal_noise_ratio, | ||||
|                              const int16_t* pitchGains_Q12, | ||||
|                              double* lo_coeff, | ||||
|                              double* hi_coeff); | ||||
|  | ||||
| void WebRtcIsac_GetVars(const double *input, const int16_t *pitchGains_Q12, | ||||
|                        double *oldEnergy, double *varscale); | ||||
| void WebRtcIsac_GetLpcGain(double signal_noise_ratio, | ||||
|                            const double* filtCoeffVecs, | ||||
|                            int numVecs, | ||||
|                            double* gain, | ||||
|                            double corrLo[][UB_LPC_ORDER + 1], | ||||
|                            const double* varscale); | ||||
|  | ||||
| void WebRtcIsac_GetLpcCoefLb(double *inLo, double *inHi, MaskFiltstr *maskdata, | ||||
|                              double signal_noise_ratio, const int16_t *pitchGains_Q12, | ||||
|                              double *lo_coeff, double *hi_coeff); | ||||
| void WebRtcIsac_GetLpcCoefUb(double* inSignal, | ||||
|                              MaskFiltstr* maskdata, | ||||
|                              double* lpCoeff, | ||||
|                              double corr[][UB_LPC_ORDER + 1], | ||||
|                              double* varscale, | ||||
|                              int16_t bandwidth); | ||||
|  | ||||
|  | ||||
| void WebRtcIsac_GetLpcGain( | ||||
|     double         signal_noise_ratio, | ||||
|     const double*  filtCoeffVecs, | ||||
|     int            numVecs, | ||||
|     double*        gain, | ||||
|     double         corrLo[][UB_LPC_ORDER + 1], | ||||
|     const double*  varscale); | ||||
|  | ||||
| void WebRtcIsac_GetLpcCoefUb( | ||||
|     double*      inSignal, | ||||
|     MaskFiltstr* maskdata, | ||||
|     double*      lpCoeff, | ||||
|     double       corr[][UB_LPC_ORDER + 1], | ||||
|     double*      varscale, | ||||
|     int16_t  bandwidth); | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_ANALYIS_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_ANALYIS_H_ */ | ||||
|   | ||||
| @@ -16,9 +16,8 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include "lpc_gain_swb_tables.h" | ||||
| #include "settings.h" | ||||
| #include "webrtc/typedefs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
| const double WebRtcIsac_kQSizeLpcGain = 0.100000; | ||||
|  | ||||
|   | ||||
| @@ -16,11 +16,12 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_GAIN_SWB_TABLES_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_GAIN_SWB_TABLES_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_GAIN_SWB_TABLES_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_GAIN_SWB_TABLES_H_ | ||||
|  | ||||
| #include "settings.h" | ||||
| #include "webrtc/typedefs.h" | ||||
| #include <stdint.h> | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
| extern const double WebRtcIsac_kQSizeLpcGain; | ||||
|  | ||||
| @@ -46,4 +47,4 @@ extern const uint16_t* WebRtcIsac_kLpcGainCdfMat[SUBFRAMES]; | ||||
|  | ||||
| extern const double WebRtcIsac_kLpcGainDecorrMat[SUBFRAMES][SUBFRAMES]; | ||||
|  | ||||
| #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_GAIN_SWB_TABLES_H_ | ||||
| #endif  // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_GAIN_SWB_TABLES_H_ | ||||
|   | ||||
| @@ -16,9 +16,8 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include "lpc_shape_swb12_tables.h" | ||||
| #include "settings.h" | ||||
| #include "webrtc/typedefs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
| /* | ||||
| * Mean value of LAR | ||||
|   | ||||
| @@ -16,32 +16,33 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB12_TABLES_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB12_TABLES_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB12_TABLES_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB12_TABLES_H_ | ||||
|  | ||||
| #include "settings.h" | ||||
| #include "webrtc/typedefs.h" | ||||
| #include <stdint.h> | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
| extern const double WebRtcIsac_kMeanLarUb12[UB_LPC_ORDER]; | ||||
|  | ||||
| extern const double WebRtcIsac_kMeanLpcGain; | ||||
|  | ||||
| extern const double WebRtcIsac_kIntraVecDecorrMatUb12[UB_LPC_ORDER][UB_LPC_ORDER]; | ||||
| extern const double WebRtcIsac_kIntraVecDecorrMatUb12[UB_LPC_ORDER] | ||||
|                                                      [UB_LPC_ORDER]; | ||||
|  | ||||
| extern const double WebRtcIsac_kInterVecDecorrMatUb12 | ||||
| [UB_LPC_VEC_PER_FRAME][UB_LPC_VEC_PER_FRAME]; | ||||
| extern const double WebRtcIsac_kInterVecDecorrMatUb12[UB_LPC_VEC_PER_FRAME] | ||||
|                                                      [UB_LPC_VEC_PER_FRAME]; | ||||
|  | ||||
| extern const double WebRtcIsac_kLpcShapeQStepSizeUb12; | ||||
|  | ||||
| extern const double WebRtcIsac_kLpcShapeLeftRecPointUb12 | ||||
| [UB_LPC_ORDER*UB_LPC_VEC_PER_FRAME]; | ||||
| extern const double | ||||
|     WebRtcIsac_kLpcShapeLeftRecPointUb12[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; | ||||
|  | ||||
| extern const int16_t | ||||
|     WebRtcIsac_kLpcShapeNumRecPointUb12[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; | ||||
|  | ||||
| extern const int16_t WebRtcIsac_kLpcShapeNumRecPointUb12 | ||||
| [UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; | ||||
|  | ||||
| extern const uint16_t WebRtcIsac_kLpcShapeEntropySearchUb12 | ||||
| [UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; | ||||
| extern const uint16_t | ||||
|     WebRtcIsac_kLpcShapeEntropySearchUb12[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; | ||||
|  | ||||
| extern const uint16_t WebRtcIsac_kLpcShapeCdfVec0Ub12[14]; | ||||
|  | ||||
| @@ -59,7 +60,7 @@ extern const uint16_t WebRtcIsac_kLpcShapeCdfVec6Ub12[33]; | ||||
|  | ||||
| extern const uint16_t WebRtcIsac_kLpcShapeCdfVec7Ub12[49]; | ||||
|  | ||||
| extern const uint16_t* WebRtcIsac_kLpcShapeCdfMatUb12 | ||||
| [UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; | ||||
| extern const uint16_t* | ||||
|     WebRtcIsac_kLpcShapeCdfMatUb12[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; | ||||
|  | ||||
| #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB12_TABLES_H_ | ||||
| #endif  // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB12_TABLES_H_ | ||||
|   | ||||
| @@ -16,9 +16,8 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include "lpc_shape_swb16_tables.h" | ||||
| #include "settings.h" | ||||
| #include "webrtc/typedefs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
| /* | ||||
| * Mean value of LAR | ||||
|   | ||||
| @@ -16,18 +16,20 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB16_TABLES_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB16_TABLES_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB16_TABLES_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB16_TABLES_H_ | ||||
|  | ||||
| #include "settings.h" | ||||
| #include "webrtc/typedefs.h" | ||||
| #include <stdint.h> | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
| extern const double WebRtcIsac_kMeanLarUb16[UB_LPC_ORDER]; | ||||
|  | ||||
| extern const double WebRtcIsac_kIintraVecDecorrMatUb16[UB_LPC_ORDER][UB_LPC_ORDER]; | ||||
| extern const double WebRtcIsac_kIintraVecDecorrMatUb16[UB_LPC_ORDER] | ||||
|                                                       [UB_LPC_ORDER]; | ||||
|  | ||||
| extern const double WebRtcIsac_kInterVecDecorrMatUb16 | ||||
| [UB16_LPC_VEC_PER_FRAME][UB16_LPC_VEC_PER_FRAME]; | ||||
| extern const double WebRtcIsac_kInterVecDecorrMatUb16[UB16_LPC_VEC_PER_FRAME] | ||||
|                                                      [UB16_LPC_VEC_PER_FRAME]; | ||||
|  | ||||
| extern const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub16[14]; | ||||
|  | ||||
| @@ -61,18 +63,19 @@ extern const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub165[34]; | ||||
|  | ||||
| extern const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub166[71]; | ||||
|  | ||||
| extern const uint16_t* WebRtcIsac_kLpcShapeCdfMatUb16 | ||||
| [UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; | ||||
| extern const uint16_t* | ||||
|     WebRtcIsac_kLpcShapeCdfMatUb16[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; | ||||
|  | ||||
| extern const double WebRtcIsac_kLpcShapeLeftRecPointUb16 | ||||
| [UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; | ||||
| extern const double | ||||
|     WebRtcIsac_kLpcShapeLeftRecPointUb16[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; | ||||
|  | ||||
| extern const int16_t WebRtcIsac_kLpcShapeNumRecPointUb16 | ||||
| [UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; | ||||
| extern const int16_t | ||||
|     WebRtcIsac_kLpcShapeNumRecPointUb16[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; | ||||
|  | ||||
| extern const uint16_t WebRtcIsac_kLpcShapeEntropySearchUb16 | ||||
| [UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; | ||||
| extern const uint16_t | ||||
|     WebRtcIsac_kLpcShapeEntropySearchUb16[UB_LPC_ORDER * | ||||
|                                           UB16_LPC_VEC_PER_FRAME]; | ||||
|  | ||||
| extern const double WebRtcIsac_kLpcShapeQStepSizeUb16; | ||||
|  | ||||
| #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB16_TABLES_H_ | ||||
| #endif  // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB16_TABLES_H_ | ||||
|   | ||||
| @@ -10,8 +10,8 @@ | ||||
|  | ||||
| /* coding tables for the KLT coefficients */ | ||||
|  | ||||
| #include "lpc_tables.h" | ||||
| #include "settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/lpc_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
| /* cdf array for model indicator */ | ||||
| const uint16_t WebRtcIsac_kQKltModelCdf[4] = { | ||||
|   | ||||
| @@ -15,34 +15,33 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_TABLES_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_TABLES_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_TABLES_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_TABLES_H_ | ||||
|  | ||||
| #include "structs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
|  | ||||
| #include "settings.h" | ||||
| #define KLT_STEPSIZE 1.00000000 | ||||
| #define KLT_NUM_AVG_GAIN 0 | ||||
| #define KLT_NUM_AVG_SHAPE 0 | ||||
| #define KLT_NUM_MODELS 3 | ||||
| #define LPC_GAIN_SCALE 4.000f | ||||
| #define LPC_LOBAND_SCALE 2.100f | ||||
| #define LPC_LOBAND_ORDER ORDERLO | ||||
| #define LPC_HIBAND_SCALE 0.450f | ||||
| #define LPC_HIBAND_ORDER ORDERHI | ||||
| #define LPC_GAIN_ORDER 2 | ||||
|  | ||||
| #define KLT_STEPSIZE         1.00000000 | ||||
| #define KLT_NUM_AVG_GAIN     0 | ||||
| #define KLT_NUM_AVG_SHAPE    0 | ||||
| #define KLT_NUM_MODELS  3 | ||||
| #define LPC_GAIN_SCALE     4.000f | ||||
| #define LPC_LOBAND_SCALE   2.100f | ||||
| #define LPC_LOBAND_ORDER   ORDERLO | ||||
| #define LPC_HIBAND_SCALE   0.450f | ||||
| #define LPC_HIBAND_ORDER   ORDERHI | ||||
| #define LPC_GAIN_ORDER     2 | ||||
| #define LPC_SHAPE_ORDER (LPC_LOBAND_ORDER + LPC_HIBAND_ORDER) | ||||
|  | ||||
| #define LPC_SHAPE_ORDER    (LPC_LOBAND_ORDER + LPC_HIBAND_ORDER) | ||||
|  | ||||
| #define KLT_ORDER_GAIN     (LPC_GAIN_ORDER * SUBFRAMES) | ||||
| #define KLT_ORDER_SHAPE    (LPC_SHAPE_ORDER * SUBFRAMES) | ||||
| #define KLT_ORDER_GAIN (LPC_GAIN_ORDER * SUBFRAMES) | ||||
| #define KLT_ORDER_SHAPE (LPC_SHAPE_ORDER * SUBFRAMES) | ||||
|  | ||||
| /* cdf array for model indicator */ | ||||
| extern const uint16_t WebRtcIsac_kQKltModelCdf[KLT_NUM_MODELS+1]; | ||||
| extern const uint16_t WebRtcIsac_kQKltModelCdf[KLT_NUM_MODELS + 1]; | ||||
|  | ||||
| /* pointer to cdf array for model indicator */ | ||||
| extern const uint16_t *WebRtcIsac_kQKltModelCdfPtr[1]; | ||||
| extern const uint16_t* WebRtcIsac_kQKltModelCdfPtr[1]; | ||||
|  | ||||
| /* initial cdf index for decoder of model indicator */ | ||||
| extern const uint16_t WebRtcIsac_kQKltModelInitIndex[1]; | ||||
| @@ -78,9 +77,9 @@ extern const uint16_t WebRtcIsac_kQKltCdfGain[404]; | ||||
| extern const uint16_t WebRtcIsac_kQKltCdfShape[686]; | ||||
|  | ||||
| /* pointers to cdf tables for quantizer indices */ | ||||
| extern const uint16_t *WebRtcIsac_kQKltCdfPtrGain[12]; | ||||
| extern const uint16_t* WebRtcIsac_kQKltCdfPtrGain[12]; | ||||
|  | ||||
| extern const uint16_t *WebRtcIsac_kQKltCdfPtrShape[108]; | ||||
| extern const uint16_t* WebRtcIsac_kQKltCdfPtrShape[108]; | ||||
|  | ||||
| /* left KLT transforms */ | ||||
| extern const double WebRtcIsac_kKltT1Gain[4]; | ||||
| @@ -97,4 +96,4 @@ extern const double WebRtcIsac_kLpcMeansGain[12]; | ||||
|  | ||||
| extern const double WebRtcIsac_kLpcMeansShape[108]; | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_TABLES_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_TABLES_H_ */ | ||||
|   | ||||
| @@ -8,12 +8,12 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_OS_SPECIFIC_INLINE_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_OS_SPECIFIC_INLINE_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_OS_SPECIFIC_INLINE_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_OS_SPECIFIC_INLINE_H_ | ||||
|  | ||||
| #include <math.h> | ||||
| #include "webrtc/typedefs.h" | ||||
|  | ||||
| #include "rtc_base/system/arch.h" | ||||
|  | ||||
| #if defined(WEBRTC_POSIX) | ||||
| #define WebRtcIsac_lrint lrint | ||||
| @@ -24,11 +24,12 @@ static __inline long int WebRtcIsac_lrint(double x_dbl) { | ||||
|   __asm { | ||||
|     fld x_dbl | ||||
|     fistp x_int | ||||
|   }; | ||||
|   } | ||||
|   ; | ||||
|  | ||||
|   return x_int; | ||||
| } | ||||
| #else // Do a slow but correct implementation of lrint | ||||
| #else  // Do a slow but correct implementation of lrint | ||||
|  | ||||
| static __inline long int WebRtcIsac_lrint(double x_dbl) { | ||||
|   long int x_int; | ||||
| @@ -38,4 +39,4 @@ static __inline long int WebRtcIsac_lrint(double x_dbl) { | ||||
|  | ||||
| #endif | ||||
|  | ||||
| #endif  // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_OS_SPECIFIC_INLINE_H_ | ||||
| #endif  // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_OS_SPECIFIC_INLINE_H_ | ||||
|   | ||||
| @@ -8,7 +8,7 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "pitch_estimator.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_estimator.h" | ||||
|  | ||||
| #include <math.h> | ||||
| #include <memory.h> | ||||
| @@ -17,6 +17,10 @@ | ||||
| #include <stdlib.h> | ||||
| #endif | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/filter_functions.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_filter.h" | ||||
| #include "rtc_base/system/ignore_warnings.h" | ||||
|  | ||||
| static const double kInterpolWin[8] = {-0.00067556028640,  0.02184247643159, -0.12203175715679,  0.60086484101160, | ||||
|                                        0.60086484101160, -0.12203175715679,  0.02184247643159, -0.00067556028640}; | ||||
|  | ||||
| @@ -122,13 +126,56 @@ static void PCorr(const double *in, double *outcorr) | ||||
|   } | ||||
| } | ||||
|  | ||||
| static void WebRtcIsac_AllpassFilterForDec(double* InOut, | ||||
|                                            const double* APSectionFactors, | ||||
|                                            size_t lengthInOut, | ||||
|                                            double* FilterState) { | ||||
|   // This performs all-pass filtering--a series of first order all-pass | ||||
|   // sections are used to filter the input in a cascade manner. | ||||
|   size_t n, j; | ||||
|   double temp; | ||||
|   for (j = 0; j < ALLPASSSECTIONS; j++) { | ||||
|     for (n = 0; n < lengthInOut; n += 2) { | ||||
|       temp = InOut[n];  // store input | ||||
|       InOut[n] = FilterState[j] + APSectionFactors[j] * temp; | ||||
|       FilterState[j] = -APSectionFactors[j] * InOut[n] + temp; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| void WebRtcIsac_InitializePitch(const double *in, | ||||
|                                 const double old_lag, | ||||
|                                 const double old_gain, | ||||
|                                 PitchAnalysisStruct *State, | ||||
|                                 double *lags) | ||||
| { | ||||
| static void WebRtcIsac_DecimateAllpass( | ||||
|     const double* in, | ||||
|     double* state_in,  // array of size: 2*ALLPASSSECTIONS+1 | ||||
|     size_t N,          // number of input samples | ||||
|     double* out) {     // array of size N/2 | ||||
|  | ||||
|   static const double APupper[ALLPASSSECTIONS] = {0.0347, 0.3826}; | ||||
|   static const double APlower[ALLPASSSECTIONS] = {0.1544, 0.744}; | ||||
|  | ||||
|   size_t n; | ||||
|   double data_vec[PITCH_FRAME_LEN]; | ||||
|  | ||||
|   /* copy input */ | ||||
|   memcpy(data_vec + 1, in, sizeof(double) * (N - 1)); | ||||
|  | ||||
|   data_vec[0] = state_in[2 * ALLPASSSECTIONS];  // the z^(-1) state | ||||
|   state_in[2 * ALLPASSSECTIONS] = in[N - 1]; | ||||
|  | ||||
|   WebRtcIsac_AllpassFilterForDec(data_vec + 1, APupper, N, state_in); | ||||
|   WebRtcIsac_AllpassFilterForDec(data_vec, APlower, N, | ||||
|                                  state_in + ALLPASSSECTIONS); | ||||
|  | ||||
|   for (n = 0; n < N / 2; n++) | ||||
|     out[n] = data_vec[2 * n] + data_vec[2 * n + 1]; | ||||
| } | ||||
|  | ||||
| RTC_PUSH_IGNORING_WFRAME_LARGER_THAN() | ||||
|  | ||||
| static void WebRtcIsac_InitializePitch(const double* in, | ||||
|                                        const double old_lag, | ||||
|                                        const double old_gain, | ||||
|                                        PitchAnalysisStruct* State, | ||||
|                                        double* lags) { | ||||
|   double buf_dec[PITCH_CORR_LEN2+PITCH_CORR_STEP2+PITCH_MAX_LAG/2+2]; | ||||
|   double ratio, log_lag, gain_bias; | ||||
|   double bias; | ||||
| @@ -449,7 +496,7 @@ void WebRtcIsac_InitializePitch(const double *in, | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| RTC_POP_IGNORING_WFRAME_LARGER_THAN() | ||||
|  | ||||
| /* create weighting matrix by orthogonalizing a basis of polynomials of increasing order | ||||
|  * t = (0:4)'; | ||||
| @@ -464,6 +511,29 @@ static const double kWeight[5][5] = { | ||||
|   { 0.01714285714286,   0.05142857142857,  -0.05714285714286,  -0.30857142857143,  0.29714285714286} | ||||
| }; | ||||
|  | ||||
| /* second order high-pass filter */ | ||||
| static void WebRtcIsac_Highpass(const double* in, | ||||
|                          double* out, | ||||
|                          double* state, | ||||
|                          size_t N) { | ||||
|   /* create high-pass filter ocefficients | ||||
|    * z = 0.998 * exp(j*2*pi*35/8000); | ||||
|    * p = 0.94 * exp(j*2*pi*140/8000); | ||||
|    * HP_b = [1, -2*real(z), abs(z)^2]; | ||||
|    * HP_a = [1, -2*real(p), abs(p)^2]; */ | ||||
|   static const double a_coef[2] = { 1.86864659625574, -0.88360000000000}; | ||||
|   static const double b_coef[2] = {-1.99524591718270,  0.99600400000000}; | ||||
|  | ||||
|   size_t k; | ||||
|  | ||||
|   for (k=0; k<N; k++) { | ||||
|     *out = *in + state[1]; | ||||
|     state[1] = state[0] + b_coef[0] * *in + a_coef[0] * *out; | ||||
|     state[0] = b_coef[1] * *in++ + a_coef[1] * *out++; | ||||
|   } | ||||
| } | ||||
|  | ||||
| RTC_PUSH_IGNORING_WFRAME_LARGER_THAN() | ||||
|  | ||||
| void WebRtcIsac_PitchAnalysis(const double *in,               /* PITCH_FRAME_LEN samples */ | ||||
|                               double *out,                    /* PITCH_FRAME_LEN+QLOOKAHEAD samples */ | ||||
| @@ -621,3 +691,5 @@ void WebRtcIsac_PitchAnalysis(const double *in,               /* PITCH_FRAME_LEN | ||||
|   for (k = 0; k < QLOOKAHEAD; k++) | ||||
|     State->inbuf[k] = inbuf[k + PITCH_FRAME_LEN]; | ||||
| } | ||||
|  | ||||
| RTC_POP_IGNORING_WFRAME_LARGER_THAN() | ||||
|   | ||||
| @@ -15,61 +15,18 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_ESTIMATOR_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_ESTIMATOR_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_ESTIMATOR_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_ESTIMATOR_H_ | ||||
|  | ||||
| #include "structs.h" | ||||
| #include <stddef.h> | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
|  | ||||
| void WebRtcIsac_PitchAnalysis( | ||||
|     const double* in, /* PITCH_FRAME_LEN samples */ | ||||
|     double* out,      /* PITCH_FRAME_LEN+QLOOKAHEAD samples */ | ||||
|     PitchAnalysisStruct* State, | ||||
|     double* lags, | ||||
|     double* gains); | ||||
|  | ||||
| void WebRtcIsac_PitchAnalysis(const double *in,               /* PITCH_FRAME_LEN samples */ | ||||
|                               double *out,                    /* PITCH_FRAME_LEN+QLOOKAHEAD samples */ | ||||
|                               PitchAnalysisStruct *State, | ||||
|                               double *lags, | ||||
|                               double *gains); | ||||
|  | ||||
| void WebRtcIsac_InitializePitch(const double *in, | ||||
|                                 const double old_lag, | ||||
|                                 const double old_gain, | ||||
|                                 PitchAnalysisStruct *State, | ||||
|                                 double *lags); | ||||
|  | ||||
| void WebRtcIsac_PitchfilterPre(double *indat, | ||||
|                                double *outdat, | ||||
|                                PitchFiltstr *pfp, | ||||
|                                double *lags, | ||||
|                                double *gains); | ||||
|  | ||||
| void WebRtcIsac_PitchfilterPost(double *indat, | ||||
|                                 double *outdat, | ||||
|                                 PitchFiltstr *pfp, | ||||
|                                 double *lags, | ||||
|                                 double *gains); | ||||
|  | ||||
| void WebRtcIsac_PitchfilterPre_la(double *indat, | ||||
|                                   double *outdat, | ||||
|                                   PitchFiltstr *pfp, | ||||
|                                   double *lags, | ||||
|                                   double *gains); | ||||
|  | ||||
| void WebRtcIsac_PitchfilterPre_gains(double *indat, | ||||
|                                      double *outdat, | ||||
|                                      double out_dG[][PITCH_FRAME_LEN + QLOOKAHEAD], | ||||
|                                      PitchFiltstr *pfp, | ||||
|                                      double *lags, | ||||
|                                      double *gains); | ||||
|  | ||||
| void WebRtcIsac_WeightingFilter(const double *in, double *weiout, double *whiout, WeightFiltstr *wfdata); | ||||
|  | ||||
| void WebRtcIsac_Highpass(const double *in, | ||||
|                          double *out, | ||||
|                          double *state, | ||||
|                          size_t N); | ||||
|  | ||||
| void WebRtcIsac_DecimateAllpass(const double *in, | ||||
|                                 double *state_in,  /* array of size: | ||||
|                                                     *     2*ALLPASSSECTIONS+1 */ | ||||
|                                 size_t N,          /* number of input samples */ | ||||
|                                 double *out);      /* array of size N/2 */ | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_ESTIMATOR_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_ESTIMATOR_H_ */ | ||||
|   | ||||
| @@ -8,13 +8,13 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "pitch_estimator.h" | ||||
|  | ||||
| #include <math.h> | ||||
| #include <memory.h> | ||||
| #include <stdlib.h> | ||||
|  | ||||
| #include "os_specific_inline.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_estimator.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/os_specific_inline.h" | ||||
| #include "rtc_base/compile_assert_c.h" | ||||
|  | ||||
| /* | ||||
|  * We are implementing the following filters; | ||||
| @@ -275,6 +275,11 @@ static void FilterFrame(const double* in_data, PitchFiltstr* filter_state, | ||||
|   /* Copy states to local variables. */ | ||||
|   memcpy(filter_parameters.buffer, filter_state->ubuf, | ||||
|          sizeof(filter_state->ubuf)); | ||||
|   RTC_COMPILE_ASSERT(sizeof(filter_parameters.buffer) >= | ||||
|                  sizeof(filter_state->ubuf)); | ||||
|   memset(filter_parameters.buffer + | ||||
|              sizeof(filter_state->ubuf) / sizeof(filter_state->ubuf[0]), | ||||
|          0, sizeof(filter_parameters.buffer) - sizeof(filter_state->ubuf)); | ||||
|   memcpy(filter_parameters.damper_state, filter_state->ystate, | ||||
|          sizeof(filter_state->ystate)); | ||||
|  | ||||
|   | ||||
| @@ -0,0 +1,42 @@ | ||||
| /* | ||||
|  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. | ||||
|  * | ||||
|  *  Use of this source code is governed by a BSD-style license | ||||
|  *  that can be found in the LICENSE file in the root of the source | ||||
|  *  tree. An additional intellectual property rights grant can be found | ||||
|  *  in the file PATENTS.  All contributing project authors may | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_FILTER_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_FILTER_H_ | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
|  | ||||
| void WebRtcIsac_PitchfilterPre(double* indat, | ||||
|                                double* outdat, | ||||
|                                PitchFiltstr* pfp, | ||||
|                                double* lags, | ||||
|                                double* gains); | ||||
|  | ||||
| void WebRtcIsac_PitchfilterPost(double* indat, | ||||
|                                 double* outdat, | ||||
|                                 PitchFiltstr* pfp, | ||||
|                                 double* lags, | ||||
|                                 double* gains); | ||||
|  | ||||
| void WebRtcIsac_PitchfilterPre_la(double* indat, | ||||
|                                   double* outdat, | ||||
|                                   PitchFiltstr* pfp, | ||||
|                                   double* lags, | ||||
|                                   double* gains); | ||||
|  | ||||
| void WebRtcIsac_PitchfilterPre_gains( | ||||
|     double* indat, | ||||
|     double* outdat, | ||||
|     double out_dG[][PITCH_FRAME_LEN + QLOOKAHEAD], | ||||
|     PitchFiltstr* pfp, | ||||
|     double* lags, | ||||
|     double* gains); | ||||
|  | ||||
| #endif  // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_FILTER_H_ | ||||
| @@ -8,9 +8,8 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "pitch_gain_tables.h" | ||||
|  | ||||
| #include "settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
| /* header file for coding tables for the pitch filter side-info in the entropy coder */ | ||||
| /********************* Pitch Filter Gain Coefficient Tables ************************/ | ||||
|   | ||||
| @@ -11,17 +11,20 @@ | ||||
| /* | ||||
|  * pitch_gain_tables.h | ||||
|  * | ||||
|  * This file contains tables for the pitch filter side-info in the entropy coder. | ||||
|  * This file contains tables for the pitch filter side-info in the entropy | ||||
|  * coder. | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_GAIN_TABLES_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_GAIN_TABLES_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_GAIN_TABLES_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_GAIN_TABLES_H_ | ||||
|  | ||||
| #include "webrtc/typedefs.h" | ||||
| #include <stdint.h> | ||||
|  | ||||
| /* header file for coding tables for the pitch filter side-info in the entropy coder */ | ||||
| /********************* Pitch Filter Gain Coefficient Tables ************************/ | ||||
| /* header file for coding tables for the pitch filter side-info in the entropy | ||||
|  * coder */ | ||||
| /********************* Pitch Filter Gain Coefficient Tables | ||||
|  * ************************/ | ||||
| /* cdf for quantized pitch filter gains */ | ||||
| extern const uint16_t WebRtcIsac_kQPitchGainCdf[255]; | ||||
|  | ||||
| @@ -42,4 +45,4 @@ extern const int16_t WebRtcIsac_kQMeanGain4Q12[144]; | ||||
| /* size of cdf table */ | ||||
| extern const uint16_t WebRtcIsac_kQCdfTableSizeGain[1]; | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_GAIN_TABLES_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_GAIN_TABLES_H_ */ | ||||
|   | ||||
| @@ -8,8 +8,8 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "pitch_lag_tables.h" | ||||
| #include "settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
| /* header file for coding tables for the pitch filter side-info in the entropy coder */ | ||||
| /********************* Pitch Filter Gain Coefficient Tables ************************/ | ||||
|   | ||||
| @@ -11,16 +11,20 @@ | ||||
| /* | ||||
|  * pitch_lag_tables.h | ||||
|  * | ||||
|  * This file contains tables for the pitch filter side-info in the entropy coder. | ||||
|  * This file contains tables for the pitch filter side-info in the entropy | ||||
|  * coder. | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_LAG_TABLES_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_LAG_TABLES_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_LAG_TABLES_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_LAG_TABLES_H_ | ||||
|  | ||||
| #include "webrtc/typedefs.h" | ||||
| /* header file for coding tables for the pitch filter side-info in the entropy coder */ | ||||
| /********************* Pitch Filter Lag Coefficient Tables ************************/ | ||||
| #include <stdint.h> | ||||
|  | ||||
| /* header file for coding tables for the pitch filter side-info in the entropy | ||||
|  * coder */ | ||||
| /********************* Pitch Filter Lag Coefficient Tables | ||||
|  * ************************/ | ||||
|  | ||||
| /* tables for use with small pitch gain */ | ||||
|  | ||||
| @@ -30,7 +34,7 @@ extern const uint16_t WebRtcIsac_kQPitchLagCdf2Lo[20]; | ||||
| extern const uint16_t WebRtcIsac_kQPitchLagCdf3Lo[2]; | ||||
| extern const uint16_t WebRtcIsac_kQPitchLagCdf4Lo[10]; | ||||
|  | ||||
| extern const uint16_t *WebRtcIsac_kQPitchLagCdfPtrLo[4]; | ||||
| extern const uint16_t* WebRtcIsac_kQPitchLagCdfPtrLo[4]; | ||||
|  | ||||
| /* size of first cdf table */ | ||||
| extern const uint16_t WebRtcIsac_kQPitchLagCdfSizeLo[1]; | ||||
| @@ -49,7 +53,6 @@ extern const double WebRtcIsac_kQMeanLag4Lo[9]; | ||||
|  | ||||
| extern const double WebRtcIsac_kQPitchLagStepsizeLo; | ||||
|  | ||||
|  | ||||
| /* tables for use with medium pitch gain */ | ||||
|  | ||||
| /* cdfs for quantized pitch lags */ | ||||
| @@ -58,7 +61,7 @@ extern const uint16_t WebRtcIsac_kQPitchLagCdf2Mid[36]; | ||||
| extern const uint16_t WebRtcIsac_kQPitchLagCdf3Mid[2]; | ||||
| extern const uint16_t WebRtcIsac_kQPitchLagCdf4Mid[20]; | ||||
|  | ||||
| extern const uint16_t *WebRtcIsac_kQPitchLagCdfPtrMid[4]; | ||||
| extern const uint16_t* WebRtcIsac_kQPitchLagCdfPtrMid[4]; | ||||
|  | ||||
| /* size of first cdf table */ | ||||
| extern const uint16_t WebRtcIsac_kQPitchLagCdfSizeMid[1]; | ||||
| @@ -77,7 +80,6 @@ extern const double WebRtcIsac_kQMeanLag4Mid[19]; | ||||
|  | ||||
| extern const double WebRtcIsac_kQPitchLagStepsizeMid; | ||||
|  | ||||
|  | ||||
| /* tables for use with large pitch gain */ | ||||
|  | ||||
| /* cdfs for quantized pitch lags */ | ||||
| @@ -86,7 +88,7 @@ extern const uint16_t WebRtcIsac_kQPitchLagCdf2Hi[68]; | ||||
| extern const uint16_t WebRtcIsac_kQPitchLagCdf3Hi[2]; | ||||
| extern const uint16_t WebRtcIsac_kQPitchLagCdf4Hi[35]; | ||||
|  | ||||
| extern const uint16_t *WebRtcIsac_kQPitchLagCdfPtrHi[4]; | ||||
| extern const uint16_t* WebRtcIsac_kQPitchLagCdfPtrHi[4]; | ||||
|  | ||||
| /* size of first cdf table */ | ||||
| extern const uint16_t WebRtcIsac_kQPitchLagCdfSizeHi[1]; | ||||
| @@ -111,4 +113,4 @@ extern const double WebRtcIsac_kTransform[4][4]; | ||||
| /* transpose transform matrix */ | ||||
| extern const double WebRtcIsac_kTransformTranspose[4][4]; | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_LAG_TABLES_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_LAG_TABLES_H_ */ | ||||
|   | ||||
| @@ -15,191 +15,182 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SETTINGS_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SETTINGS_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SETTINGS_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SETTINGS_H_ | ||||
|  | ||||
| /* sampling frequency (Hz) */ | ||||
| #define FS                                      16000 | ||||
| #define FS 16000 | ||||
|  | ||||
| /* number of samples per frame (either 320 (20ms), 480 (30ms) or 960 (60ms)) */ | ||||
| #define INITIAL_FRAMESAMPLES     960 | ||||
|  | ||||
|  | ||||
| #define MAXFFTSIZE 2048 | ||||
| #define NFACTOR 11 | ||||
|  | ||||
|  | ||||
| #define INITIAL_FRAMESAMPLES 960 | ||||
|  | ||||
| /* do not modify the following; this will have to be modified if we | ||||
|  * have a 20ms framesize option */ | ||||
| /**********************************************************************/ | ||||
| /* miliseconds */ | ||||
| #define FRAMESIZE                               30 | ||||
| #define FRAMESIZE 30 | ||||
| /* number of samples per frame processed in the encoder, 480 */ | ||||
| #define FRAMESAMPLES                            480 /* ((FRAMESIZE*FS)/1000) */ | ||||
| #define FRAMESAMPLES_HALF      240 | ||||
| #define FRAMESAMPLES_QUARTER                    120 | ||||
| #define FRAMESAMPLES 480 /* ((FRAMESIZE*FS)/1000) */ | ||||
| #define FRAMESAMPLES_HALF 240 | ||||
| #define FRAMESAMPLES_QUARTER 120 | ||||
| /**********************************************************************/ | ||||
|  | ||||
|  | ||||
|  | ||||
| /* max number of samples per frame (= 60 ms frame) */ | ||||
| #define MAX_FRAMESAMPLES      960 | ||||
| #define MAX_SWBFRAMESAMPLES                     (MAX_FRAMESAMPLES * 2) | ||||
| #define MAX_FRAMESAMPLES 960 | ||||
| #define MAX_SWBFRAMESAMPLES (MAX_FRAMESAMPLES * 2) | ||||
| /* number of samples per 10ms frame */ | ||||
| #define FRAMESAMPLES_10ms                       ((10*FS)/1000) | ||||
| #define SWBFRAMESAMPLES_10ms                    (FRAMESAMPLES_10ms * 2) | ||||
| #define FRAMESAMPLES_10ms ((10 * FS) / 1000) | ||||
| #define SWBFRAMESAMPLES_10ms (FRAMESAMPLES_10ms * 2) | ||||
| /* number of samples in 30 ms frame */ | ||||
| #define FRAMESAMPLES_30ms            480 | ||||
| #define FRAMESAMPLES_30ms 480 | ||||
| /* number of subframes */ | ||||
| #define SUBFRAMES                               6 | ||||
| #define SUBFRAMES 6 | ||||
| /* length of a subframe */ | ||||
| #define UPDATE                                  80 | ||||
| #define UPDATE 80 | ||||
| /* length of half a subframe (low/high band) */ | ||||
| #define HALF_SUBFRAMELEN                        (UPDATE/2) | ||||
| #define HALF_SUBFRAMELEN (UPDATE / 2) | ||||
| /* samples of look ahead (in a half-band, so actually | ||||
|  * half the samples of look ahead @ FS) */ | ||||
| #define QLOOKAHEAD                              24    /* 3 ms */ | ||||
| #define QLOOKAHEAD 24 /* 3 ms */ | ||||
| /* order of AR model in spectral entropy coder */ | ||||
| #define AR_ORDER                                6 | ||||
| #define AR_ORDER 6 | ||||
| /* order of LP model in spectral entropy coder */ | ||||
| #define LP_ORDER                                0 | ||||
| #define LP_ORDER 0 | ||||
|  | ||||
| /* window length (masking analysis) */ | ||||
| #define WINLEN                                  256 | ||||
| #define WINLEN 256 | ||||
| /* order of low-band pole filter used to approximate masking curve */ | ||||
| #define ORDERLO                                 12 | ||||
| #define ORDERLO 12 | ||||
| /* order of hi-band pole filter used to approximate masking curve */ | ||||
| #define ORDERHI                                 6 | ||||
|  | ||||
| #define UB_LPC_ORDER                            4 | ||||
| #define UB_LPC_VEC_PER_FRAME                    2 | ||||
| #define UB16_LPC_VEC_PER_FRAME                  4 | ||||
| #define UB_ACTIVE_SUBFRAMES                     2 | ||||
| #define UB_MAX_LPC_ORDER                        6 | ||||
| #define UB_INTERPOL_SEGMENTS                    1 | ||||
| #define UB16_INTERPOL_SEGMENTS                  3 | ||||
| #define LB_TOTAL_DELAY_SAMPLES                 48 | ||||
| enum ISACBandwidth {isac8kHz = 8, isac12kHz = 12, isac16kHz = 16}; | ||||
| enum ISACBand {kIsacLowerBand = 0, kIsacUpperBand12 = 1, kIsacUpperBand16 = 2}; | ||||
| enum IsacSamplingRate {kIsacWideband = 16,  kIsacSuperWideband = 32}; | ||||
| #define UB_LPC_GAIN_DIM                 SUBFRAMES | ||||
| #define FB_STATE_SIZE_WORD32                    6 | ||||
| #define ORDERHI 6 | ||||
|  | ||||
| #define UB_LPC_ORDER 4 | ||||
| #define UB_LPC_VEC_PER_FRAME 2 | ||||
| #define UB16_LPC_VEC_PER_FRAME 4 | ||||
| #define UB_ACTIVE_SUBFRAMES 2 | ||||
| #define UB_MAX_LPC_ORDER 6 | ||||
| #define UB_INTERPOL_SEGMENTS 1 | ||||
| #define UB16_INTERPOL_SEGMENTS 3 | ||||
| #define LB_TOTAL_DELAY_SAMPLES 48 | ||||
| enum ISACBandwidth { isac8kHz = 8, isac12kHz = 12, isac16kHz = 16 }; | ||||
| enum ISACBand { | ||||
|   kIsacLowerBand = 0, | ||||
|   kIsacUpperBand12 = 1, | ||||
|   kIsacUpperBand16 = 2 | ||||
| }; | ||||
| enum IsacSamplingRate { kIsacWideband = 16, kIsacSuperWideband = 32 }; | ||||
| #define UB_LPC_GAIN_DIM SUBFRAMES | ||||
| #define FB_STATE_SIZE_WORD32 6 | ||||
|  | ||||
| /* order for post_filter_bank */ | ||||
| #define POSTQORDER                              3 | ||||
| #define POSTQORDER 3 | ||||
| /* order for pre-filterbank */ | ||||
| #define QORDER                                  3 | ||||
| #define QORDER 3 | ||||
| /* another order */ | ||||
| #define QORDER_ALL                              (POSTQORDER+QORDER-1) | ||||
| #define QORDER_ALL (POSTQORDER + QORDER - 1) | ||||
| /* for decimator */ | ||||
| #define ALLPASSSECTIONS                         2 | ||||
|  | ||||
| #define ALLPASSSECTIONS 2 | ||||
|  | ||||
| /* array size for byte stream in number of bytes. */ | ||||
| /* The old maximum size still needed for the decoding */ | ||||
| #define STREAM_SIZE_MAX     600 | ||||
| #define STREAM_SIZE_MAX_30  200 /* 200 bytes=53.4 kbps @ 30 ms.framelength */ | ||||
| #define STREAM_SIZE_MAX_60  400 /* 400 bytes=53.4 kbps @ 60 ms.framelength */ | ||||
| #define STREAM_SIZE_MAX 600 | ||||
| #define STREAM_SIZE_MAX_30 200 /* 200 bytes=53.4 kbps @ 30 ms.framelength */ | ||||
| #define STREAM_SIZE_MAX_60 400 /* 400 bytes=53.4 kbps @ 60 ms.framelength */ | ||||
|  | ||||
| /* storage size for bit counts */ | ||||
| #define BIT_COUNTER_SIZE                        30 | ||||
| #define BIT_COUNTER_SIZE 30 | ||||
| /* maximum order of any AR model or filter */ | ||||
| #define MAX_AR_MODEL_ORDER                      12//50 | ||||
|  | ||||
| #define MAX_AR_MODEL_ORDER 12  // 50 | ||||
|  | ||||
| /* For pitch analysis */ | ||||
| #define PITCH_FRAME_LEN                         (FRAMESAMPLES_HALF) /* 30 ms  */ | ||||
| #define PITCH_MAX_LAG                           140     /* 57 Hz  */ | ||||
| #define PITCH_MIN_LAG                           20              /* 400 Hz */ | ||||
| #define PITCH_MAX_GAIN                          0.45 | ||||
| #define PITCH_MAX_GAIN_06                       0.27  /* PITCH_MAX_GAIN*0.6 */ | ||||
| #define PITCH_MAX_GAIN_Q12      1843 | ||||
| #define PITCH_LAG_SPAN2                     (PITCH_MAX_LAG/2-PITCH_MIN_LAG/2+5) | ||||
| #define PITCH_CORR_LEN2                         60     /* 15 ms  */ | ||||
| #define PITCH_CORR_STEP2                        (PITCH_FRAME_LEN/4) | ||||
| #define PITCH_BW        11     /* half the band width of correlation surface */ | ||||
| #define PITCH_SUBFRAMES                         4 | ||||
| #define PITCH_GRAN_PER_SUBFRAME                 5 | ||||
| #define PITCH_SUBFRAME_LEN        (PITCH_FRAME_LEN/PITCH_SUBFRAMES) | ||||
| #define PITCH_UPDATE              (PITCH_SUBFRAME_LEN/PITCH_GRAN_PER_SUBFRAME) | ||||
| #define PITCH_FRAME_LEN (FRAMESAMPLES_HALF) /* 30 ms  */ | ||||
| #define PITCH_MAX_LAG 140                   /* 57 Hz  */ | ||||
| #define PITCH_MIN_LAG 20                    /* 400 Hz */ | ||||
| #define PITCH_MAX_GAIN 0.45 | ||||
| #define PITCH_MAX_GAIN_06 0.27 /* PITCH_MAX_GAIN*0.6 */ | ||||
| #define PITCH_MAX_GAIN_Q12 1843 | ||||
| #define PITCH_LAG_SPAN2 (PITCH_MAX_LAG / 2 - PITCH_MIN_LAG / 2 + 5) | ||||
| #define PITCH_CORR_LEN2 60 /* 15 ms  */ | ||||
| #define PITCH_CORR_STEP2 (PITCH_FRAME_LEN / 4) | ||||
| #define PITCH_BW 11 /* half the band width of correlation surface */ | ||||
| #define PITCH_SUBFRAMES 4 | ||||
| #define PITCH_GRAN_PER_SUBFRAME 5 | ||||
| #define PITCH_SUBFRAME_LEN (PITCH_FRAME_LEN / PITCH_SUBFRAMES) | ||||
| #define PITCH_UPDATE (PITCH_SUBFRAME_LEN / PITCH_GRAN_PER_SUBFRAME) | ||||
| /* maximum number of peaks to be examined in correlation surface */ | ||||
| #define PITCH_MAX_NUM_PEAKS                  10 | ||||
| #define PITCH_PEAK_DECAY               0.85 | ||||
| #define PITCH_MAX_NUM_PEAKS 10 | ||||
| #define PITCH_PEAK_DECAY 0.85 | ||||
| /* For weighting filter */ | ||||
| #define PITCH_WLPCORDER                   6 | ||||
| #define PITCH_WLPCWINLEN               PITCH_FRAME_LEN | ||||
| #define PITCH_WLPCASYM                   0.3         /* asymmetry parameter */ | ||||
| #define PITCH_WLPCBUFLEN               PITCH_WLPCWINLEN | ||||
| #define PITCH_WLPCORDER 6 | ||||
| #define PITCH_WLPCWINLEN PITCH_FRAME_LEN | ||||
| #define PITCH_WLPCASYM 0.3 /* asymmetry parameter */ | ||||
| #define PITCH_WLPCBUFLEN PITCH_WLPCWINLEN | ||||
| /* For pitch filter */ | ||||
| /* Extra 50 for fraction and LP filters */ | ||||
| #define PITCH_BUFFSIZE                   (PITCH_MAX_LAG + 50) | ||||
| #define PITCH_INTBUFFSIZE               (PITCH_FRAME_LEN+PITCH_BUFFSIZE) | ||||
| #define PITCH_BUFFSIZE (PITCH_MAX_LAG + 50) | ||||
| #define PITCH_INTBUFFSIZE (PITCH_FRAME_LEN + PITCH_BUFFSIZE) | ||||
| /* Max rel. step for interpolation */ | ||||
| #define PITCH_UPSTEP                1.5 | ||||
| #define PITCH_UPSTEP 1.5 | ||||
| /* Max rel. step for interpolation */ | ||||
| #define PITCH_DOWNSTEP                   0.67 | ||||
| #define PITCH_FRACS                             8 | ||||
| #define PITCH_FRACORDER                         9 | ||||
| #define PITCH_DAMPORDER                         5 | ||||
| #define PITCH_FILTDELAY                         1.5f | ||||
| #define PITCH_DOWNSTEP 0.67 | ||||
| #define PITCH_FRACS 8 | ||||
| #define PITCH_FRACORDER 9 | ||||
| #define PITCH_DAMPORDER 5 | ||||
| #define PITCH_FILTDELAY 1.5f | ||||
| /* stepsize for quantization of the pitch Gain */ | ||||
| #define PITCH_GAIN_STEPSIZE                     0.125 | ||||
|  | ||||
|  | ||||
| #define PITCH_GAIN_STEPSIZE 0.125 | ||||
|  | ||||
| /* Order of high pass filter */ | ||||
| #define HPORDER                                 2 | ||||
| #define HPORDER 2 | ||||
|  | ||||
| /* some mathematical constants */ | ||||
| /* log2(exp) */ | ||||
| #define LOG2EXP                                 1.44269504088896 | ||||
| #define PI                                      3.14159265358979 | ||||
| #define LOG2EXP 1.44269504088896 | ||||
| #define PI 3.14159265358979 | ||||
|  | ||||
| /* Maximum number of iterations allowed to limit payload size */ | ||||
| #define MAX_PAYLOAD_LIMIT_ITERATION             5 | ||||
| #define MAX_PAYLOAD_LIMIT_ITERATION 5 | ||||
|  | ||||
| /* Redundant Coding */ | ||||
| #define RCU_BOTTLENECK_BPS                      16000 | ||||
| #define RCU_TRANSCODING_SCALE                   0.40f | ||||
| #define RCU_TRANSCODING_SCALE_INVERSE           2.5f | ||||
| #define RCU_BOTTLENECK_BPS 16000 | ||||
| #define RCU_TRANSCODING_SCALE 0.40f | ||||
| #define RCU_TRANSCODING_SCALE_INVERSE 2.5f | ||||
|  | ||||
| #define RCU_TRANSCODING_SCALE_UB                0.50f | ||||
| #define RCU_TRANSCODING_SCALE_UB_INVERSE        2.0f | ||||
| #define RCU_TRANSCODING_SCALE_UB 0.50f | ||||
| #define RCU_TRANSCODING_SCALE_UB_INVERSE 2.0f | ||||
|  | ||||
| /* Define Error codes */ | ||||
| /* 6000 General */ | ||||
| #define ISAC_MEMORY_ALLOCATION_FAILED    6010 | ||||
| #define ISAC_MODE_MISMATCH       6020 | ||||
| #define ISAC_DISALLOWED_BOTTLENECK     6030 | ||||
| #define ISAC_DISALLOWED_FRAME_LENGTH    6040 | ||||
| #define ISAC_UNSUPPORTED_SAMPLING_FREQUENCY         6050 | ||||
| #define ISAC_MEMORY_ALLOCATION_FAILED 6010 | ||||
| #define ISAC_MODE_MISMATCH 6020 | ||||
| #define ISAC_DISALLOWED_BOTTLENECK 6030 | ||||
| #define ISAC_DISALLOWED_FRAME_LENGTH 6040 | ||||
| #define ISAC_UNSUPPORTED_SAMPLING_FREQUENCY 6050 | ||||
|  | ||||
| /* 6200 Bandwidth estimator */ | ||||
| #define ISAC_RANGE_ERROR_BW_ESTIMATOR    6240 | ||||
| #define ISAC_RANGE_ERROR_BW_ESTIMATOR 6240 | ||||
| /* 6400 Encoder */ | ||||
| #define ISAC_ENCODER_NOT_INITIATED     6410 | ||||
| #define ISAC_DISALLOWED_CODING_MODE     6420 | ||||
| #define ISAC_DISALLOWED_FRAME_MODE_ENCODER   6430 | ||||
| #define ISAC_DISALLOWED_BITSTREAM_LENGTH            6440 | ||||
| #define ISAC_PAYLOAD_LARGER_THAN_LIMIT              6450 | ||||
| #define ISAC_DISALLOWED_ENCODER_BANDWIDTH           6460 | ||||
| #define ISAC_ENCODER_NOT_INITIATED 6410 | ||||
| #define ISAC_DISALLOWED_CODING_MODE 6420 | ||||
| #define ISAC_DISALLOWED_FRAME_MODE_ENCODER 6430 | ||||
| #define ISAC_DISALLOWED_BITSTREAM_LENGTH 6440 | ||||
| #define ISAC_PAYLOAD_LARGER_THAN_LIMIT 6450 | ||||
| #define ISAC_DISALLOWED_ENCODER_BANDWIDTH 6460 | ||||
| /* 6600 Decoder */ | ||||
| #define ISAC_DECODER_NOT_INITIATED     6610 | ||||
| #define ISAC_EMPTY_PACKET       6620 | ||||
| #define ISAC_DISALLOWED_FRAME_MODE_DECODER   6630 | ||||
| #define ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH  6640 | ||||
| #define ISAC_RANGE_ERROR_DECODE_BANDWIDTH   6650 | ||||
| #define ISAC_RANGE_ERROR_DECODE_PITCH_GAIN   6660 | ||||
| #define ISAC_RANGE_ERROR_DECODE_PITCH_LAG   6670 | ||||
| #define ISAC_RANGE_ERROR_DECODE_LPC     6680 | ||||
| #define ISAC_RANGE_ERROR_DECODE_SPECTRUM   6690 | ||||
| #define ISAC_LENGTH_MISMATCH      6730 | ||||
| #define ISAC_RANGE_ERROR_DECODE_BANDWITH            6740 | ||||
| #define ISAC_DISALLOWED_BANDWIDTH_MODE_DECODER      6750 | ||||
| #define ISAC_DISALLOWED_LPC_MODEL                   6760 | ||||
| #define ISAC_DECODER_NOT_INITIATED 6610 | ||||
| #define ISAC_EMPTY_PACKET 6620 | ||||
| #define ISAC_DISALLOWED_FRAME_MODE_DECODER 6630 | ||||
| #define ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH 6640 | ||||
| #define ISAC_RANGE_ERROR_DECODE_BANDWIDTH 6650 | ||||
| #define ISAC_RANGE_ERROR_DECODE_PITCH_GAIN 6660 | ||||
| #define ISAC_RANGE_ERROR_DECODE_PITCH_LAG 6670 | ||||
| #define ISAC_RANGE_ERROR_DECODE_LPC 6680 | ||||
| #define ISAC_RANGE_ERROR_DECODE_SPECTRUM 6690 | ||||
| #define ISAC_LENGTH_MISMATCH 6730 | ||||
| #define ISAC_RANGE_ERROR_DECODE_BANDWITH 6740 | ||||
| #define ISAC_DISALLOWED_BANDWIDTH_MODE_DECODER 6750 | ||||
| #define ISAC_DISALLOWED_LPC_MODEL 6760 | ||||
| /* 6800 Call setup formats */ | ||||
| #define ISAC_INCOMPATIBLE_FORMATS     6810 | ||||
| #define ISAC_INCOMPATIBLE_FORMATS 6810 | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SETTINGS_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SETTINGS_H_ */ | ||||
|   | ||||
| @@ -8,8 +8,8 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "spectrum_ar_model_tables.h" | ||||
| #include "settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
|  | ||||
| /********************* AR Coefficient Tables ************************/ | ||||
| /* cdf for quantized reflection coefficient 1 */ | ||||
|   | ||||
| @@ -11,15 +11,15 @@ | ||||
| /* | ||||
|  * spectrum_ar_model_tables.h | ||||
|  * | ||||
|  * This file contains definitions of tables with AR coefficients,  | ||||
|  * This file contains definitions of tables with AR coefficients, | ||||
|  * Gain coefficients and cosine tables. | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SPECTRUM_AR_MODEL_TABLES_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SPECTRUM_AR_MODEL_TABLES_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SPECTRUM_AR_MODEL_TABLES_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SPECTRUM_AR_MODEL_TABLES_H_ | ||||
|  | ||||
| #include "structs.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/structs.h" | ||||
|  | ||||
| #define NUM_AR_RC_QUANT_BAUNDARY 12 | ||||
|  | ||||
| @@ -45,15 +45,15 @@ extern const uint16_t WebRtcIsac_kQArRc6Cdf[NUM_AR_RC_QUANT_BAUNDARY]; | ||||
| /* quantization boundary levels for reflection coefficients */ | ||||
| extern const int16_t WebRtcIsac_kQArBoundaryLevels[NUM_AR_RC_QUANT_BAUNDARY]; | ||||
|  | ||||
| /* initial indices for AR reflection coefficient quantizer and cdf table search */ | ||||
| /* initial indices for AR reflection coefficient quantizer and cdf table search | ||||
|  */ | ||||
| extern const uint16_t WebRtcIsac_kQArRcInitIndex[AR_ORDER]; | ||||
|  | ||||
| /* pointers to AR cdf tables */ | ||||
| extern const uint16_t *WebRtcIsac_kQArRcCdfPtr[AR_ORDER]; | ||||
| extern const uint16_t* WebRtcIsac_kQArRcCdfPtr[AR_ORDER]; | ||||
|  | ||||
| /* pointers to AR representation levels tables */ | ||||
| extern const int16_t *WebRtcIsac_kQArRcLevelsPtr[AR_ORDER]; | ||||
|  | ||||
| extern const int16_t* WebRtcIsac_kQArRcLevelsPtr[AR_ORDER]; | ||||
|  | ||||
| /******************** GAIN Coefficient Tables ***********************/ | ||||
| /* cdf for Gain coefficient */ | ||||
| @@ -66,7 +66,7 @@ extern const int32_t WebRtcIsac_kQGain2Levels[18]; | ||||
| extern const int32_t WebRtcIsac_kQGain2BoundaryLevels[19]; | ||||
|  | ||||
| /* pointer to Gain cdf table */ | ||||
| extern const uint16_t *WebRtcIsac_kQGainCdf_ptr[1]; | ||||
| extern const uint16_t* WebRtcIsac_kQGainCdf_ptr[1]; | ||||
|  | ||||
| /* Gain initial index for gain quantizer and cdf table search */ | ||||
| extern const uint16_t WebRtcIsac_kQGainInitIndex[1]; | ||||
| @@ -75,4 +75,5 @@ extern const uint16_t WebRtcIsac_kQGainInitIndex[1]; | ||||
| /* Cosine table */ | ||||
| extern const int16_t WebRtcIsac_kCos[6][60]; | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SPECTRUM_AR_MODEL_TABLES_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SPECTRUM_AR_MODEL_TABLES_H_ \ | ||||
|         */ | ||||
|   | ||||
| @@ -15,187 +15,174 @@ | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_STRUCTS_H_ | ||||
| #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_STRUCTS_H_ | ||||
| #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_STRUCTS_H_ | ||||
| #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_STRUCTS_H_ | ||||
|  | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/bandwidth_info.h" | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/include/isac.h" | ||||
| #include "webrtc/modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "webrtc/typedefs.h" | ||||
| #include "modules/audio_coding/codecs/isac/bandwidth_info.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/third_party/fft/fft.h" | ||||
|  | ||||
| typedef struct Bitstreamstruct { | ||||
|  | ||||
|   uint8_t   stream[STREAM_SIZE_MAX]; | ||||
|   uint32_t  W_upper; | ||||
|   uint32_t  streamval; | ||||
|   uint32_t  stream_index; | ||||
|   uint8_t stream[STREAM_SIZE_MAX]; | ||||
|   uint32_t W_upper; | ||||
|   uint32_t streamval; | ||||
|   uint32_t stream_index; | ||||
|  | ||||
| } Bitstr; | ||||
|  | ||||
| typedef struct { | ||||
|   double DataBufferLo[WINLEN]; | ||||
|   double DataBufferHi[WINLEN]; | ||||
|  | ||||
|   double    DataBufferLo[WINLEN]; | ||||
|   double    DataBufferHi[WINLEN]; | ||||
|   double CorrBufLo[ORDERLO + 1]; | ||||
|   double CorrBufHi[ORDERHI + 1]; | ||||
|  | ||||
|   double    CorrBufLo[ORDERLO+1]; | ||||
|   double    CorrBufHi[ORDERHI+1]; | ||||
|   float PreStateLoF[ORDERLO + 1]; | ||||
|   float PreStateLoG[ORDERLO + 1]; | ||||
|   float PreStateHiF[ORDERHI + 1]; | ||||
|   float PreStateHiG[ORDERHI + 1]; | ||||
|   float PostStateLoF[ORDERLO + 1]; | ||||
|   float PostStateLoG[ORDERLO + 1]; | ||||
|   float PostStateHiF[ORDERHI + 1]; | ||||
|   float PostStateHiG[ORDERHI + 1]; | ||||
|  | ||||
|   float    PreStateLoF[ORDERLO+1]; | ||||
|   float    PreStateLoG[ORDERLO+1]; | ||||
|   float    PreStateHiF[ORDERHI+1]; | ||||
|   float    PreStateHiG[ORDERHI+1]; | ||||
|   float    PostStateLoF[ORDERLO+1]; | ||||
|   float    PostStateLoG[ORDERLO+1]; | ||||
|   float    PostStateHiF[ORDERHI+1]; | ||||
|   float    PostStateHiG[ORDERHI+1]; | ||||
|  | ||||
|   double    OldEnergy; | ||||
|   double OldEnergy; | ||||
|  | ||||
| } MaskFiltstr; | ||||
|  | ||||
|  | ||||
| typedef struct { | ||||
|   // state vectors for each of the two analysis filters | ||||
|   double INSTAT1[2 * (QORDER - 1)]; | ||||
|   double INSTAT2[2 * (QORDER - 1)]; | ||||
|   double INSTATLA1[2 * (QORDER - 1)]; | ||||
|   double INSTATLA2[2 * (QORDER - 1)]; | ||||
|   double INLABUF1[QLOOKAHEAD]; | ||||
|   double INLABUF2[QLOOKAHEAD]; | ||||
|  | ||||
|   //state vectors for each of the two analysis filters | ||||
|   double    INSTAT1[2*(QORDER-1)]; | ||||
|   double    INSTAT2[2*(QORDER-1)]; | ||||
|   double    INSTATLA1[2*(QORDER-1)]; | ||||
|   double    INSTATLA2[2*(QORDER-1)]; | ||||
|   double    INLABUF1[QLOOKAHEAD]; | ||||
|   double    INLABUF2[QLOOKAHEAD]; | ||||
|  | ||||
|   float    INSTAT1_float[2*(QORDER-1)]; | ||||
|   float    INSTAT2_float[2*(QORDER-1)]; | ||||
|   float    INSTATLA1_float[2*(QORDER-1)]; | ||||
|   float    INSTATLA2_float[2*(QORDER-1)]; | ||||
|   float    INLABUF1_float[QLOOKAHEAD]; | ||||
|   float    INLABUF2_float[QLOOKAHEAD]; | ||||
|   float INSTAT1_float[2 * (QORDER - 1)]; | ||||
|   float INSTAT2_float[2 * (QORDER - 1)]; | ||||
|   float INSTATLA1_float[2 * (QORDER - 1)]; | ||||
|   float INSTATLA2_float[2 * (QORDER - 1)]; | ||||
|   float INLABUF1_float[QLOOKAHEAD]; | ||||
|   float INLABUF2_float[QLOOKAHEAD]; | ||||
|  | ||||
|   /* High pass filter */ | ||||
|   double    HPstates[HPORDER]; | ||||
|   float    HPstates_float[HPORDER]; | ||||
|   double HPstates[HPORDER]; | ||||
|   float HPstates_float[HPORDER]; | ||||
|  | ||||
| } PreFiltBankstr; | ||||
|  | ||||
|  | ||||
| typedef struct { | ||||
|  | ||||
|   //state vectors for each of the two analysis filters | ||||
|   double    STATE_0_LOWER[2*POSTQORDER]; | ||||
|   double    STATE_0_UPPER[2*POSTQORDER]; | ||||
|   // state vectors for each of the two analysis filters | ||||
|   double STATE_0_LOWER[2 * POSTQORDER]; | ||||
|   double STATE_0_UPPER[2 * POSTQORDER]; | ||||
|  | ||||
|   /* High pass filter */ | ||||
|   double    HPstates1[HPORDER]; | ||||
|   double    HPstates2[HPORDER]; | ||||
|   double HPstates1[HPORDER]; | ||||
|   double HPstates2[HPORDER]; | ||||
|  | ||||
|   float    STATE_0_LOWER_float[2*POSTQORDER]; | ||||
|   float    STATE_0_UPPER_float[2*POSTQORDER]; | ||||
|   float STATE_0_LOWER_float[2 * POSTQORDER]; | ||||
|   float STATE_0_UPPER_float[2 * POSTQORDER]; | ||||
|  | ||||
|   float    HPstates1_float[HPORDER]; | ||||
|   float    HPstates2_float[HPORDER]; | ||||
|   float HPstates1_float[HPORDER]; | ||||
|   float HPstates2_float[HPORDER]; | ||||
|  | ||||
| } PostFiltBankstr; | ||||
|  | ||||
| typedef struct { | ||||
|   // data buffer for pitch filter | ||||
|   double ubuf[PITCH_BUFFSIZE]; | ||||
|  | ||||
|   //data buffer for pitch filter | ||||
|   double    ubuf[PITCH_BUFFSIZE]; | ||||
|   // low pass state vector | ||||
|   double ystate[PITCH_DAMPORDER]; | ||||
|  | ||||
|   //low pass state vector | ||||
|   double    ystate[PITCH_DAMPORDER]; | ||||
|  | ||||
|   //old lag and gain | ||||
|   double    oldlagp[1]; | ||||
|   double    oldgainp[1]; | ||||
|   // old lag and gain | ||||
|   double oldlagp[1]; | ||||
|   double oldgainp[1]; | ||||
|  | ||||
| } PitchFiltstr; | ||||
|  | ||||
| typedef struct { | ||||
|   // data buffer | ||||
|   double buffer[PITCH_WLPCBUFLEN]; | ||||
|  | ||||
|   //data buffer | ||||
|   double    buffer[PITCH_WLPCBUFLEN]; | ||||
|   // state vectors | ||||
|   double istate[PITCH_WLPCORDER]; | ||||
|   double weostate[PITCH_WLPCORDER]; | ||||
|   double whostate[PITCH_WLPCORDER]; | ||||
|  | ||||
|   //state vectors | ||||
|   double    istate[PITCH_WLPCORDER]; | ||||
|   double    weostate[PITCH_WLPCORDER]; | ||||
|   double    whostate[PITCH_WLPCORDER]; | ||||
|  | ||||
|   //LPC window   -> should be a global array because constant | ||||
|   double    window[PITCH_WLPCWINLEN]; | ||||
|   // LPC window   -> should be a global array because constant | ||||
|   double window[PITCH_WLPCWINLEN]; | ||||
|  | ||||
| } WeightFiltstr; | ||||
|  | ||||
| typedef struct { | ||||
|   // for inital estimator | ||||
|   double dec_buffer[PITCH_CORR_LEN2 + PITCH_CORR_STEP2 + PITCH_MAX_LAG / 2 - | ||||
|                     PITCH_FRAME_LEN / 2 + 2]; | ||||
|   double decimator_state[2 * ALLPASSSECTIONS + 1]; | ||||
|   double hp_state[2]; | ||||
|  | ||||
|   //for inital estimator | ||||
|   double         dec_buffer[PITCH_CORR_LEN2 + PITCH_CORR_STEP2 + | ||||
|                             PITCH_MAX_LAG/2 - PITCH_FRAME_LEN/2+2]; | ||||
|   double        decimator_state[2*ALLPASSSECTIONS+1]; | ||||
|   double        hp_state[2]; | ||||
|   double whitened_buf[QLOOKAHEAD]; | ||||
|  | ||||
|   double        whitened_buf[QLOOKAHEAD]; | ||||
|   double inbuf[QLOOKAHEAD]; | ||||
|  | ||||
|   double        inbuf[QLOOKAHEAD]; | ||||
|  | ||||
|   PitchFiltstr  PFstr_wght; | ||||
|   PitchFiltstr  PFstr; | ||||
|   PitchFiltstr PFstr_wght; | ||||
|   PitchFiltstr PFstr; | ||||
|   WeightFiltstr Wghtstr; | ||||
|  | ||||
| } PitchAnalysisStruct; | ||||
|  | ||||
|  | ||||
|  | ||||
| /* Have instance of struct together with other iSAC structs */ | ||||
| typedef struct { | ||||
|  | ||||
|   /* Previous frame length (in ms)                                    */ | ||||
|   int32_t    prev_frame_length; | ||||
|   int32_t prev_frame_length; | ||||
|  | ||||
|   /* Previous RTP timestamp from received | ||||
|      packet (in samples relative beginning)                           */ | ||||
|   int32_t    prev_rec_rtp_number; | ||||
|   int32_t prev_rec_rtp_number; | ||||
|  | ||||
|   /* Send timestamp for previous packet (in ms using timeGetTime())   */ | ||||
|   uint32_t    prev_rec_send_ts; | ||||
|   uint32_t prev_rec_send_ts; | ||||
|  | ||||
|   /* Arrival time for previous packet (in ms using timeGetTime())     */ | ||||
|   uint32_t    prev_rec_arr_ts; | ||||
|   uint32_t prev_rec_arr_ts; | ||||
|  | ||||
|   /* rate of previous packet, derived from RTP timestamps (in bits/s) */ | ||||
|   float   prev_rec_rtp_rate; | ||||
|   float prev_rec_rtp_rate; | ||||
|  | ||||
|   /* Time sinse the last update of the BN estimate (in ms)            */ | ||||
|   uint32_t    last_update_ts; | ||||
|   uint32_t last_update_ts; | ||||
|  | ||||
|   /* Time sinse the last reduction (in ms)                            */ | ||||
|   uint32_t    last_reduction_ts; | ||||
|   uint32_t last_reduction_ts; | ||||
|  | ||||
|   /* How many times the estimate was update in the beginning          */ | ||||
|   int32_t    count_tot_updates_rec; | ||||
|   int32_t count_tot_updates_rec; | ||||
|  | ||||
|   /* The estimated bottle neck rate from there to here (in bits/s)    */ | ||||
|   int32_t  rec_bw; | ||||
|   float   rec_bw_inv; | ||||
|   float   rec_bw_avg; | ||||
|   float   rec_bw_avg_Q; | ||||
|   int32_t rec_bw; | ||||
|   float rec_bw_inv; | ||||
|   float rec_bw_avg; | ||||
|   float rec_bw_avg_Q; | ||||
|  | ||||
|   /* The estimated mean absolute jitter value, | ||||
|      as seen on this side (in ms)                                     */ | ||||
|   float   rec_jitter; | ||||
|   float   rec_jitter_short_term; | ||||
|   float   rec_jitter_short_term_abs; | ||||
|   float   rec_max_delay; | ||||
|   float   rec_max_delay_avg_Q; | ||||
|   float rec_jitter; | ||||
|   float rec_jitter_short_term; | ||||
|   float rec_jitter_short_term_abs; | ||||
|   float rec_max_delay; | ||||
|   float rec_max_delay_avg_Q; | ||||
|  | ||||
|   /* (assumed) bitrate for headers (bps)                              */ | ||||
|   float   rec_header_rate; | ||||
|   float rec_header_rate; | ||||
|  | ||||
|   /* The estimated bottle neck rate from here to there (in bits/s)    */ | ||||
|   float    send_bw_avg; | ||||
|   float send_bw_avg; | ||||
|  | ||||
|   /* The estimated mean absolute jitter value, as seen on | ||||
|      the other siee (in ms)                                           */ | ||||
|   float   send_max_delay_avg; | ||||
|   float send_max_delay_avg; | ||||
|  | ||||
|   // number of packets received since last update | ||||
|   int num_pkts_rec; | ||||
| @@ -218,72 +205,54 @@ typedef struct { | ||||
|  | ||||
|   int change_to_WB; | ||||
|  | ||||
|   uint32_t                 senderTimestamp; | ||||
|   uint32_t                 receiverTimestamp; | ||||
|   //enum IsacSamplingRate incomingStreamSampFreq; | ||||
|   uint16_t                 numConsecLatePkts; | ||||
|   float                        consecLatency; | ||||
|   int16_t                  inWaitLatePkts; | ||||
|   uint32_t senderTimestamp; | ||||
|   uint32_t receiverTimestamp; | ||||
|   // enum IsacSamplingRate incomingStreamSampFreq; | ||||
|   uint16_t numConsecLatePkts; | ||||
|   float consecLatency; | ||||
|   int16_t inWaitLatePkts; | ||||
|  | ||||
|   IsacBandwidthInfo external_bw_info; | ||||
| } BwEstimatorstr; | ||||
|  | ||||
|  | ||||
| typedef struct { | ||||
|  | ||||
|   /* boolean, flags if previous packet exceeded B.N. */ | ||||
|   int    PrevExceed; | ||||
|   int PrevExceed; | ||||
|   /* ms */ | ||||
|   int    ExceedAgo; | ||||
|   int ExceedAgo; | ||||
|   /* packets left to send in current burst */ | ||||
|   int    BurstCounter; | ||||
|   int BurstCounter; | ||||
|   /* packets */ | ||||
|   int    InitCounter; | ||||
|   int InitCounter; | ||||
|   /* ms remaining in buffer when next packet will be sent */ | ||||
|   double StillBuffered; | ||||
|  | ||||
| } RateModel; | ||||
|  | ||||
|  | ||||
| typedef struct { | ||||
|  | ||||
|   unsigned int SpaceAlloced; | ||||
|   unsigned int MaxPermAlloced; | ||||
|   double Tmp0[MAXFFTSIZE]; | ||||
|   double Tmp1[MAXFFTSIZE]; | ||||
|   double Tmp2[MAXFFTSIZE]; | ||||
|   double Tmp3[MAXFFTSIZE]; | ||||
|   int Perm[MAXFFTSIZE]; | ||||
|   int factor [NFACTOR]; | ||||
|  | ||||
| } FFTstr; | ||||
|  | ||||
|  | ||||
| /* The following strutc is used to store data from encoding, to make it | ||||
|    fast and easy to construct a new bitstream with a different Bandwidth | ||||
|    estimate. All values (except framelength and minBytes) is double size to | ||||
|    handle 60 ms of data. | ||||
| */ | ||||
| typedef struct { | ||||
|  | ||||
|   /* Used to keep track of if it is first or second part of 60 msec packet */ | ||||
|   int         startIdx; | ||||
|   int startIdx; | ||||
|  | ||||
|   /* Frame length in samples */ | ||||
|   int16_t framelength; | ||||
|  | ||||
|   /* Pitch Gain */ | ||||
|   int         pitchGain_index[2]; | ||||
|   int pitchGain_index[2]; | ||||
|  | ||||
|   /* Pitch Lag */ | ||||
|   double      meanGain[2]; | ||||
|   int         pitchIndex[PITCH_SUBFRAMES*2]; | ||||
|   double meanGain[2]; | ||||
|   int pitchIndex[PITCH_SUBFRAMES * 2]; | ||||
|  | ||||
|   /* LPC */ | ||||
|   int         LPCindex_s[108*2]; /* KLT_ORDER_SHAPE = 108 */ | ||||
|   int         LPCindex_g[12*2];  /* KLT_ORDER_GAIN = 12 */ | ||||
|   double      LPCcoeffs_lo[(ORDERLO+1)*SUBFRAMES*2]; | ||||
|   double      LPCcoeffs_hi[(ORDERHI+1)*SUBFRAMES*2]; | ||||
|   int LPCindex_s[108 * 2]; /* KLT_ORDER_SHAPE = 108 */ | ||||
|   int LPCindex_g[12 * 2];  /* KLT_ORDER_GAIN = 12 */ | ||||
|   double LPCcoeffs_lo[(ORDERLO + 1) * SUBFRAMES * 2]; | ||||
|   double LPCcoeffs_hi[(ORDERHI + 1) * SUBFRAMES * 2]; | ||||
|  | ||||
|   /* Encode Spec */ | ||||
|   int16_t fre[FRAMESAMPLES]; | ||||
| @@ -291,125 +260,109 @@ typedef struct { | ||||
|   int16_t AvgPitchGain[2]; | ||||
|  | ||||
|   /* Used in adaptive mode only */ | ||||
|   int         minBytes; | ||||
|   int minBytes; | ||||
|  | ||||
| } IsacSaveEncoderData; | ||||
|  | ||||
|  | ||||
| typedef struct { | ||||
|   int indexLPCShape[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; | ||||
|   double lpcGain[SUBFRAMES << 1]; | ||||
|   int lpcGainIndex[SUBFRAMES << 1]; | ||||
|  | ||||
|   int         indexLPCShape[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; | ||||
|   double      lpcGain[SUBFRAMES<<1]; | ||||
|   int         lpcGainIndex[SUBFRAMES<<1]; | ||||
|  | ||||
|   Bitstr      bitStreamObj; | ||||
|   Bitstr bitStreamObj; | ||||
|  | ||||
|   int16_t realFFT[FRAMESAMPLES_HALF]; | ||||
|   int16_t imagFFT[FRAMESAMPLES_HALF]; | ||||
| } ISACUBSaveEncDataStruct; | ||||
|  | ||||
|  | ||||
|  | ||||
| typedef struct { | ||||
|  | ||||
|   Bitstr              bitstr_obj; | ||||
|   MaskFiltstr         maskfiltstr_obj; | ||||
|   PreFiltBankstr      prefiltbankstr_obj; | ||||
|   PitchFiltstr        pitchfiltstr_obj; | ||||
|   Bitstr bitstr_obj; | ||||
|   MaskFiltstr maskfiltstr_obj; | ||||
|   PreFiltBankstr prefiltbankstr_obj; | ||||
|   PitchFiltstr pitchfiltstr_obj; | ||||
|   PitchAnalysisStruct pitchanalysisstr_obj; | ||||
|   FFTstr              fftstr_obj; | ||||
|   FFTstr fftstr_obj; | ||||
|   IsacSaveEncoderData SaveEnc_obj; | ||||
|  | ||||
|   int                 buffer_index; | ||||
|   int16_t         current_framesamples; | ||||
|   int buffer_index; | ||||
|   int16_t current_framesamples; | ||||
|  | ||||
|   float               data_buffer_float[FRAMESAMPLES_30ms]; | ||||
|   float data_buffer_float[FRAMESAMPLES_30ms]; | ||||
|  | ||||
|   int                 frame_nb; | ||||
|   double              bottleneck; | ||||
|   int16_t         new_framelength; | ||||
|   double              s2nr; | ||||
|   int frame_nb; | ||||
|   double bottleneck; | ||||
|   int16_t new_framelength; | ||||
|   double s2nr; | ||||
|  | ||||
|   /* Maximum allowed number of bits for a 30 msec packet */ | ||||
|   int16_t         payloadLimitBytes30; | ||||
|   int16_t payloadLimitBytes30; | ||||
|   /* Maximum allowed number of bits for a 30 msec packet */ | ||||
|   int16_t         payloadLimitBytes60; | ||||
|   int16_t payloadLimitBytes60; | ||||
|   /* Maximum allowed number of bits for both 30 and 60 msec packet */ | ||||
|   int16_t         maxPayloadBytes; | ||||
|   int16_t maxPayloadBytes; | ||||
|   /* Maximum allowed rate in bytes per 30 msec packet */ | ||||
|   int16_t         maxRateInBytes; | ||||
|   int16_t maxRateInBytes; | ||||
|  | ||||
|   /*--- | ||||
|     If set to 1 iSAC will not addapt the frame-size, if used in | ||||
|     If set to 1 iSAC will not adapt the frame-size, if used in | ||||
|     channel-adaptive mode. The initial value will be used for all rates. | ||||
|     ---*/ | ||||
|   int16_t         enforceFrameSize; | ||||
|   int16_t enforceFrameSize; | ||||
|  | ||||
|   /*----- | ||||
|     This records the BWE index the encoder injected into the bit-stream. | ||||
|     It will be used in RCU. The same BWE index of main payload will be in | ||||
|     the redundant payload. We can not retrive it from BWE because it is | ||||
|     the redundant payload. We can not retrieve it from BWE because it is | ||||
|     a recursive procedure (WebRtcIsac_GetDownlinkBwJitIndexImpl) and has to be | ||||
|     called only once per each encode. | ||||
|     -----*/ | ||||
|   int16_t         lastBWIdx; | ||||
|   int16_t lastBWIdx; | ||||
| } ISACLBEncStruct; | ||||
|  | ||||
| typedef struct { | ||||
|  | ||||
|   Bitstr                  bitstr_obj; | ||||
|   MaskFiltstr             maskfiltstr_obj; | ||||
|   PreFiltBankstr          prefiltbankstr_obj; | ||||
|   FFTstr                  fftstr_obj; | ||||
|   Bitstr bitstr_obj; | ||||
|   MaskFiltstr maskfiltstr_obj; | ||||
|   PreFiltBankstr prefiltbankstr_obj; | ||||
|   FFTstr fftstr_obj; | ||||
|   ISACUBSaveEncDataStruct SaveEnc_obj; | ||||
|  | ||||
|   int                     buffer_index; | ||||
|   float                   data_buffer_float[MAX_FRAMESAMPLES + | ||||
|                                             LB_TOTAL_DELAY_SAMPLES]; | ||||
|   double                  bottleneck; | ||||
|   int buffer_index; | ||||
|   float data_buffer_float[MAX_FRAMESAMPLES + LB_TOTAL_DELAY_SAMPLES]; | ||||
|   double bottleneck; | ||||
|   /* Maximum allowed number of bits for a 30 msec packet */ | ||||
|   //int16_t        payloadLimitBytes30; | ||||
|   // int16_t        payloadLimitBytes30; | ||||
|   /* Maximum allowed number of bits for both 30 and 60 msec packet */ | ||||
|   //int16_t        maxPayloadBytes; | ||||
|   int16_t             maxPayloadSizeBytes; | ||||
|   // int16_t        maxPayloadBytes; | ||||
|   int16_t maxPayloadSizeBytes; | ||||
|  | ||||
|   double                  lastLPCVec[UB_LPC_ORDER]; | ||||
|   int16_t             numBytesUsed; | ||||
|   int16_t             lastJitterInfo; | ||||
|   double lastLPCVec[UB_LPC_ORDER]; | ||||
|   int16_t numBytesUsed; | ||||
|   int16_t lastJitterInfo; | ||||
| } ISACUBEncStruct; | ||||
|  | ||||
|  | ||||
|  | ||||
| typedef struct { | ||||
|  | ||||
|   Bitstr          bitstr_obj; | ||||
|   MaskFiltstr     maskfiltstr_obj; | ||||
|   Bitstr bitstr_obj; | ||||
|   MaskFiltstr maskfiltstr_obj; | ||||
|   PostFiltBankstr postfiltbankstr_obj; | ||||
|   PitchFiltstr    pitchfiltstr_obj; | ||||
|   FFTstr          fftstr_obj; | ||||
|   PitchFiltstr pitchfiltstr_obj; | ||||
|   FFTstr fftstr_obj; | ||||
|  | ||||
| } ISACLBDecStruct; | ||||
|  | ||||
| typedef struct { | ||||
|  | ||||
|   Bitstr          bitstr_obj; | ||||
|   MaskFiltstr     maskfiltstr_obj; | ||||
|   Bitstr bitstr_obj; | ||||
|   MaskFiltstr maskfiltstr_obj; | ||||
|   PostFiltBankstr postfiltbankstr_obj; | ||||
|   FFTstr          fftstr_obj; | ||||
|   FFTstr fftstr_obj; | ||||
|  | ||||
| } ISACUBDecStruct; | ||||
|  | ||||
|  | ||||
|  | ||||
| typedef struct { | ||||
|  | ||||
|   ISACLBEncStruct ISACencLB_obj; | ||||
|   ISACLBDecStruct ISACdecLB_obj; | ||||
| } ISACLBStruct; | ||||
|  | ||||
|  | ||||
| typedef struct { | ||||
|  | ||||
|   ISACUBEncStruct ISACencUB_obj; | ||||
|   ISACUBDecStruct ISACdecUB_obj; | ||||
| } ISACUBStruct; | ||||
| @@ -421,14 +374,14 @@ typedef struct { | ||||
| */ | ||||
| typedef struct { | ||||
|   /* 6 lower-band & 6 upper-band */ | ||||
|   double       loFiltGain[SUBFRAMES]; | ||||
|   double       hiFiltGain[SUBFRAMES]; | ||||
|   double loFiltGain[SUBFRAMES]; | ||||
|   double hiFiltGain[SUBFRAMES]; | ||||
|   /* Upper boundary of interval W */ | ||||
|   uint32_t W_upper; | ||||
|   uint32_t streamval; | ||||
|   /* Index to the current position in bytestream */ | ||||
|   uint32_t stream_index; | ||||
|   uint8_t  stream[3]; | ||||
|   uint8_t stream[3]; | ||||
| } transcode_obj; | ||||
|  | ||||
| typedef struct { | ||||
| @@ -444,46 +397,46 @@ typedef struct { | ||||
|  | ||||
| typedef struct { | ||||
|   // lower-band codec instance | ||||
|   ISACLBStruct              instLB; | ||||
|   ISACLBStruct instLB; | ||||
|   // upper-band codec instance | ||||
|   ISACUBStruct              instUB; | ||||
|   ISACUBStruct instUB; | ||||
|  | ||||
|   // Bandwidth Estimator and model for the rate. | ||||
|   BwEstimatorstr            bwestimator_obj; | ||||
|   RateModel                 rate_data_obj; | ||||
|   double                    MaxDelay; | ||||
|   BwEstimatorstr bwestimator_obj; | ||||
|   RateModel rate_data_obj; | ||||
|   double MaxDelay; | ||||
|  | ||||
|   /* 0 = adaptive; 1 = instantaneous */ | ||||
|   int16_t               codingMode; | ||||
|   int16_t codingMode; | ||||
|  | ||||
|   // overall bottleneck of the codec | ||||
|   int32_t               bottleneck; | ||||
|   int32_t bottleneck; | ||||
|  | ||||
|   // QMF Filter state | ||||
|   int32_t               analysisFBState1[FB_STATE_SIZE_WORD32]; | ||||
|   int32_t               analysisFBState2[FB_STATE_SIZE_WORD32]; | ||||
|   int32_t               synthesisFBState1[FB_STATE_SIZE_WORD32]; | ||||
|   int32_t               synthesisFBState2[FB_STATE_SIZE_WORD32]; | ||||
|   int32_t analysisFBState1[FB_STATE_SIZE_WORD32]; | ||||
|   int32_t analysisFBState2[FB_STATE_SIZE_WORD32]; | ||||
|   int32_t synthesisFBState1[FB_STATE_SIZE_WORD32]; | ||||
|   int32_t synthesisFBState2[FB_STATE_SIZE_WORD32]; | ||||
|  | ||||
|   // Error Code | ||||
|   int16_t               errorCode; | ||||
|   int16_t errorCode; | ||||
|  | ||||
|   // bandwidth of the encoded audio 8, 12 or 16 kHz | ||||
|   enum ISACBandwidth        bandwidthKHz; | ||||
|   enum ISACBandwidth bandwidthKHz; | ||||
|   // Sampling rate of audio, encoder and decode,  8 or 16 kHz | ||||
|   enum IsacSamplingRate encoderSamplingRateKHz; | ||||
|   enum IsacSamplingRate decoderSamplingRateKHz; | ||||
|   // Flag to keep track of initializations, lower & upper-band | ||||
|   // encoder and decoder. | ||||
|   int16_t               initFlag; | ||||
|   int16_t initFlag; | ||||
|  | ||||
|   // Flag to to indicate signal bandwidth switch | ||||
|   int16_t               resetFlag_8kHz; | ||||
|   int16_t resetFlag_8kHz; | ||||
|  | ||||
|   // Maximum allowed rate, measured in Bytes per 30 ms. | ||||
|   int16_t               maxRateBytesPer30Ms; | ||||
|   int16_t maxRateBytesPer30Ms; | ||||
|   // Maximum allowed payload-size, measured in Bytes. | ||||
|   int16_t               maxPayloadSizeBytes; | ||||
|   int16_t maxPayloadSizeBytes; | ||||
|   /* The expected sampling rate of the input signal. Valid values are 16000 | ||||
|    * and 32000. This is not the operation sampling rate of the codec. */ | ||||
|   uint16_t in_sample_rate_hz; | ||||
| @@ -492,4 +445,4 @@ typedef struct { | ||||
|   TransformTables transform_tables; | ||||
| } ISACMainStruct; | ||||
|  | ||||
| #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_STRUCTS_H_ */ | ||||
| #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_STRUCTS_H_ */ | ||||
|   | ||||
| @@ -8,12 +8,13 @@ | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include "settings.h" | ||||
| #include "fft.h" | ||||
| #include "codec.h" | ||||
| #include "os_specific_inline.h" | ||||
| #include <math.h> | ||||
|  | ||||
| #include "modules/audio_coding/codecs/isac/main/source/settings.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/codec.h" | ||||
| #include "modules/audio_coding/codecs/isac/main/source/os_specific_inline.h" | ||||
| #include "modules/third_party/fft/fft.h" | ||||
|  | ||||
| void WebRtcIsac_InitTransform(TransformTables* tables) { | ||||
|   int k; | ||||
|   double fact, phase; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user