Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
566ac171
Commit
566ac171
authored
Jan 14, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pcm/Dsd2Pcm: generate `ctables` at compile time
parent
8aaf39ef
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
15 deletions
+18
-15
Dsd2Pcm.cxx
src/pcm/Dsd2Pcm.cxx
+18
-15
No files found.
src/pcm/Dsd2Pcm.cxx
View file @
566ac171
...
...
@@ -32,6 +32,7 @@ or implied, of Sebastian Gesemann.
#include "Dsd2Pcm.hxx"
#include "util/bit_reverse.h"
#include "util/GenerateArray.hxx"
#include <stdlib.h>
#include <string.h>
...
...
@@ -121,9 +122,6 @@ static constexpr double htaps[HTAPS] = {
3.130441005359396e-08
};
static
float
ctables
[
CTABLES
][
256
];
static
int
precalculated
=
0
;
static
constexpr
float
CalculateCtableValue
(
int
t
,
int
k
,
int
e
)
noexcept
{
...
...
@@ -135,21 +133,27 @@ CalculateCtableValue(int t, int k, int e) noexcept
return
acc
;
}
static
void
precalc
()
noexcept
/* this needs to be a struct because GCC 6 doesn't have constexpr
lambdas (C++17) */
struct
GenerateCtableValue
{
int
t
,
k
;
constexpr
auto
operator
()(
int
e
)
const
noexcept
{
return
CalculateCtableValue
(
t
,
k
,
e
);
}
};
static
constexpr
auto
GenerateCtable
(
int
t
)
noexcept
{
int
t
,
e
,
k
;
if
(
precalculated
)
return
;
for
(
t
=
0
;
t
<
CTABLES
;
++
t
)
{
k
=
HTAPS
-
t
*
8
;
int
k
=
HTAPS
-
t
*
8
;
if
(
k
>
8
)
k
=
8
;
for
(
e
=
0
;
e
<
256
;
++
e
)
{
ctables
[
CTABLES
-
1
-
t
][
e
]
=
CalculateCtableValue
(
t
,
k
,
e
);
}
}
precalculated
=
1
;
return
GenerateArray
<
256
>
(
GenerateCtableValue
{
CTABLES
-
1
-
t
,
k
});
}
static
constexpr
auto
ctables
=
GenerateArray
<
CTABLES
>
(
GenerateCtable
);
struct
dsd2pcm_ctx_s
{
unsigned
char
fifo
[
FIFOSIZE
];
...
...
@@ -160,7 +164,6 @@ dsd2pcm_ctx *
dsd2pcm_init
()
noexcept
{
dsd2pcm_ctx
*
ptr
;
if
(
!
precalculated
)
precalc
();
ptr
=
(
dsd2pcm_ctx
*
)
malloc
(
sizeof
(
dsd2pcm_ctx
));
if
(
ptr
)
dsd2pcm_reset
(
ptr
);
return
ptr
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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