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
366a9656
Commit
366a9656
authored
Jan 10, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Precompute db-magnitudes to make sync search faster.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
417b7806
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
+22
-19
audiowmark.cc
src/audiowmark.cc
+22
-19
No files found.
src/audiowmark.cc
View file @
366a9656
...
@@ -818,7 +818,7 @@ public:
...
@@ -818,7 +818,7 @@ public:
get_up_down
(
i
,
up
[
i
],
down
[
i
]);
get_up_down
(
i
,
up
[
i
],
down
[
i
]);
}
}
double
double
sync_decode
(
const
WavData
&
wav_data
,
const
size_t
start_frame
,
const
vector
<
vector
<
complex
<
float
>>>&
fft_out
,
const
vector
<
vector
<
complex
<
float
>>>&
fft_orig_out
)
sync_decode
(
const
WavData
&
wav_data
,
const
size_t
start_frame
,
const
vector
<
vector
<
float
>>&
fft_out_db
)
{
{
// FIXME: is copypasted
// FIXME: is copypasted
const
int
frame_count
=
mark_sync_frame_count
();
const
int
frame_count
=
mark_sync_frame_count
();
...
@@ -832,21 +832,11 @@ public:
...
@@ -832,21 +832,11 @@ public:
{
{
const
size_t
index
=
(
f
+
start_frame
)
*
wav_data
.
n_channels
()
+
ch
;
const
size_t
index
=
(
f
+
start_frame
)
*
wav_data
.
n_channels
()
+
ch
;
const
double
min_db
=
-
96
;
for
(
auto
u
:
up
[
f
])
for
(
auto
u
:
up
[
f
])
{
umag
+=
fft_out_db
[
index
][
u
];
umag
+=
db_from_factor
(
abs
(
fft_out
[
index
][
u
]),
min_db
);
if
(
index
<
fft_orig_out
.
size
())
umag
-=
db_from_factor
(
abs
(
fft_orig_out
[
index
][
u
]),
min_db
);
}
for
(
auto
d
:
down
[
f
])
for
(
auto
d
:
down
[
f
])
{
dmag
+=
fft_out_db
[
index
][
d
];
dmag
+=
db_from_factor
(
abs
(
fft_out
[
index
][
d
]),
min_db
);
if
(
index
<
fft_orig_out
.
size
())
dmag
-=
db_from_factor
(
abs
(
fft_orig_out
[
index
][
d
]),
min_db
);
}
}
}
if
((
f
%
Params
::
sync_frames_per_bit
)
==
(
Params
::
sync_frames_per_bit
-
1
))
if
((
f
%
Params
::
sync_frames_per_bit
)
==
(
Params
::
sync_frames_per_bit
-
1
))
{
{
...
@@ -875,7 +865,7 @@ public:
...
@@ -875,7 +865,7 @@ public:
vector
<
SyncScore
>
sync_scores
;
vector
<
SyncScore
>
sync_scores
;
// compute multiple time-shifted fft vectors
// compute multiple time-shifted fft vectors
vector
<
vector
<
vector
<
complex
<
float
>
>>>
fft_sync_shift_out
;
vector
<
vector
<
vector
<
float
>>>
fft_sync_shift_out
;
for
(
size_t
sync_shift
=
0
;
sync_shift
<
Params
::
frame_size
;
sync_shift
+=
128
)
for
(
size_t
sync_shift
=
0
;
sync_shift
<
Params
::
frame_size
;
sync_shift
+=
128
)
fft_sync_shift_out
.
push_back
(
sync_fft
(
wav_data
,
sync_shift
,
frame_count
(
wav_data
)
-
1
));
fft_sync_shift_out
.
push_back
(
sync_fft
(
wav_data
,
sync_shift
,
frame_count
(
wav_data
)
-
1
));
...
@@ -886,7 +876,7 @@ public:
...
@@ -886,7 +876,7 @@ public:
const
size_t
sync_index
=
start_frame
*
Params
::
frame_size
+
sync_shift
;
const
size_t
sync_index
=
start_frame
*
Params
::
frame_size
+
sync_shift
;
if
((
start_frame
+
mark_sync_frame_count
())
*
wav_data
.
n_channels
()
<
fft_sync_shift_out
[
sync_shift
/
128
].
size
())
if
((
start_frame
+
mark_sync_frame_count
())
*
wav_data
.
n_channels
()
<
fft_sync_shift_out
[
sync_shift
/
128
].
size
())
{
{
double
quality
=
sync_decode
(
wav_data
,
start_frame
,
fft_sync_shift_out
[
sync_shift
/
128
]
,
/* FIXME: non-blind */
{}
);
double
quality
=
sync_decode
(
wav_data
,
start_frame
,
fft_sync_shift_out
[
sync_shift
/
128
]);
// printf ("%zd %f\n", sync_index, quality);
// printf ("%zd %f\n", sync_index, quality);
sync_scores
.
emplace_back
(
SyncScore
{
sync_index
,
quality
});
sync_scores
.
emplace_back
(
SyncScore
{
sync_index
,
quality
});
}
}
...
@@ -919,10 +909,10 @@ public:
...
@@ -919,10 +909,10 @@ public:
int
step
=
8
;
int
step
=
8
;
for
(
int
fine_index
=
start
;
fine_index
<
end
;
fine_index
+=
step
)
for
(
int
fine_index
=
start
;
fine_index
<
end
;
fine_index
+=
step
)
{
{
vector
<
vector
<
complex
<
float
>
>>
fft_out_range
=
sync_fft
(
wav_data
,
fine_index
,
mark_sync_frame_count
());
vector
<
vector
<
float
>>
fft_out_range
=
sync_fft
(
wav_data
,
fine_index
,
mark_sync_frame_count
());
if
(
fft_out_range
.
size
())
if
(
fft_out_range
.
size
())
{
{
double
q
=
sync_decode
(
wav_data
,
0
,
fft_out_range
,
{}
);
double
q
=
sync_decode
(
wav_data
,
0
,
fft_out_range
);
if
(
q
>
best_quality
)
if
(
q
>
best_quality
)
{
{
...
@@ -936,7 +926,7 @@ public:
...
@@ -936,7 +926,7 @@ public:
}
}
}
}
}
}
vector
<
vector
<
complex
<
float
>
>>
vector
<
vector
<
float
>>
sync_fft
(
const
WavData
&
wav_data
,
size_t
index
,
size_t
count
)
sync_fft
(
const
WavData
&
wav_data
,
size_t
index
,
size_t
count
)
{
{
if
(
wav_data
.
n_values
()
<
(
index
+
count
*
Params
::
frame_size
)
*
wav_data
.
n_channels
())
if
(
wav_data
.
n_values
()
<
(
index
+
count
*
Params
::
frame_size
)
*
wav_data
.
n_channels
())
...
@@ -949,7 +939,20 @@ public:
...
@@ -949,7 +939,20 @@ public:
part_signal
.
push_back
(
wav_data
.
samples
()[(
index
+
i
)
*
wav_data
.
n_channels
()
+
ch
]);
part_signal
.
push_back
(
wav_data
.
samples
()[(
index
+
i
)
*
wav_data
.
n_channels
()
+
ch
]);
}
}
WavData
wav_part
(
part_signal
,
wav_data
.
n_channels
(),
wav_data
.
mix_freq
(),
wav_data
.
bit_depth
());
WavData
wav_part
(
part_signal
,
wav_data
.
n_channels
(),
wav_data
.
mix_freq
(),
wav_data
.
bit_depth
());
return
compute_frame_ffts
(
wav_part
);
/* computing db-magnitude is expensive, so we better do it here */
vector
<
vector
<
float
>>
fft_out_db
;
for
(
auto
spect
:
compute_frame_ffts
(
wav_part
))
{
const
double
min_db
=
-
96
;
vector
<
float
>
db_spect
(
spect
.
size
());
for
(
size_t
i
=
Params
::
min_band
;
i
<=
Params
::
max_band
;
i
++
)
db_spect
[
i
]
=
db_from_factor
(
abs
(
spect
[
i
]),
min_db
);
fft_out_db
.
push_back
(
db_spect
);
}
return
fft_out_db
;
}
}
const
char
*
const
char
*
...
...
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