Chisato Kenmochi | 9470443 | 2017-01-10 11:56:48 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 - 2016 Sony Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "ldac.h" |
| 18 | |
| 19 | |
| 20 | /******************************************************************************* |
| 21 | Subfunction: Check Saturation |
| 22 | *******************************************************************************/ |
| 23 | __inline static INT32 check_sature_ldac( |
| 24 | INT64 val) |
| 25 | { |
| 26 | |
| 27 | return (INT32)val; |
| 28 | } |
| 29 | |
| 30 | /******************************************************************************* |
| 31 | Shift and Round |
| 32 | *******************************************************************************/ |
| 33 | DECLFUNC INT32 sftrnd_ldac( |
| 34 | INT32 in, |
| 35 | int shift) |
| 36 | { |
| 37 | INT64 out; |
| 38 | |
| 39 | if (shift > 0) { |
| 40 | out = ((INT64)in + ((INT64)1 << (shift-1))) >> shift; |
| 41 | } |
| 42 | else { |
| 43 | out = (INT64)in << (-shift); |
| 44 | } |
| 45 | |
| 46 | return check_sature_ldac(out); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | /******************************************************************************* |
| 51 | Get Bit Length of Value |
| 52 | *******************************************************************************/ |
| 53 | DECLFUNC int get_bit_length_ldac( |
| 54 | INT32 val) |
| 55 | { |
| 56 | int len; |
| 57 | |
| 58 | len = 0; |
| 59 | while (val > 0) { |
| 60 | val >>= 1; |
| 61 | len++; |
| 62 | } |
| 63 | |
| 64 | return len; |
| 65 | } |
| 66 | |
| 67 | /******************************************************************************* |
| 68 | Get Maximum Absolute Value |
| 69 | *******************************************************************************/ |
| 70 | DECLFUNC INT32 get_absmax_ldac( |
| 71 | INT32 *p_x, |
| 72 | int num) |
| 73 | { |
| 74 | int i; |
| 75 | INT32 abmax, val; |
| 76 | |
| 77 | abmax = abs(p_x[0]); |
| 78 | for (i = 1; i < num; i++) { |
| 79 | val = abs(p_x[i]); |
| 80 | if (abmax < val) { |
| 81 | abmax = val; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return abmax; |
| 86 | } |
| 87 | |