Coverage Report

Created: 2025-11-16 07:20

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