/* ** Copyright 2003-2010, VisualOn, Inc. ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ /*********************************************************************** * File: q_pulse.c * * * * Description: Coding and decoding of algebraic codebook * * * ************************************************************************/ #include #include "typedef.h" #include "basic_op.h" #include "q_pulse.h" #define NB_POS 16 /* pos in track, mask for sign bit */ #define UNUSED_VAR __attribute__((unused)) Word32 quant_1p_N1( /* (o) return N+1 bits */ Word16 pos, /* (i) position of the pulse */ Word16 N) /* (i) number of bits for position */ { Word16 mask; Word32 index; mask = (1 << N) - 1; /* mask = ((1<> 1)), 1); index = L_shl(quant_1p_N1(posA[0], n_1), tmp); /* index += quant_3p_3N1(posB[0], posB[1], posB[2], n_1); */ index = vo_L_add(index, quant_3p_3N1(posB[0], posB[1], posB[2], n_1)); break; case 2: tmp = ((n_1 << 1) + 1); /* index = quant_2p_2N1(posA[0], posA[1], n_1) << ((2*n_1)+1); */ index = L_shl(quant_2p_2N1(posA[0], posA[1], n_1), tmp); /* index += quant_2p_2N1(posB[0], posB[1], n_1); */ index = vo_L_add(index, quant_2p_2N1(posB[0], posB[1], n_1)); break; case 3: /* index = quant_3p_3N1(posA[0], posA[1], posA[2], n_1) << N; */ index = L_shl(quant_3p_3N1(posA[0], posA[1], posA[2], n_1), N); index = vo_L_add(index, quant_1p_N1(posB[0], n_1)); /* index += quant_1p_N1(posB[0], n_1); */ break; case 4: index = quant_4p_4N1(posA[0], posA[1], posA[2], posA[3], n_1); break; default: index = 0; fprintf(stderr, "Error in function quant_4p_4N\n"); } tmp = ((N << 2) - 2); /* index += (i & 3) << ((4*N)-2); */ index = vo_L_add(index, L_shl((L_deposit_l(i) & (3L)), tmp)); return (index); } Word32 quant_5p_5N( /* (o) return 5*N bits */ Word16 pos[], /* (i) position of the pulse 1..5 */ Word16 N) /* (i) number of bits for position */ { Word16 nb_pos, n_1, tmp; Word16 posA[5], posB[5]; Word32 i, j, k, index, tmp2; n_1 = (Word16) (N - 1); nb_pos = (1 << n_1); /* nb_pos = (1<> 1)), 1); /* ((5*N)-1)) */ index = L_shl(1L, tmp); /* index = 1 << ((5*N)-1); */ tmp = add1((N << 1), 1); /* index += quant_3p_3N1(posB[0], posB[1], posB[2], n_1) << ((2*N)+1);*/ tmp2 = L_shl(quant_3p_3N1(posB[0], posB[1], posB[2], n_1), tmp); index = vo_L_add(index, tmp2); index = vo_L_add(index, quant_2p_2N1(posB[3], posB[4], N)); /* index += quant_2p_2N1(posB[3], posB[4], N); */ break; case 1: tmp = vo_sub((Word16)((vo_L_mult(5, N) >> 1)), 1); /* index = 1 << ((5*N)-1); */ index = L_shl(1L, tmp); tmp = add1((N << 1), 1); /* index += quant_3p_3N1(posB[0], posB[1], posB[2], n_1) <<((2*N)+1); */ tmp2 = L_shl(quant_3p_3N1(posB[0], posB[1], posB[2], n_1), tmp); index = vo_L_add(index, tmp2); index = vo_L_add(index, quant_2p_2N1(posB[3], posA[0], N)); /* index += quant_2p_2N1(posB[3], posA[0], N); */ break; case 2: tmp = vo_sub((Word16)((vo_L_mult(5, N) >> 1)), 1); /* ((5*N)-1)) */ index = L_shl(1L, tmp); /* index = 1 << ((5*N)-1); */ tmp = add1((N << 1), 1); /* index += quant_3p_3N1(posB[0], posB[1], posB[2], n_1) << ((2*N)+1); */ tmp2 = L_shl(quant_3p_3N1(posB[0], posB[1], posB[2], n_1), tmp); index = vo_L_add(index, tmp2); index = vo_L_add(index, quant_2p_2N1(posA[0], posA[1], N)); /* index += quant_2p_2N1(posA[0], posA[1], N); */ break; case 3: tmp = add1((N << 1), 1); /* index = quant_3p_3N1(posA[0], posA[1], posA[2], n_1) << ((2*N)+1); */ index = L_shl(quant_3p_3N1(posA[0], posA[1], posA[2], n_1), tmp); index = vo_L_add(index, quant_2p_2N1(posB[0], posB[1], N)); /* index += quant_2p_2N1(posB[0], posB[1], N); */ break; case 4: tmp = add1((N << 1), 1); /* index = quant_3p_3N1(posA[0], posA[1], posA[2], n_1) << ((2*N)+1); */ index = L_shl(quant_3p_3N1(posA[0], posA[1], posA[2], n_1), tmp); index = vo_L_add(index, quant_2p_2N1(posA[3], posB[0], N)); /* index += quant_2p_2N1(posA[3], posB[0], N); */ break; case 5: tmp = add1((N << 1), 1); /* index = quant_3p_3N1(posA[0], posA[1], posA[2], n_1) << ((2*N)+1); */ index = L_shl(quant_3p_3N1(posA[0], posA[1], posA[2], n_1), tmp); index = vo_L_add(index, quant_2p_2N1(posA[3], posA[4], N)); /* index += quant_2p_2N1(posA[3], posA[4], N); */ break; default: index = 0; fprintf(stderr, "Error in function quant_5p_5N\n"); } return (index); } Word32 quant_6p_6N_2( /* (o) return (6*N)-2 bits */ Word16 pos[], /* (i) position of the pulse 1..6 */ Word16 N) /* (i) number of bits for position */ { Word16 nb_pos, n_1; Word16 posA[6], posB[6]; Word32 i, j, k, index; /* !! N and n_1 are constants -> it doesn't need to be operated by Basic Operators */ n_1 = (Word16) (N - 1); nb_pos = (1 << n_1); /* nb_pos = (1<