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
f371f0c8
Commit
f371f0c8
authored
May 19, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize performance for skipping in resampled input.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
c16d9bdf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
18 deletions
+30
-18
wmadd.cc
src/wmadd.cc
+30
-18
No files found.
src/wmadd.cc
View file @
f371f0c8
...
...
@@ -383,7 +383,7 @@ public:
{
}
virtual
void
write_frames
(
const
vector
<
float
>&
frames
)
=
0
;
virtual
void
write_frames
(
const
vector
<
float
>&
frames
,
bool
skip
=
false
)
=
0
;
virtual
vector
<
float
>
read_frames
(
size_t
frames
)
=
0
;
virtual
size_t
can_read_frames
()
const
=
0
;
};
...
...
@@ -392,13 +392,17 @@ template<class Resampler>
class
BufferedResamplerImpl
:
public
ResamplerImpl
{
const
int
n_channels
=
0
;
const
int
old_rate
=
0
;
const
int
new_rate
=
0
;
bool
first_write
=
true
;
Resampler
m_resampler
;
vector
<
float
>
buffer
;
public
:
BufferedResamplerImpl
(
int
n_channels
)
:
n_channels
(
n_channels
)
BufferedResamplerImpl
(
int
n_channels
,
int
old_rate
,
int
new_rate
)
:
n_channels
(
n_channels
),
old_rate
(
old_rate
),
new_rate
(
new_rate
)
{
}
Resampler
&
...
...
@@ -407,7 +411,7 @@ public:
return
m_resampler
;
}
void
write_frames
(
const
vector
<
float
>&
frames
)
write_frames
(
const
vector
<
float
>&
frames
,
bool
skip
)
{
if
(
first_write
)
{
...
...
@@ -424,6 +428,13 @@ public:
uint
start
=
0
;
do
{
if
(
frames
.
size
()
/
n_channels
-
start
>=
old_rate
&&
skip
)
{
buffer
.
resize
(
buffer
.
size
()
+
new_rate
*
n_channels
);
start
+=
old_rate
;
}
else
{
const
int
out_count
=
Params
::
frame_size
;
float
out
[
out_count
*
n_channels
];
...
...
@@ -440,6 +451,7 @@ public:
start
+=
frames
.
size
()
/
n_channels
-
start
-
m_resampler
.
inp_count
;
}
}
while
(
start
!=
frames
.
size
()
/
n_channels
);
}
vector
<
float
>
...
...
@@ -481,7 +493,7 @@ create_resampler (int n_channels, int old_rate, int new_rate)
*/
const
int
hlen
=
16
;
auto
resampler
=
new
BufferedResamplerImpl
<
Resampler
>
(
n_channels
);
auto
resampler
=
new
BufferedResamplerImpl
<
Resampler
>
(
n_channels
,
old_rate
,
new_rate
);
if
(
resampler
->
resampler
().
setup
(
old_rate
,
new_rate
,
n_channels
,
hlen
)
==
0
)
{
return
resampler
;
...
...
@@ -489,7 +501,7 @@ create_resampler (int n_channels, int old_rate, int new_rate)
else
delete
resampler
;
auto
vresampler
=
new
BufferedResamplerImpl
<
VResampler
>
(
n_channels
);
auto
vresampler
=
new
BufferedResamplerImpl
<
VResampler
>
(
n_channels
,
old_rate
,
new_rate
);
const
double
ratio
=
double
(
new_rate
)
/
old_rate
;
if
(
vresampler
->
resampler
().
setup
(
ratio
,
n_channels
,
hlen
)
==
0
)
{
...
...
@@ -575,7 +587,7 @@ public:
vector
<
float
>
samples
(
zeros
*
n_channels
);
/* resample to the watermark sample rate */
in_resampler
->
write_frames
(
samples
);
in_resampler
->
write_frames
(
samples
,
true
);
size_t
skip_blocks
=
in_resampler
->
can_read_frames
()
/
Params
::
frame_size
;
...
...
@@ -586,7 +598,7 @@ public:
wm_samples
.
resize
(
wm_gen
.
skip
(
r_samples
.
size
()
/
n_channels
)
*
n_channels
);
/* resample back to the original sample rate of the audio file */
out_resampler
->
write_frames
(
wm_samples
);
out_resampler
->
write_frames
(
wm_samples
,
true
);
size_t
to_read
=
out_resampler
->
can_read_frames
();
return
out_resampler
->
read_frames
(
to_read
).
size
()
/
n_channels
;
...
...
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