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
a8f37a47
Commit
a8f37a47
authored
Nov 13, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve efficiency of stdout output conversion.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
21248bdc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
7 deletions
+25
-7
teststream.cc
src/teststream.cc
+25
-7
No files found.
src/teststream.cc
View file @
a8f37a47
...
...
@@ -235,11 +235,9 @@ StdoutWavOutputStream::open (int n_channels, int sample_rate, int bit_depth, siz
return
true
;
}
bool
StdoutWavOutputStream
::
write_frames
(
const
vector
<
float
>&
sampl
es
)
template
<
int
BIT_DEPTH
>
void
convert_frames
(
const
vector
<
float
>&
samples
,
vector
<
unsigned
char
>&
output_byt
es
)
{
vector
<
unsigned
char
>
output_bytes
(
samples
.
size
()
*
(
m_bit_depth
/
8
));
for
(
size_t
i
=
0
;
i
<
samples
.
size
();
i
++
)
{
const
double
norm
=
0x80000000LL
;
...
...
@@ -248,13 +246,13 @@ StdoutWavOutputStream::write_frames (const vector<float>& samples)
const
int
sample
=
lrint
(
bound
<
double
>
(
min_value
,
samples
[
i
]
*
norm
,
max_value
));
if
(
m_bit_depth
==
16
)
if
(
BIT_DEPTH
==
16
)
{
// write 16-bit little endian value
output_bytes
[
i
*
2
]
=
sample
>>
16
;
output_bytes
[
i
*
2
+
1
]
=
sample
>>
24
;
}
else
if
(
m_bit_depth
==
24
)
else
if
(
BIT_DEPTH
==
24
)
{
// write 24-bit little endian value
output_bytes
[
i
*
3
]
=
sample
>>
8
;
...
...
@@ -262,6 +260,26 @@ StdoutWavOutputStream::write_frames (const vector<float>& samples)
output_bytes
[
i
*
3
+
2
]
=
sample
>>
24
;
}
}
}
bool
StdoutWavOutputStream
::
write_frames
(
const
vector
<
float
>&
samples
)
{
vector
<
unsigned
char
>
output_bytes
(
samples
.
size
()
*
(
m_bit_depth
/
8
));
if
(
m_bit_depth
==
16
)
{
convert_frames
<
16
>
(
samples
,
output_bytes
);
}
else
if
(
m_bit_depth
==
24
)
{
convert_frames
<
24
>
(
samples
,
output_bytes
);
}
else
{
assert
(
false
);
}
fwrite
(
&
output_bytes
[
0
],
1
,
output_bytes
.
size
(),
stdout
);
return
true
;
}
...
...
@@ -290,7 +308,7 @@ main (int argc, char **argv)
fprintf
(
stderr
,
"teststream: open input failed: %s
\n
"
,
in
.
error_blurb
());
return
1
;
}
if
(
!
out
.
open
(
in
.
n_channels
(),
in
.
sample_rate
(),
24
,
in
.
n_frames
()))
if
(
!
out
.
open
(
in
.
n_channels
(),
in
.
sample_rate
(),
16
,
in
.
n_frames
()))
{
fprintf
(
stderr
,
"teststream: open output failed: %s
\n
"
,
out
.
error_blurb
());
return
1
;
...
...
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