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
e75d3fff
Commit
e75d3fff
authored
5 years ago
by
Blaß, Michael
Browse files
Options
Downloads
Patches
Plain Diff
Basic TimbreTrack
parent
efd23da2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
comsar/__init__.py
+1
-0
1 addition, 0 deletions
comsar/__init__.py
comsar/tracks/timbre.py
+72
-45
72 additions, 45 deletions
comsar/tracks/timbre.py
setup.cfg
+3
-3
3 additions, 3 deletions
setup.cfg
setup.py
+0
-2
0 additions, 2 deletions
setup.py
with
77 additions
and
50 deletions
.gitignore
+
1
−
0
View file @
e75d3fff
...
...
@@ -28,6 +28,7 @@ wheels/
*.ipynb
.ipynb_checkpoints
.mypy_cache
.comsar*/
# PyInstaller
# Usually these files are written by a python script from a template
...
...
This diff is collapsed.
Click to expand it.
comsar/__init__.py
+
1
−
0
View file @
e75d3fff
from
.
track
import
TimbreTrack
This diff is collapsed.
Click to expand it.
comsar/tracks/timbre.py
+
72
−
45
View file @
e75d3fff
from
collections
import
ChainMap
from
dataclasses
import
dataclass
import
pathlib
from
timeit
import
default_timer
as
timer
from
typing
import
Tuple
,
Union
import
numpy
as
np
import
pandas
as
pd
import
soundfile
as
sf
from
apollon.signal.container
import
SpectrumParams
from
apollon.signal.spectral
import
Spectrum
from
apollon.audio
import
AudioFile
from
apollon.segment
import
Segmentation
,
Segments
from
apollon.signal.container
import
STParams
from
apollon.signal.spectral
import
StftSegments
from
apollon.signal
import
features
from
apollon.tools
import
standardize
from
apollon.signal
import
features
,
tools
from
apollon.audio
import
fti16
from
apollon.tools
import
scale
,
standardize
segment_default
=
{
'
n_perseg
'
:
2
**
15
,
'
n_overlap
'
:
2
**
14
,
'
extend
'
:
True
,
'
pad
'
:
True
}
cdim_default
=
{
'
delay
'
:
14
,
'
m_dim
'
:
80
,
'
n_bins
'
:
1000
,
'
scaling_size
'
:
10
}
crr_default
=
{
'
wlen
'
:
2
**
9
,
'
n_delay
'
:
2
**
10
,
'
total
'
:
True
}
@dataclass
class
TTParams
:
segment
:
dict
=
{
'
n_perseg
'
:
2
**
15
,
'
n_overlap
'
:
2
**
14
}
spectrum
:
SpectrumParams
=
SpectrumParams
(
window
=
'
hamming
'
,
lcf
=
50
,
ucf
=
10000
,
ldb
=
30
)
cdim
:
dict
=
{
'
delay
'
:
14
,
'
m_dim
'
:
80
}
crr
:
dict
=
{
'
wlen
'
:
300
,
'
n_delay
'
:
2500
})
segment
:
dict
cdim
:
dict
crr
:
dict
class
TimbreTrack
:
"""
Compute timbre track of an audio file.
"""
def
__init__
(
self
,
path
,
params
:
TTParams
)
->
None
:
def
__init__
(
self
,
path
,
segment_params
:
dict
=
segment_default
,
cdim_params
:
dict
=
cdim_default
,
crr_params
:
dict
=
crr_default
)
->
None
:
"""
Args:
path: Path to audio file.
params: Feature computation parameters.
"""
self
.
params
=
TTParams
(
segment_params
,
cdim_params
,
crr_params
)
self
.
path
=
pathlib
.
Path
(
path
)
self
.
params
=
params
snd
=
AudioFile
(
path
)
cutter
=
Segmentation
(
**
self
.
params
.
segment
)
self
.
segments
=
cutter
.
transform
(
snd
.
data
.
squeeze
())
stp
=
STParams
(
snd
.
fps
)
stft
=
StftSegments
(
stp
)
self
.
spectrogram
=
stft
.
transform
(
self
.
segments
)
self
.
feature_names
=
(
'
Spectral Centroid
'
,
'
Spectral Spread
'
,
'
Spectral Flux
'
,
'
Roughness
'
,
'
Sharpness
'
,
'
SPL
'
,
'
Correlation Dimension
'
,
'
Correlogram
'
)
self
.
funcs
=
[
features
.
spectral_centroid
,
features
.
spectral_spread
,
features
.
spectral_flux
,
features
.
roughness_helmholtz
,
features
.
sharpness
,
features
.
spl
,
features
.
cdim
,
features
.
correlogram
]
self
.
segments
=
Segments
(
self
.
path
,
**
self
.
params
[
'
segment
'
])
self
.
estimators
=
(
'
spectral_centroid
'
,
'
spectral_spread
'
,
'
splc
'
,
'
roughness
'
,
'
sharpness
'
,
'
cdim
'
,
'
correlogram
'
)
assert
len
(
self
.
feature_names
)
==
len
(
self
.
funcs
)
self
.
total_time
=
0.0
self
.
features
=
None
self
.
_features
=
np
.
zeros
((
self
.
segments
.
n_segs
,
self
.
n_features
))
self
.
pace
=
np
.
zeros
(
self
.
n_features
)
self
.
verbose
=
False
snd
.
close
()
def
fit
(
self
)
@property
def
n_features
(
self
)
->
int
:
return
len
(
self
.
feature_names
)
@property
def
features
(
self
)
pd
.
DataFrame
:
if
self
.
_features
is
None
:
return
None
return
pd
.
DataFrame
(
data
=
self
.
_features
,
columns
=
self
.
feature_names
)
@property
def
z_score
(
self
)
->
pd
.
Dataframe
:
if
self
.
_features
is
None
:
return
None
return
standardize
(
self
.
features
)
def
extract
(
self
)
->
None
:
"""
Perform extraction.
"""
_data
=
np
.
zeros
((
self
.
segments
.
n_segs
,
len
(
self
.
estimators
)))
for
seg
in
self
.
segments
:
print
(
seg
.
idx
,
flush
=
True
)
_data
[
seg
.
idx
]
=
self
.
_extract
(
seg
)
args
=
[(
self
.
spectrogram
.
frqs
,
self
.
spectrogram
.
power
),
(
self
.
spectrogram
.
frqs
,
self
.
spectrogram
.
power
),
(
self
.
spectrogram
.
abs
,),
(
self
.
spectrogram
.
d_frq
,
self
.
spectrogram
.
abs
,
15000
),
(
self
.
spectrogram
.
frqs
,
self
.
spectrogram
.
abs
),
(
self
.
segments
.
_segs
,),
(
self
.
segments
.
_segs
,),
(
self
.
segments
.
_segs
,)]
self
.
features
=
pd
.
DataFrame
(
data
=
_data
,
columns
=
self
.
estimators
)
kwargs
=
[{},
{},
{},
{},
{},
{},
self
.
params
.
cdim
,
self
.
params
.
crr
]
for
i
,
(
fun
,
arg
,
kwarg
)
in
enumerate
(
zip
(
self
.
funcs
,
args
,
kwargs
)):
self
.
_worker
(
i
,
fun
,
arg
,
kwarg
)
def
_extract
(
self
,
seg
:
Segment
):
"""
Worker
"""
start
=
timer
()
y
=
spectral
.
Spectrum
(
self
.
se
)
y
.
transform
(
seg
.
data
)
ff
=
{
'
spectral_centroid
'
:
{
'
frqs
'
:
y
.
frqs
,
'
bins
'
:
y
.
power
},
'
spectral_spread
'
:
{
'
frqs
'
:
y
.
frqs
,
'
bins
'
:
y
.
power
},
'
splc
'
:
{
'
frqs
'
:
y
.
frqs
,
'
amps
'
:
y
.
abs
,
'
total
'
:
True
},
'
roughness_helmholtz
'
:
{
'
frqs
'
:
y
.
frqs
,
'
bins
'
:
y
.
power
,
'
frq_max
'
:
100
},
'
sharpness
'
:
{
'
frqs
'
:
y
.
frqs
.
squeeze
(),
'
bins
'
:
y
.
abs
.
squeeze
()},
'
cdim
'
:
{
'
inp
'
:
fti16
(
seg
.
data
).
squeeze
(),
**
self
.
params
[
'
cdim
'
]},
'
correlogram
'
:
{
'
inp
'
:
seg
.
data
.
squeeze
(),
**
self
.
params
[
'
crr
'
],
'
total
'
:
True
}
}
estimates
=
[
getattr
(
features
,
func
)(
**
kwargs
).
item
()
for
func
,
kwargs
in
ff
.
items
()]
stop
=
timer
()
-
start
print
(
f
'
{
seg
.
idx
}
/
{
self
.
segments
.
n_segs
}
'
,
stop
,
flush
=
True
)
return
estimates
def
_worker
(
self
,
idx
,
func
,
args
,
kwargs
)
->
None
:
print
(
self
.
feature_names
[
idx
],
end
=
'
...
'
)
pace
=
timer
()
self
.
_features
[:,
idx
]
=
func
(
*
args
,
**
kwargs
)
pace
=
timer
()
-
pace
self
.
pace
[
idx
]
=
pace
print
(
f
'
{
pace
:
.
4
}
s.
'
)
This diff is collapsed.
Click to expand it.
setup.cfg
+
3
−
3
View file @
e75d3fff
[metadata]
name
=
apollon
version
=
0.
1.2
.1
name
=
comsar
version
=
0.
0
.1
description
=
Computational Music and Sound Archiving
long_description
=
file: README.md
licence
=
BSD-3-Clause
author
=
Michael Blaß
author_email
=
michael.blass@uni-hamburg.de
keywords
=
hmm, som,
apollon,
comsar, music, analysis
keywords
=
hmm, som, comsar, music, analysis
classifiers
=
Programming
Language
::
Python
::
3
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
0
−
2
View file @
e75d3fff
#!/usr/bin/env python3
from
setuptools
import
setup
from
setuptools.config
import
read_configuration
...
...
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