media/libopus/celt/rate.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Copyright (c) 2007-2008 CSIRO
michael@0 2 Copyright (c) 2007-2009 Xiph.Org Foundation
michael@0 3 Written by Jean-Marc Valin */
michael@0 4 /*
michael@0 5 Redistribution and use in source and binary forms, with or without
michael@0 6 modification, are permitted provided that the following conditions
michael@0 7 are met:
michael@0 8
michael@0 9 - Redistributions of source code must retain the above copyright
michael@0 10 notice, this list of conditions and the following disclaimer.
michael@0 11
michael@0 12 - Redistributions in binary form must reproduce the above copyright
michael@0 13 notice, this list of conditions and the following disclaimer in the
michael@0 14 documentation and/or other materials provided with the distribution.
michael@0 15
michael@0 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 17 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
michael@0 20 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 23 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
michael@0 24 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
michael@0 25 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
michael@0 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 27 */
michael@0 28
michael@0 29 #ifndef RATE_H
michael@0 30 #define RATE_H
michael@0 31
michael@0 32 #define MAX_PSEUDO 40
michael@0 33 #define LOG_MAX_PSEUDO 6
michael@0 34
michael@0 35 #define MAX_PULSES 128
michael@0 36
michael@0 37 #define MAX_FINE_BITS 8
michael@0 38
michael@0 39 #define FINE_OFFSET 21
michael@0 40 #define QTHETA_OFFSET 4
michael@0 41 #define QTHETA_OFFSET_TWOPHASE 16
michael@0 42
michael@0 43 #include "cwrs.h"
michael@0 44 #include "modes.h"
michael@0 45
michael@0 46 void compute_pulse_cache(CELTMode *m, int LM);
michael@0 47
michael@0 48 static OPUS_INLINE int get_pulses(int i)
michael@0 49 {
michael@0 50 return i<8 ? i : (8 + (i&7)) << ((i>>3)-1);
michael@0 51 }
michael@0 52
michael@0 53 static OPUS_INLINE int bits2pulses(const CELTMode *m, int band, int LM, int bits)
michael@0 54 {
michael@0 55 int i;
michael@0 56 int lo, hi;
michael@0 57 const unsigned char *cache;
michael@0 58
michael@0 59 LM++;
michael@0 60 cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band];
michael@0 61
michael@0 62 lo = 0;
michael@0 63 hi = cache[0];
michael@0 64 bits--;
michael@0 65 for (i=0;i<LOG_MAX_PSEUDO;i++)
michael@0 66 {
michael@0 67 int mid = (lo+hi+1)>>1;
michael@0 68 /* OPT: Make sure this is implemented with a conditional move */
michael@0 69 if ((int)cache[mid] >= bits)
michael@0 70 hi = mid;
michael@0 71 else
michael@0 72 lo = mid;
michael@0 73 }
michael@0 74 if (bits- (lo == 0 ? -1 : (int)cache[lo]) <= (int)cache[hi]-bits)
michael@0 75 return lo;
michael@0 76 else
michael@0 77 return hi;
michael@0 78 }
michael@0 79
michael@0 80 static OPUS_INLINE int pulses2bits(const CELTMode *m, int band, int LM, int pulses)
michael@0 81 {
michael@0 82 const unsigned char *cache;
michael@0 83
michael@0 84 LM++;
michael@0 85 cache = m->cache.bits + m->cache.index[LM*m->nbEBands+band];
michael@0 86 return pulses == 0 ? 0 : cache[pulses]+1;
michael@0 87 }
michael@0 88
michael@0 89 /** Compute the pulse allocation, i.e. how many pulses will go in each
michael@0 90 * band.
michael@0 91 @param m mode
michael@0 92 @param offsets Requested increase or decrease in the number of bits for
michael@0 93 each band
michael@0 94 @param total Number of bands
michael@0 95 @param pulses Number of pulses per band (returned)
michael@0 96 @return Total number of bits allocated
michael@0 97 */
michael@0 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,
michael@0 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);
michael@0 100
michael@0 101 #endif

mercurial