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
efd23da2
Commit
efd23da2
authored
5 years ago
by
Blaß, Michael
Browse files
Options
Downloads
Patches
Plain Diff
General update.
parent
e676882a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
comsar/__init__.py
+0
-0
0 additions, 0 deletions
comsar/__init__.py
comsar/tracks.py
+0
-4
0 additions, 4 deletions
comsar/tracks.py
comsar/tracks/timbre.py
+75
-0
75 additions, 0 deletions
comsar/tracks/timbre.py
with
75 additions
and
4 deletions
comsar/__init__.py
0 → 100644
+
0
−
0
View file @
efd23da2
This diff is collapsed.
Click to expand it.
comsar/tracks.py
deleted
100644 → 0
+
0
−
4
View file @
e676882a
import
logging
class
TrackBase
:
def
__init__
(
self
,
source
)
This diff is collapsed.
Click to expand it.
comsar/tracks/timbre.py
+
75
−
0
View file @
efd23da2
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.signal
import
features
,
tools
from
apollon.audio
import
fti16
from
apollon.tools
import
scale
,
standardize
@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
})
class
TimbreTrack
:
"""
Compute timbre track of an audio file.
"""
def
__init__
(
self
,
path
,
params
:
TTParams
)
->
None
:
"""
Args:
path: Path to audio file.
params: Feature computation parameters.
"""
self
.
path
=
pathlib
.
Path
(
path
)
self
.
params
=
params
self
.
segments
=
Segments
(
self
.
path
,
**
self
.
params
[
'
segment
'
])
self
.
estimators
=
(
'
spectral_centroid
'
,
'
spectral_spread
'
,
'
splc
'
,
'
roughness
'
,
'
sharpness
'
,
'
cdim
'
,
'
correlogram
'
)
self
.
total_time
=
0.0
self
.
features
=
None
def
fit
(
self
)
"""
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
)
self
.
features
=
pd
.
DataFrame
(
data
=
_data
,
columns
=
self
.
estimators
)
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
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