Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
comsar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Blaß, Michael
comsar
Commits
f60586d4
Commit
f60586d4
authored
5 years ago
by
Blaß, Michael
Browse files
Options
Downloads
Patches
Plain Diff
Added alternative TimbreTrack.
parent
e708d1d7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
comsar/tracks/timbre.py
+82
-0
82 additions, 0 deletions
comsar/tracks/timbre.py
with
82 additions
and
0 deletions
comsar/tracks/timbre.py
+
82
−
0
View file @
f60586d4
...
@@ -113,3 +113,85 @@ class TimbreTrack:
...
@@ -113,3 +113,85 @@ class TimbreTrack:
self
.
pace
[
idx
]
=
pace
self
.
pace
[
idx
]
=
pace
print
(
f
'
{
pace
:
.
4
}
s.
'
)
print
(
f
'
{
pace
:
.
4
}
s.
'
)
return
res
return
res
class
TimbreTrackAlt
:
"""
Compute timbre track of an audio file. Do not use correlogram.
"""
def
__init__
(
self
,
stft_params
:
Optional
[
container
.
StftParams
]
=
None
,
corr_dim_params
:
Optional
[
container
.
CorrDimParams
]
=
None
,
)
->
None
:
"""
Args:
"""
self
.
params
=
TimbreTrackParams
(
stft_params
or
STFT_DEFAULT
,
corr_dim_params
or
CORR_DIM_DEFAULT
,
corr_gram_params
or
CORR_GRAM_DEFAULT
)
self
.
cutter
=
Segmentation
(
self
.
params
.
stft
.
n_perseg
,
self
.
params
.
stft
.
n_overlap
,
self
.
params
.
stft
.
extend
,
self
.
params
.
stft
.
pad
)
self
.
stft
=
StftSegments
(
self
.
params
.
stft
.
fps
,
self
.
params
.
stft
.
window
,
self
.
params
.
stft
.
n_fft
)
self
.
feature_names
=
(
'
Spectral Centroid
'
,
'
Spectral Spread
'
,
'
Spectral Flux
'
,
'
Roughness
'
,
'
Sharpness
'
,
'
SPL
'
,
'
Correlation Dimension
'
)
self
.
funcs
=
[
features
.
spectral_centroid
,
features
.
spectral_spread
,
features
.
spectral_flux
,
features
.
roughness_helmholtz
,
features
.
sharpness
,
features
.
spl
,
features
.
cdim
]
self
.
pace
=
np
.
zeros
(
self
.
n_features
)
self
.
verbose
=
False
@property
def
n_features
(
self
)
->
int
:
"""
Number of features on track
"""
return
len
(
self
.
feature_names
)
def
extract
(
self
,
path
)
->
pd
.
DataFrame
:
"""
Perform extraction.
"""
snd
=
AudioFile
(
path
)
if
snd
.
fps
!=
self
.
params
.
stft
.
fps
:
snd
.
close
()
raise
ValueError
(
'
Sample rate of {snd!str} differs from init.
'
)
segs
=
self
.
cutter
.
transform
(
snd
.
data
.
squeeze
())
sxx
=
self
.
stft
.
transform
(
segs
)
args
=
[(
sxx
.
frqs
,
sxx
.
power
),
(
sxx
.
frqs
,
sxx
.
power
),
(
sxx
.
abs
,),
(
sxx
.
d_frq
,
sxx
.
abs
,
15000
),
(
sxx
.
frqs
,
sxx
.
abs
),
(
segs
.
data
,),
(
segs
.
data
,)]
kwargs
=
[{},
{},
{},
{},
{},
{},
self
.
params
.
corr_dim
.
to_dict
()]
out
=
np
.
zeros
((
segs
.
n_segs
,
self
.
n_features
))
for
i
,
(
fun
,
arg
,
kwarg
)
in
enumerate
(
zip
(
self
.
funcs
,
args
,
kwargs
)):
out
[:,
i
]
=
self
.
_worker
(
i
,
fun
,
arg
,
kwarg
)
snd
.
close
()
meta
=
TrackMeta
(
comsar
.
__version__
,
time_stamp
(),
snd
.
file_name
)
out
=
pd
.
DataFrame
(
data
=
out
,
columns
=
self
.
feature_names
)
return
TrackResult
(
meta
,
self
.
params
,
out
)
def
_worker
(
self
,
idx
,
func
,
args
,
kwargs
)
->
np
.
ndarray
:
print
(
self
.
feature_names
[
idx
],
end
=
'
...
'
)
pace
=
timer
()
res
=
func
(
*
args
,
**
kwargs
)
pace
=
timer
()
-
pace
self
.
pace
[
idx
]
=
pace
print
(
f
'
{
pace
:
.
4
}
s.
'
)
return
res
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