1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/celt/rate.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +/* Copyright (c) 2007-2008 CSIRO 1.5 + Copyright (c) 2007-2009 Xiph.Org Foundation 1.6 + Written by Jean-Marc Valin */ 1.7 +/* 1.8 + Redistribution and use in source and binary forms, with or without 1.9 + modification, are permitted provided that the following conditions 1.10 + are met: 1.11 + 1.12 + - Redistributions of source code must retain the above copyright 1.13 + notice, this list of conditions and the following disclaimer. 1.14 + 1.15 + - Redistributions in binary form must reproduce the above copyright 1.16 + notice, this list of conditions and the following disclaimer in the 1.17 + documentation and/or other materials provided with the distribution. 1.18 + 1.19 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.20 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.21 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.22 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 1.23 + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.24 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.25 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.26 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.27 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.28 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.29 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.30 +*/ 1.31 + 1.32 +#ifndef RATE_H 1.33 +#define RATE_H 1.34 + 1.35 +#define MAX_PSEUDO 40 1.36 +#define LOG_MAX_PSEUDO 6 1.37 + 1.38 +#define MAX_PULSES 128 1.39 + 1.40 +#define MAX_FINE_BITS 8 1.41 + 1.42 +#define FINE_OFFSET 21 1.43 +#define QTHETA_OFFSET 4 1.44 +#define QTHETA_OFFSET_TWOPHASE 16 1.45 + 1.46 +#include "cwrs.h" 1.47 +#include "modes.h" 1.48 + 1.49 +void compute_pulse_cache(CELTMode *m, int LM); 1.50 + 1.51 +static OPUS_INLINE int get_pulses(int i) 1.52 +{ 1.53 + return i<8 ? i : (8 + (i&7)) << ((i>>3)-1); 1.54 +} 1.55 + 1.56 +static OPUS_INLINE int bits2pulses(const CELTMode *m, int band, int LM, int bits) 1.57 +{ 1.58 + int i; 1.59 + int lo, hi; 1.60 + const unsigned char *cache; 1.61 + 1.62 + LM++; 1.63 + cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band]; 1.64 + 1.65 + lo = 0; 1.66 + hi = cache[0]; 1.67 + bits--; 1.68 + for (i=0;i<LOG_MAX_PSEUDO;i++) 1.69 + { 1.70 + int mid = (lo+hi+1)>>1; 1.71 + /* OPT: Make sure this is implemented with a conditional move */ 1.72 + if ((int)cache[mid] >= bits) 1.73 + hi = mid; 1.74 + else 1.75 + lo = mid; 1.76 + } 1.77 + if (bits- (lo == 0 ? -1 : (int)cache[lo]) <= (int)cache[hi]-bits) 1.78 + return lo; 1.79 + else 1.80 + return hi; 1.81 +} 1.82 + 1.83 +static OPUS_INLINE int pulses2bits(const CELTMode *m, int band, int LM, int pulses) 1.84 +{ 1.85 + const unsigned char *cache; 1.86 + 1.87 + LM++; 1.88 + cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band]; 1.89 + return pulses == 0 ? 0 : cache[pulses]+1; 1.90 +} 1.91 + 1.92 +/** Compute the pulse allocation, i.e. how many pulses will go in each 1.93 + * band. 1.94 + @param m mode 1.95 + @param offsets Requested increase or decrease in the number of bits for 1.96 + each band 1.97 + @param total Number of bands 1.98 + @param pulses Number of pulses per band (returned) 1.99 + @return Total number of bits allocated 1.100 +*/ 1.101 +int compute_allocation(const CELTMode *m, int start, int end, const int *offsets, const int *cap, int alloc_trim, int *intensity, int *dual_stero, 1.102 + 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); 1.103 + 1.104 +#endif