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
10b958fc
Commit
10b958fc
authored
Jan 30, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resample to 44100 before embedding watermark.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
8247097a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
32 deletions
+32
-32
audiowmark.cc
src/audiowmark.cc
+32
-32
No files found.
src/audiowmark.cc
View file @
10b958fc
...
@@ -501,6 +501,32 @@ mark_pad (const WavData& wav_data, size_t frame, const vector<vector<complex<flo
...
@@ -501,6 +501,32 @@ mark_pad (const WavData& wav_data, size_t frame, const vector<vector<complex<flo
}
}
}
}
WavData
resample
(
const
WavData
&
wav_data
,
int
rate
)
{
if
(
fabs
(
double
(
rate
)
-
wav_data
.
mix_freq
())
<
0.1
)
return
wav_data
;
double
ratio
=
double
(
rate
)
/
wav_data
.
mix_freq
();
const
vector
<
float
>&
in
=
wav_data
.
samples
();
vector
<
float
>
out
(
lrint
(
in
.
size
()
/
wav_data
.
n_channels
()
*
ratio
)
*
wav_data
.
n_channels
());
SRC_DATA
data
;
data
.
data_in
=
&
in
[
0
];
data
.
data_out
=
&
out
[
0
];
data
.
input_frames
=
in
.
size
()
/
wav_data
.
n_channels
();
data
.
output_frames
=
out
.
size
()
/
wav_data
.
n_channels
();
data
.
src_ratio
=
ratio
;
if
(
src_simple
(
&
data
,
SRC_SINC_MEDIUM_QUALITY
,
wav_data
.
n_channels
())
!=
0
)
{
fprintf
(
stderr
,
"audiowmark: resampling error occurred
\n
"
);
exit
(
1
);
}
return
WavData
(
out
,
wav_data
.
n_channels
(),
rate
,
wav_data
.
bit_depth
());
}
int
int
add_watermark
(
const
string
&
infile
,
const
string
&
outfile
,
const
string
&
bits
)
add_watermark
(
const
string
&
infile
,
const
string
&
outfile
,
const
string
&
bits
)
{
{
...
@@ -531,13 +557,15 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
...
@@ -531,13 +557,15 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
printf
(
"loading %s
\n
"
,
infile
.
c_str
());
printf
(
"loading %s
\n
"
,
infile
.
c_str
());
WavData
in
_wav_data
;
WavData
orig
_wav_data
;
if
(
!
in
_wav_data
.
load
(
infile
))
if
(
!
orig
_wav_data
.
load
(
infile
))
{
{
fprintf
(
stderr
,
"audiowmark: error loading %s: %s
\n
"
,
infile
.
c_str
(),
in
_wav_data
.
error_blurb
());
fprintf
(
stderr
,
"audiowmark: error loading %s: %s
\n
"
,
infile
.
c_str
(),
orig
_wav_data
.
error_blurb
());
return
1
;
return
1
;
}
}
WavData
in_wav_data
=
resample
(
orig_wav_data
,
Params
::
mark_sample_rate
);
/*
/*
* to keep the watermarking code simpler, we pad the wave data with zeros
* to keep the watermarking code simpler, we pad the wave data with zeros
* to avoid processing a partly filled frame
* to avoid processing a partly filled frame
...
@@ -1076,35 +1104,7 @@ get_watermark (const string& infile, const string& orig_pattern)
...
@@ -1076,35 +1104,7 @@ get_watermark (const string& infile, const string& orig_pattern)
fprintf
(
stderr
,
"audiowmark: error loading %s: %s
\n
"
,
infile
.
c_str
(),
wav_data
.
error_blurb
());
fprintf
(
stderr
,
"audiowmark: error loading %s: %s
\n
"
,
infile
.
c_str
(),
wav_data
.
error_blurb
());
return
1
;
return
1
;
}
}
if
(
fabs
(
wav_data
.
mix_freq
()
-
Params
::
mark_sample_rate
)
>
0.1
)
return
decode_and_report
(
resample
(
wav_data
,
Params
::
mark_sample_rate
),
orig_pattern
);
{
printf
(
"sample rate: %f -> autoconvert
\n
"
,
wav_data
.
mix_freq
());
double
ratio
=
double
(
Params
::
mark_sample_rate
)
/
wav_data
.
mix_freq
();
const
vector
<
float
>&
in
=
wav_data
.
samples
();
vector
<
float
>
out
(
lrint
(
in
.
size
()
/
wav_data
.
n_channels
()
*
ratio
)
*
wav_data
.
n_channels
());
SRC_DATA
data
;
data
.
data_in
=
&
in
[
0
];
data
.
data_out
=
&
out
[
0
];
data
.
input_frames
=
in
.
size
()
/
wav_data
.
n_channels
();
data
.
output_frames
=
out
.
size
()
/
wav_data
.
n_channels
();
data
.
src_ratio
=
ratio
;
if
(
src_simple
(
&
data
,
SRC_SINC_MEDIUM_QUALITY
,
wav_data
.
n_channels
())
!=
0
)
{
fprintf
(
stderr
,
"audiowmark: resampling error occurred
\n
"
);
return
1
;
}
WavData
resampled_data
(
out
,
wav_data
.
n_channels
(),
Params
::
mark_sample_rate
,
wav_data
.
bit_depth
());
return
decode_and_report
(
resampled_data
,
orig_pattern
);
}
else
{
return
decode_and_report
(
wav_data
,
orig_pattern
);
}
}
}
int
int
...
...
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