Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
71ac8994
Commit
71ac8994
authored
May 26, 2024
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize native endian case for RawConverter float->int 16/32 bit.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
880e31b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
16 deletions
+31
-16
rawconverter.cc
src/rawconverter.cc
+31
-16
No files found.
src/rawconverter.cc
View file @
71ac8994
...
...
@@ -116,6 +116,7 @@ RawConverterImpl<BIT_DEPTH, ENDIAN, ENCODING>::to_raw (const vector<float>& samp
#else
constexpr
bool
native_endian
=
ENDIAN
==
RawFormat
::
LITTLE
;
#endif
assert
((
uintptr_t
(
output_bytes
.
data
())
&
3
)
==
0
);
// ensure alignment for optimized 32 bit native endian version
output_bytes
.
resize
(
sample_width
*
samples
.
size
());
...
...
@@ -123,22 +124,36 @@ RawConverterImpl<BIT_DEPTH, ENDIAN, ENCODING>::to_raw (const vector<float>& samp
for
(
size_t
i
=
0
;
i
<
samples
.
size
();
i
++
)
{
const
double
norm
=
0x80000000LL
;
const
double
min_value
=
-
0x80000000LL
;
const
double
max_value
=
0x7FFFFFFF
;
const
int
sample
=
lrint
(
bound
<
double
>
(
min_value
,
samples
[
i
]
*
norm
,
max_value
));
if
(
eshift
[
0
]
>=
0
)
ptr
[
0
]
=
(
sample
>>
eshift
[
0
])
^
sign_flip
;
if
(
eshift
[
1
]
>=
0
)
ptr
[
1
]
=
sample
>>
eshift
[
1
];
if
(
eshift
[
2
]
>=
0
)
ptr
[
2
]
=
sample
>>
eshift
[
2
];
if
(
eshift
[
3
]
>=
0
)
ptr
[
3
]
=
sample
>>
eshift
[
3
];
ptr
+=
sample_width
;
const
float
min_value
=
-
0x80000000LL
;
const
float
max_value
=
0x7FFFFFFF
;
const
float
norm
=
0x80000000LL
;
const
float
snorm
=
samples
[
i
]
*
norm
;
int
sample
;
if
(
snorm
>=
max_value
)
sample
=
0x7FFFFFFF
;
else
if
(
snorm
<=
min_value
)
sample
=
0x80000000
;
else
sample
=
snorm
;
if
(
native_endian
&&
ENCODING
==
RawFormat
::
SIGNED
&&
BIT_DEPTH
==
32
)
((
int32_t
*
)
ptr
)[
i
]
=
sample
;
else
if
(
native_endian
&&
ENCODING
==
RawFormat
::
SIGNED
&&
BIT_DEPTH
==
16
)
((
int16_t
*
)
ptr
)[
i
]
=
sample
>>
16
;
else
{
if
(
eshift
[
0
]
>=
0
)
ptr
[
0
]
=
(
sample
>>
eshift
[
0
])
^
sign_flip
;
if
(
eshift
[
1
]
>=
0
)
ptr
[
1
]
=
sample
>>
eshift
[
1
];
if
(
eshift
[
2
]
>=
0
)
ptr
[
2
]
=
sample
>>
eshift
[
2
];
if
(
eshift
[
3
]
>=
0
)
ptr
[
3
]
=
sample
>>
eshift
[
3
];
ptr
+=
sample_width
;
}
}
}
...
...
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