Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autosimilarity_segmentation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MARMORET Axel
autosimilarity_segmentation
Commits
070b5d6b
Commit
070b5d6b
authored
1 year ago
by
MARMORET Axel
Browse files
Options
Downloads
Patches
Plain Diff
Adding the median_hop function
parent
150531d6
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
as_seg/data_manipulation.py
+33
-1
33 additions, 1 deletion
as_seg/data_manipulation.py
with
33 additions
and
1 deletion
as_seg/data_manipulation.py
+
33
−
1
View file @
070b5d6b
...
...
@@ -427,7 +427,39 @@ def align_frontiers_on_bars(frontiers, bars):
else
:
frontiers_on_bars
.
append
(
bars
[
i
][
0
])
return
frontiers_on_bars
def
get_median_hop
(
bars
,
subdivision
=
96
,
sampling_rate
=
44100
):
"""
Returns the median hop length in the song, used for audio reconstruction.
The rationale is that all bars are sampled with
'
subdivision
'
number of frames,
but they can be of different lengths in absolute time.
Hence, the time gap between two consecutive frames (the hop length) can differ between bars.
For reconstruction, we use the median hop length among all bars.
Parameters
----------
bars : list of tuples of float
The bars, as (start time, end time) tuples.
subdivision : integer, optional
The number of subdivision of the bar to be contained in each slice of the tensor.
The default is 96.
sampling_rate : integer, optional
The sampling rate of the signal, in Hz.
The default is 44100.
Returns
-------
integer
The median hop length in these bars.
"""
hops
=
[]
for
bar_idx
in
range
(
1
,
len
(
bars
)):
len_sig
=
bars
[
bar_idx
][
1
]
-
bars
[
bar_idx
][
0
]
hop
=
int
(
len_sig
/
subdivision
*
sampling_rate
)
hops
.
append
(
hop
)
return
int
(
np
.
median
(
hops
))
# Generally used for audio reconstruction
# %% Sonification of the segmentation
def
sonify_frontiers_path
(
audio_file_path
,
frontiers_in_seconds
,
output_path
):
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment