1470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/*
2470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *
4470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  Use of this source code is governed by a BSD-style license
5470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  that can be found in the LICENSE file in the root of the source
6470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  tree. An additional intellectual property rights grant can be found
7470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  in the file PATENTS.  All contributing project authors may
8470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *  be found in the AUTHORS file in the root of the source tree.
9470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com */
10470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
11470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/*
12470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * entropy_coding.h
13470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *
14470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * This header file contains all of the functions used to arithmetically
15470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * encode the iSAC bistream
16470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *
17470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com */
18470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
19470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_SOURCE_ENTROPY_CODING_H_
20470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_SOURCE_ENTROPY_CODING_H_
21470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
22470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#include "structs.h"
23470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
24470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* decode complex spectrum (return number of bytes in stream) */
25aba07ef6d92bf1ded7ad1af49b54a8e6652dfcbbPeter Kastingint WebRtcIsacfix_DecodeSpec(Bitstr_dec  *streamdata,
26aba07ef6d92bf1ded7ad1af49b54a8e6652dfcbbPeter Kasting                             int16_t *frQ7,
27aba07ef6d92bf1ded7ad1af49b54a8e6652dfcbbPeter Kasting                             int16_t *fiQ7,
28aba07ef6d92bf1ded7ad1af49b54a8e6652dfcbbPeter Kasting                             int16_t AvgPitchGain_Q12);
29470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
30470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* encode complex spectrum */
310946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.orgint WebRtcIsacfix_EncodeSpec(const int16_t *fr,
320946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                             const int16_t *fi,
33470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com                             Bitstr_enc *streamdata,
340946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                             int16_t AvgPitchGain_Q12);
35470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
36470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
37470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* decode & dequantize LPC Coef */
38470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comint WebRtcIsacfix_DecodeLpcCoef(Bitstr_dec  *streamdata,
390946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                                int32_t *LPCCoefQ17,
400946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                                int32_t *gain_lo_hiQ17,
410946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                                int16_t *outmodel);
42470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
430946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.orgint WebRtcIsacfix_DecodeLpc(int32_t *gain_lo_hiQ17,
440946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                            int16_t *LPCCoef_loQ15,
450946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                            int16_t *LPCCoef_hiQ15,
46470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com                            Bitstr_dec  *streamdata,
470946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                            int16_t *outmodel);
48470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
49470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* quantize & code LPC Coef */
500946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.orgint WebRtcIsacfix_EncodeLpc(int32_t *gain_lo_hiQ17,
510946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                            int16_t *LPCCoef_loQ15,
520946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                            int16_t *LPCCoef_hiQ15,
530946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                            int16_t *model,
540946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                            int32_t *sizeQ11,
55470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com                            Bitstr_enc *streamdata,
56eb544460e47140d494dddf1217a698a1dcf4dee0pbos@webrtc.org                            IsacSaveEncoderData* encData,
57470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com                            transcode_obj *transcodeParam);
58470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
590946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.orgint WebRtcIsacfix_EstCodeLpcGain(int32_t *gain_lo_hiQ17,
60470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com                                 Bitstr_enc *streamdata,
61eb544460e47140d494dddf1217a698a1dcf4dee0pbos@webrtc.org                                 IsacSaveEncoderData* encData);
62470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* decode & dequantize RC */
63470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comint WebRtcIsacfix_DecodeRcCoef(Bitstr_dec *streamdata,
640946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                               int16_t *RCQ15);
65470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
66470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* quantize & code RC */
670946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.orgint WebRtcIsacfix_EncodeRcCoef(int16_t *RCQ15,
68470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com                               Bitstr_enc *streamdata);
69470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
70470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* decode & dequantize squared Gain */
71470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comint WebRtcIsacfix_DecodeGain2(Bitstr_dec *streamdata,
720946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                              int32_t *Gain2);
73470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
74470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* quantize & code squared Gain (input is squared gain) */
750946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.orgint WebRtcIsacfix_EncodeGain2(int32_t *gain2,
76470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com                              Bitstr_enc *streamdata);
77470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
780946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.orgint WebRtcIsacfix_EncodePitchGain(int16_t *PitchGains_Q12,
79470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com                                  Bitstr_enc *streamdata,
80eb544460e47140d494dddf1217a698a1dcf4dee0pbos@webrtc.org                                  IsacSaveEncoderData* encData);
81470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
820946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.orgint WebRtcIsacfix_EncodePitchLag(int16_t *PitchLagQ7,
830946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                                 int16_t *PitchGain_Q12,
84470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com                                 Bitstr_enc *streamdata,
85eb544460e47140d494dddf1217a698a1dcf4dee0pbos@webrtc.org                                 IsacSaveEncoderData* encData);
86470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
87470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comint WebRtcIsacfix_DecodePitchGain(Bitstr_dec *streamdata,
880946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                                  int16_t *PitchGain_Q12);
89470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
90470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comint WebRtcIsacfix_DecodePitchLag(Bitstr_dec *streamdata,
910946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                                 int16_t *PitchGain_Q12,
920946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                                 int16_t *PitchLagQ7);
93470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
94470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comint WebRtcIsacfix_DecodeFrameLen(Bitstr_dec *streamdata,
95dce40cf804019a9898b6ab8d8262466b697c56e0Peter Kasting                                 size_t *framelength);
96470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
97470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
980946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.orgint WebRtcIsacfix_EncodeFrameLen(int16_t framelength,
99470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com                                 Bitstr_enc *streamdata);
100470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
101470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comint WebRtcIsacfix_DecodeSendBandwidth(Bitstr_dec *streamdata,
1020946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                                      int16_t *BWno);
103470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
104470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
1050946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.orgint WebRtcIsacfix_EncodeReceiveBandwidth(int16_t *BWno,
106470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com                                         Bitstr_enc *streamdata);
107470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
1080946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.orgvoid WebRtcIsacfix_TranscodeLpcCoef(int32_t *tmpcoeffs_gQ6,
1090946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org                                    int16_t *index_gQQ);
110470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com
11123da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org// Pointer functions for LPC transforms.
11223da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org
11323da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.orgtypedef void (*MatrixProduct1)(const int16_t matrix0[],
11423da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int32_t matrix1[],
11523da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               int32_t matrix_product[],
11623da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int matrix1_index_factor1,
11723da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int matrix0_index_factor1,
11823da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int matrix1_index_init_case,
11923da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int matrix1_index_step,
12023da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int matrix0_index_step,
12123da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int inner_loop_count,
12223da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int mid_loop_count,
12323da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int shift);
12423da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.orgtypedef void (*MatrixProduct2)(const int16_t matrix0[],
12523da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int32_t matrix1[],
12623da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               int32_t matrix_product[],
12723da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int matrix0_index_factor,
12823da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                               const int matrix0_index_step);
12923da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org
13023da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.orgextern MatrixProduct1 WebRtcIsacfix_MatrixProduct1;
13123da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.orgextern MatrixProduct2 WebRtcIsacfix_MatrixProduct2;
13223da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org
13323da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.orgvoid WebRtcIsacfix_MatrixProduct1C(const int16_t matrix0[],
13423da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int32_t matrix1[],
13523da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   int32_t matrix_product[],
13623da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int matrix1_index_factor1,
13723da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int matrix0_index_factor1,
13823da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int matrix1_index_init_case,
13923da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int matrix1_index_step,
14023da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int matrix0_index_step,
14123da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int inner_loop_count,
14223da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int mid_loop_count,
14323da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int shift);
14423da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.orgvoid WebRtcIsacfix_MatrixProduct2C(const int16_t matrix0[],
14523da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int32_t matrix1[],
14623da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   int32_t matrix_product[],
14723da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int matrix0_index_factor,
14823da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                   const int matrix0_index_step);
14923da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org
150cb7f8ce2df7564546936d3041a96ccc86a90f988Andrew MacDonald#if (defined WEBRTC_DETECT_NEON) || (defined WEBRTC_HAS_NEON)
15123da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.orgvoid WebRtcIsacfix_MatrixProduct1Neon(const int16_t matrix0[],
15223da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int32_t matrix1[],
15323da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      int32_t matrix_product[],
15423da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int matrix1_index_factor1,
15523da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int matrix0_index_factor1,
15623da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int matrix1_index_init_case,
15723da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int matrix1_index_step,
15823da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int matrix0_index_step,
15923da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int inner_loop_count,
16023da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int mid_loop_count,
16123da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int shift);
16223da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.orgvoid WebRtcIsacfix_MatrixProduct2Neon(const int16_t matrix0[],
16323da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int32_t matrix1[],
16423da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      int32_t matrix_product[],
16523da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int matrix0_index_factor,
16623da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org                                      const int matrix0_index_step);
16723da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org#endif
16823da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org
169f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org#if defined(MIPS32_LE)
170f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.orgvoid WebRtcIsacfix_MatrixProduct1MIPS(const int16_t matrix0[],
171f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int32_t matrix1[],
172f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      int32_t matrix_product[],
173f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int matrix1_index_factor1,
174f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int matrix0_index_factor1,
175f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int matrix1_index_init_case,
176f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int matrix1_index_step,
177f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int matrix0_index_step,
178f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int inner_loop_count,
179f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int mid_loop_count,
180f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int shift);
181f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org
182f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.orgvoid WebRtcIsacfix_MatrixProduct2MIPS(const int16_t matrix0[],
183f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int32_t matrix1[],
184f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      int32_t matrix_product[],
185f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int matrix0_index_factor,
186f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org                                      const int matrix0_index_step);
187f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org#endif
188f86b2625889b065ccf67e580a8456f0b5e42b261andrew@webrtc.org
18923da8622c04ac843f7912dd33b4ad55f41422119kma@webrtc.org#endif  // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_FIX_SOURCE_ENTROPY_CODING_H_
190