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
3285734a
Commit
3285734a
authored
May 26, 2024
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize wav-pipe format a bit more.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
71ac8994
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
15 deletions
+26
-15
rawconverter.cc
src/rawconverter.cc
+22
-15
stdoutwavoutputstream.cc
src/stdoutwavoutputstream.cc
+4
-0
No files found.
src/rawconverter.cc
View file @
3285734a
...
...
@@ -104,6 +104,24 @@ make_endian_shift ()
}
}
template
<
int
BITS
>
static
int
float_to_int_clip
(
float
f
)
{
const
int64_t
inorm
=
(
1LL
<<
(
BITS
-
1
));
const
float
min_value
=
-
inorm
;
const
float
max_value
=
inorm
-
1
;
const
float
norm
=
inorm
;
const
float
snorm
=
f
*
norm
;
if
(
snorm
>=
max_value
)
return
inorm
-
1
;
else
if
(
snorm
<=
min_value
)
return
-
inorm
;
else
return
snorm
;
}
template
<
int
BIT_DEPTH
,
RawFormat
::
Endian
ENDIAN
,
RawFormat
::
Encoding
ENCODING
>
void
RawConverterImpl
<
BIT_DEPTH
,
ENDIAN
,
ENCODING
>::
to_raw
(
const
vector
<
float
>&
samples
,
vector
<
unsigned
char
>&
output_bytes
)
...
...
@@ -124,25 +142,14 @@ RawConverterImpl<BIT_DEPTH, ENDIAN, ENCODING>::to_raw (const vector<float>& samp
for
(
size_t
i
=
0
;
i
<
samples
.
size
();
i
++
)
{
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
;
((
int32_t
*
)
ptr
)[
i
]
=
float_to_int_clip
<
32
>
(
samples
[
i
])
;
else
if
(
native_endian
&&
ENCODING
==
RawFormat
::
SIGNED
&&
BIT_DEPTH
==
16
)
((
int16_t
*
)
ptr
)[
i
]
=
sample
>>
16
;
((
int16_t
*
)
ptr
)[
i
]
=
float_to_int_clip
<
16
>
(
samples
[
i
])
;
else
{
int
sample
=
float_to_int_clip
<
32
>
(
samples
[
i
]);
if
(
eshift
[
0
]
>=
0
)
ptr
[
0
]
=
(
sample
>>
eshift
[
0
])
^
sign_flip
;
if
(
eshift
[
1
]
>=
0
)
...
...
src/stdoutwavoutputstream.cc
View file @
3285734a
...
...
@@ -84,6 +84,10 @@ StdoutWavOutputStream::open (int n_channels, int sample_rate, int bit_depth, siz
return
Error
(
"unable to write wav format to standard out without input length information"
);
}
// 32-bit output is a faster (less conversion overhead), so we use it for pipes
if
(
bit_depth
>
16
&&
wav_pipe
)
bit_depth
=
32
;
RawFormat
format
;
format
.
set_bit_depth
(
bit_depth
);
...
...
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