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
4f629a36
Commit
4f629a36
authored
Jan 18, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor SyncFinder detection code.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
95631b5f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
24 deletions
+41
-24
audiowmark.cc
src/audiowmark.cc
+41
-24
No files found.
src/audiowmark.cc
View file @
4f629a36
...
...
@@ -3,6 +3,7 @@
#include <string>
#include <random>
#include <complex>
#include <algorithm>
#include "fft.hh"
#include "wavdata.hh"
...
...
@@ -771,53 +772,66 @@ class SyncFinder
{
vector
<
vector
<
int
>>
up
;
vector
<
vector
<
int
>>
down
;
public
:
SyncFinder
()
void
init_up_down
(
const
WavData
&
wav_data
)
{
up
.
clear
();
down
.
clear
();
up
.
resize
(
Params
::
sync_bits
);
down
.
resize
(
Params
::
sync_bits
);
size_t
n_bands
=
Params
::
max_band
-
Params
::
min_band
+
1
;
for
(
int
bit
=
0
;
bit
<
Params
::
sync_bits
;
bit
++
)
{
for
(
int
f
=
0
;
f
<
Params
::
sync_frames_per_bit
;
f
++
)
{
up
.
resize
(
mark_sync_frame_count
());
down
.
resize
(
mark_sync_frame_count
());
vector
<
int
>
frame_up
,
frame_down
;
get_up_down
(
f
+
bit
*
Params
::
sync_frames_per_bit
,
frame_up
,
frame_down
,
Random
::
Stream
::
sync_up_down
);
for
(
auto
u
:
frame_up
)
up
[
bit
].
push_back
(
u
-
Params
::
min_band
+
f
*
n_bands
*
wav_data
.
n_channels
());
for
(
size_t
i
=
0
;
i
<
mark_sync_frame_count
();
i
++
)
get_up_down
(
i
,
up
[
i
],
down
[
i
],
Random
::
Stream
::
sync_up_down
);
for
(
auto
d
:
frame_down
)
down
[
bit
].
push_back
(
d
-
Params
::
min_band
+
f
*
n_bands
*
wav_data
.
n_channels
());
}
sort
(
up
[
bit
].
begin
(),
up
[
bit
].
end
());
sort
(
down
[
bit
].
begin
(),
down
[
bit
].
end
());
}
}
double
sync_decode
(
const
WavData
&
wav_data
,
const
size_t
start_frame
,
const
vector
<
float
>&
fft_out_db
)
{
const
int
frame_count
=
mark_sync_frame_count
();
double
umag
=
0
,
dmag
=
0
;
double
sync_quality
=
0
;
size_t
n_bands
=
Params
::
max_band
-
Params
::
min_band
+
1
;
for
(
int
f
=
0
;
f
<
frame_count
;
f
++
)
for
(
int
bit
=
0
;
bit
<
Params
::
sync_bits
;
bit
++
)
{
assert
(
up
[
f
].
size
()
==
Params
::
bands_per_frame
);
assert
(
down
[
f
].
size
()
==
Params
::
bands_per_frame
);
double
umag
=
0
,
dmag
=
0
;
for
(
int
ch
=
0
;
ch
<
wav_data
.
n_channels
();
ch
++
)
{
const
int
index
=
((
f
+
start_frame
)
*
wav_data
.
n_channels
()
+
ch
)
*
n_bands
-
Params
::
min_band
;
const
int
index
=
((
(
bit
*
Params
::
sync_frames_per_bit
)
+
start_frame
)
*
wav_data
.
n_channels
()
+
ch
)
*
n_bands
;
for
(
size_t
i
=
0
;
i
<
Params
::
bands_per_frame
;
i
++
)
for
(
size_t
i
=
0
;
i
<
up
[
bit
].
size
()
;
i
++
)
{
umag
+=
fft_out_db
[
index
+
up
[
f
][
i
]];
dmag
+=
fft_out_db
[
index
+
down
[
f
][
i
]];
umag
+=
fft_out_db
[
index
+
up
[
bit
][
i
]];
dmag
+=
fft_out_db
[
index
+
down
[
bit
][
i
]];
}
}
if
((
f
%
Params
::
sync_frames_per_bit
)
==
(
Params
::
sync_frames_per_bit
-
1
))
{
const
int
expect_data_bit
=
(
f
/
Params
::
sync_frames_per_bit
)
&
1
;
/* expect 010101 */
const
int
expect_data_bit
=
bit
&
1
;
/* expect 010101 */
const
double
q
=
expect_data_bit
?
(
1
-
umag
/
dmag
)
:
(
umag
/
dmag
-
1
);
sync_quality
+=
q
;
umag
=
0
;
dmag
=
0
;
}
}
sync_quality
/=
Params
::
sync_bits
;
sync_quality
=
normalize_sync_quality
(
sync_quality
);
return
sync_quality
;
}
public
:
struct
Score
{
size_t
index
;
double
quality
;
...
...
@@ -828,6 +842,8 @@ public:
vector
<
Score
>
result_scores
;
vector
<
Score
>
sync_scores
;
init_up_down
(
wav_data
);
// compute multiple time-shifted fft vectors
vector
<
vector
<
float
>>
fft_sync_shift_out
;
for
(
size_t
sync_shift
=
0
;
sync_shift
<
Params
::
frame_size
;
sync_shift
+=
Params
::
sync_search_step
)
...
...
@@ -892,6 +908,7 @@ public:
}
return
result_scores
;
}
private
:
vector
<
float
>
sync_fft
(
const
WavData
&
wav_data
,
size_t
index
,
size_t
count
)
{
...
...
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