annotate src/opus-1.3/celt/rate.h @ 83:ae30d91d2ffe

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