Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mark Harris
Opus
Commits
33ddd797
Commit
33ddd797
authored
Jan 14, 2008
by
Jean-Marc Valin
Browse files
early code for bit-rate management
parent
ec71aee7
Changes
4
Hide whitespace changes
Inline
Side-by-side
libcelt/Makefile.am
View file @
33ddd797
...
...
@@ -10,14 +10,15 @@ lib_LTLIBRARIES = libcelt.la
# Sources for compilation in the library
libcelt_la_SOURCES
=
bands.c celt.c cwrs.c fftwrap.c mdct.c modes.c pitch.c
\
psy.c quant_bands.c quant_pitch.c smallft.c vq.c
psy.c quant_bands.c quant_pitch.c
rate.c
smallft.c vq.c
#noinst_HEADERS =
libcelt_la_LDFLAGS
=
-version-info
@CELT_LT_CURRENT@:@CELT_LT_REVISION@:@CELT_LT_AGE@
noinst_HEADERS
=
arch.h bands.h celt.h cwrs.h fftwrap.h mdct.h modes.h
\
os_support.h pgain_table.h pitch.h psy.h quant_bands.h quant_pitch.h smallft.h vq.h
os_support.h pgain_table.h pitch.h psy.h quant_bands.h quant_pitch.h rate.h
\
smallft.h vq.h
noinst_PROGRAMS
=
testcelt
testcelt_SOURCES
=
testcelt.c
...
...
libcelt/bands.c
View file @
33ddd797
...
...
@@ -227,27 +227,6 @@ void pitch_quant_bands(const CELTMode *m, float *X, float *P, float *gains)
P
[
i
]
=
0
;
}
static
int
compute_allocation
(
const
CELTMode
*
m
,
int
*
pulses
)
{
int
i
,
N
,
BC
,
bits
;
const
int
*
eBands
=
m
->
eBands
;
BC
=
m
->
nbMdctBlocks
*
m
->
nbChannels
;
bits
=
0
;
for
(
i
=
0
;
i
<
m
->
nbEBands
;
i
++
)
{
int
q
;
N
=
BC
*
(
eBands
[
i
+
1
]
-
eBands
[
i
]);
q
=
pulses
[
i
];
if
(
q
<=
0
)
{
bits
+=
ec_ilog64
(
eBands
[
i
]
-
(
eBands
[
i
+
1
]
-
eBands
[
i
]))
+
1
;
q
=
-
q
;
}
if
(
q
!=
0
)
bits
+=
ec_ilog64
(
ncwrs64
(
N
,
pulses
[
i
]))
+
1
;
}
return
bits
;
}
/* Quantisation of the residual */
void
quant_bands
(
const
CELTMode
*
m
,
float
*
X
,
float
*
P
,
float
*
W
,
ec_enc
*
enc
)
...
...
libcelt/rate.c
0 → 100644
View file @
33ddd797
/* (C) 2007 Jean-Marc Valin, CSIRO
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include
<math.h>
#include
"modes.h"
#include
"cwrs.h"
#include
"arch.h"
#include
"entcode.h"
int
log2_frac
(
ec_uint32
val
,
int
frac
)
{
int
i
;
/* EC_ILOG() actually returns log2()+1, go figure */
int
L
=
EC_ILOG
(
val
)
-
1
;
//printf ("in: %d %d ", val, L);
if
(
L
>
14
)
val
>>=
L
-
14
;
else
if
(
L
<
14
)
val
<<=
14
-
L
;
L
<<=
frac
;
//printf ("%d\n", val);
for
(
i
=
0
;
i
<
frac
;
i
++
)
{
val
=
(
val
*
val
)
>>
15
;
//printf ("%d\n", val);
if
(
val
>
16384
)
L
|=
(
1
<<
(
frac
-
i
-
1
));
else
val
<<=
1
;
}
return
L
;
}
int
log2_frac64
(
ec_uint64
val
,
int
frac
)
{
int
i
;
/* EC_ILOG64() actually returns log2()+1, go figure */
int
L
=
EC_ILOG64
(
val
)
-
1
;
//printf ("in: %d %d ", val, L);
if
(
L
>
14
)
val
>>=
L
-
14
;
else
if
(
L
<
14
)
val
<<=
14
-
L
;
L
<<=
frac
;
//printf ("%d\n", val);
for
(
i
=
0
;
i
<
frac
;
i
++
)
{
val
=
(
val
*
val
)
>>
15
;
//printf ("%d\n", val);
if
(
val
>
16384
)
L
|=
(
1
<<
(
frac
-
i
-
1
));
else
val
<<=
1
;
}
return
L
;
}
int
compute_allocation
(
const
CELTMode
*
m
,
int
*
pulses
)
{
int
i
,
N
,
BC
,
bits
;
const
int
*
eBands
=
m
->
eBands
;
BC
=
m
->
nbMdctBlocks
*
m
->
nbChannels
;
bits
=
0
;
for
(
i
=
0
;
i
<
m
->
nbEBands
;
i
++
)
{
int
q
;
N
=
BC
*
(
eBands
[
i
+
1
]
-
eBands
[
i
]);
q
=
pulses
[
i
];
if
(
q
<=
0
)
{
bits
+=
log2_frac64
(
eBands
[
i
]
-
(
eBands
[
i
+
1
]
-
eBands
[
i
]),
8
)
+
(
1
<<
8
);
q
=
-
q
;
}
if
(
q
!=
0
)
bits
+=
log2_frac64
(
ncwrs64
(
N
,
pulses
[
i
]),
8
);
}
return
(
bits
+
255
)
>>
8
;
}
int
bits2pulses
(
int
bits
,
int
N
)
{
int
i
,
b
,
prev
;
/* FIXME: This is terribly inefficient */
prev
=
0
;
i
=
1
;
b
=
log2_frac64
(
ncwrs
(
N
,
i
),
0
);
while
(
b
<
bits
)
{
prev
=
b
;
i
++
;
b
=
log2_frac64
(
ncwrs
(
N
,
i
),
0
);
}
if
(
bits
-
prev
<
b
-
bits
)
i
--
;
return
i
;
}
#if 0
int main()
{
int i;
/*for(i=1;i<2000000000;i+=1738)
{
printf ("%d %d\n", i, frac_log2(i, 10));
}*/
for (i=4;i<=32;i*=2)
{
int j;
for (j=0;j<30;j++)
{
printf ("%d %d %d\n", i, j, bits2pulses(j,i));
}
}
return 0;
}
#endif
libcelt/rate.h
0 → 100644
View file @
33ddd797
//
// C++ Interface: rate
//
// Description:
//
//
// Author: Jean-Marc Valin <Jean-Marc.Valin@USherbrooke.ca>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//
int
compute_allocation
(
const
CELTMode
*
m
,
int
*
pulses
);
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment