Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Opus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexander Traud
Opus
Commits
2eaba8ac
Commit
2eaba8ac
authored
17 years ago
by
Jean-Marc Valin
Browse files
Options
Downloads
Patches
Plain Diff
fixed-point: log approximation
parent
98193470
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libcelt/mathops.h
+18
-0
18 additions, 0 deletions
libcelt/mathops.h
libcelt/quant_bands.c
+33
-1
33 additions, 1 deletion
libcelt/quant_bands.c
with
51 additions
and
1 deletion
libcelt/mathops.h
+
18
−
0
View file @
2eaba8ac
...
...
@@ -54,6 +54,11 @@
#include
"entcode.h"
static
inline
celt_int16_t
celt_ilog2
(
celt_word32_t
x
)
{
return
EC_ILOG
(
x
)
-
1
;
}
#define C0 3634
#define C1 21173
#define C2 -12627
...
...
@@ -116,6 +121,19 @@ static inline celt_word16_t celt_cos_norm(celt_word32_t x)
}
}
static
inline
celt_word16_t
celt_log2
(
celt_word32_t
x
)
{
int
i
;
/*-0.41446 0.96093 -0.33981 0.15600 */
const
celt_word16_t
C
[
4
]
=
{
-
6791
,
7872
,
-
1392
,
319
};
if
(
x
==
0
)
return
-
32767
;
i
=
celt_ilog2
(
x
);
celt_word16_t
n
=
VSHR32
(
x
,
i
-
15
)
-
32768
-
16384
;
celt_word16_t
ret
=
ADD16
(
C
[
0
],
MULT16_16_Q14
(
n
,
ADD16
(
C
[
1
],
MULT16_16_Q14
(
n
,
ADD16
(
C
[
2
],
MULT16_16_Q14
(
n
,
(
C
[
3
])))))));
/*printf ("%d %d %d %d\n", x, n, ret, SHL16(i-13,8)+SHR16(ret,14-8));*/
return
SHL16
(
i
-
13
,
8
)
+
SHR16
(
ret
,
14
-
8
);
}
#endif
...
...
This diff is collapsed.
Click to expand it.
libcelt/quant_bands.c
+
33
−
1
View file @
2eaba8ac
...
...
@@ -38,6 +38,7 @@
#include
<math.h>
#include
"os_support.h"
#include
"arch.h"
#include
"mathops.h"
#ifdef FIXED_POINT
const
celt_word16_t
eMeans
[
24
]
=
{
11520
,
-
2048
,
-
3072
,
-
640
,
256
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
...
...
@@ -48,6 +49,37 @@ const float eMeans[24] = {45.f, -8.f, -12.f, -2.5f, 1.f, 0.f, 0.f, 0.f, 0.f, 0.f
/*const int frac[24] = {4, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};*/
const
int
frac
[
24
]
=
{
8
,
6
,
5
,
4
,
3
,
3
,
3
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
};
#ifdef FIXED_POINT
static
inline
celt_ener_t
dB2Amp
(
dB
)
{
celt_ener_t
amp
;
amp
=
pow
(
10
,
.
05
*
dB
)
-
.
3
;
if
(
amp
<
0
)
amp
=
0
;
}
#define DBofTWO 24661
static
inline
celt_word16_t
amp2dB
(
celt_ener_t
amp
)
{
/* equivalent to return 6.0207*log2(.3+amp) */
return
ROUND
(
MULT16_16
(
24661
,
celt_log2
(
ADD32
(
QCONST32
(.
3
f
,
14
),
amp
))),
12
);
/* return DB_SCALING*20*log10(.3+ENER_SCALING_1*amp); */
}
#else
static
inline
celt_ener_t
dB2Amp
(
dB
)
{
celt_ener_t
amp
;
amp
=
pow
(
10
,
.
05
*
dB
)
-
.
3
;
if
(
amp
<
0
)
amp
=
0
;
}
static
inline
celt_word16_t
amp2dB
(
celt_ener_t
amp
)
{
return
20
*
log10
(.
3
+
amp
);
}
#endif
#ifdef FIXED_POINT
#define Q8 256.f
#define Q8_1 (1.f/256.f)
...
...
@@ -75,7 +107,7 @@ static void quant_energy_mono(const CELTMode *m, celt_ener_t *eBands, celt_word1
celt_word16_t
x
;
/* dB */
celt_word16_t
f
;
/* Q8 */
celt_word16_t
mean
=
(
1
-
coef
)
*
eMeans
[
i
];
x
=
DB_SCALING
*
20
*
log10
(.
3
+
ENER_SCALING_1
*
eBands
[
i
]);
x
=
amp2dB
(
eBands
[
i
]);
res
=
DB_SCALING
*
6
;
f
=
QCONST16
(
1
.
f
,
8
)
*
(
x
-
mean
-
coef
*
oldEBands
[
i
]
-
prev
*
1
.
f
)
/
res
;
#ifdef FIXED_POINT
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment