| OLD | NEW |
| 1 /* Copyright (c) 2007-2008 CSIRO | 1 /* Copyright (c) 2007-2008 CSIRO |
| 2 Copyright (c) 2007-2009 Xiph.Org Foundation | 2 Copyright (c) 2007-2009 Xiph.Org Foundation |
| 3 Written by Jean-Marc Valin */ | 3 Written by Jean-Marc Valin */ |
| 4 /* | 4 /* |
| 5 Redistribution and use in source and binary forms, with or without | 5 Redistribution and use in source and binary forms, with or without |
| 6 modification, are permitted provided that the following conditions | 6 modification, are permitted provided that the following conditions |
| 7 are met: | 7 are met: |
| 8 | 8 |
| 9 - Redistributions of source code must retain the above copyright | 9 - Redistributions of source code must retain the above copyright |
| 10 notice, this list of conditions and the following disclaimer. | 10 notice, this list of conditions and the following disclaimer. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 #define FINE_OFFSET 21 | 39 #define FINE_OFFSET 21 |
| 40 #define QTHETA_OFFSET 4 | 40 #define QTHETA_OFFSET 4 |
| 41 #define QTHETA_OFFSET_TWOPHASE 16 | 41 #define QTHETA_OFFSET_TWOPHASE 16 |
| 42 | 42 |
| 43 #include "cwrs.h" | 43 #include "cwrs.h" |
| 44 #include "modes.h" | 44 #include "modes.h" |
| 45 | 45 |
| 46 void compute_pulse_cache(CELTMode *m, int LM); | 46 void compute_pulse_cache(CELTMode *m, int LM); |
| 47 | 47 |
| 48 static inline int get_pulses(int i) | 48 static OPUS_INLINE int get_pulses(int i) |
| 49 { | 49 { |
| 50 return i<8 ? i : (8 + (i&7)) << ((i>>3)-1); | 50 return i<8 ? i : (8 + (i&7)) << ((i>>3)-1); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static inline int bits2pulses(const CELTMode *m, int band, int LM, int bits) | 53 static OPUS_INLINE int bits2pulses(const CELTMode *m, int band, int LM, int bits
) |
| 54 { | 54 { |
| 55 int i; | 55 int i; |
| 56 int lo, hi; | 56 int lo, hi; |
| 57 const unsigned char *cache; | 57 const unsigned char *cache; |
| 58 | 58 |
| 59 LM++; | 59 LM++; |
| 60 cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band]; | 60 cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band]; |
| 61 | 61 |
| 62 lo = 0; | 62 lo = 0; |
| 63 hi = cache[0]; | 63 hi = cache[0]; |
| 64 bits--; | 64 bits--; |
| 65 for (i=0;i<LOG_MAX_PSEUDO;i++) | 65 for (i=0;i<LOG_MAX_PSEUDO;i++) |
| 66 { | 66 { |
| 67 int mid = (lo+hi+1)>>1; | 67 int mid = (lo+hi+1)>>1; |
| 68 /* OPT: Make sure this is implemented with a conditional move */ | 68 /* OPT: Make sure this is implemented with a conditional move */ |
| 69 if ((int)cache[mid] >= bits) | 69 if ((int)cache[mid] >= bits) |
| 70 hi = mid; | 70 hi = mid; |
| 71 else | 71 else |
| 72 lo = mid; | 72 lo = mid; |
| 73 } | 73 } |
| 74 if (bits- (lo == 0 ? -1 : (int)cache[lo]) <= (int)cache[hi]-bits) | 74 if (bits- (lo == 0 ? -1 : (int)cache[lo]) <= (int)cache[hi]-bits) |
| 75 return lo; | 75 return lo; |
| 76 else | 76 else |
| 77 return hi; | 77 return hi; |
| 78 } | 78 } |
| 79 | 79 |
| 80 static inline int pulses2bits(const CELTMode *m, int band, int LM, int pulses) | 80 static OPUS_INLINE int pulses2bits(const CELTMode *m, int band, int LM, int puls
es) |
| 81 { | 81 { |
| 82 const unsigned char *cache; | 82 const unsigned char *cache; |
| 83 | 83 |
| 84 LM++; | 84 LM++; |
| 85 cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band]; | 85 cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band]; |
| 86 return pulses == 0 ? 0 : cache[pulses]+1; | 86 return pulses == 0 ? 0 : cache[pulses]+1; |
| 87 } | 87 } |
| 88 | 88 |
| 89 /** Compute the pulse allocation, i.e. how many pulses will go in each | 89 /** Compute the pulse allocation, i.e. how many pulses will go in each |
| 90 * band. | 90 * band. |
| 91 @param m mode | 91 @param m mode |
| 92 @param offsets Requested increase or decrease in the number of bits for | 92 @param offsets Requested increase or decrease in the number of bits for |
| 93 each band | 93 each band |
| 94 @param total Number of bands | 94 @param total Number of bands |
| 95 @param pulses Number of pulses per band (returned) | 95 @param pulses Number of pulses per band (returned) |
| 96 @return Total number of bits allocated | 96 @return Total number of bits allocated |
| 97 */ | 97 */ |
| 98 int compute_allocation(const CELTMode *m, int start, int end, const int *offsets
, const int *cap, int alloc_trim, int *intensity, int *dual_stero, | 98 int compute_allocation(const CELTMode *m, int start, int end, const int *offsets
, const int *cap, int alloc_trim, int *intensity, int *dual_stero, |
| 99 opus_int32 total, opus_int32 *balance, int *pulses, int *ebits, int *fine_
priority, int C, int LM, ec_ctx *ec, int encode, int prev, int signalBandwidth); | 99 opus_int32 total, opus_int32 *balance, int *pulses, int *ebits, int *fine_
priority, int C, int LM, ec_ctx *ec, int encode, int prev, int signalBandwidth); |
| 100 | 100 |
| 101 #endif | 101 #endif |
| OLD | NEW |