Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
madarrays
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
Container registry
Model registry
Operate
Environments
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
skmad-suite
madarrays
Commits
df5fa127
Commit
df5fa127
authored
7 years ago
by
Ronan Hamon
Browse files
Options
Downloads
Patches
Plain Diff
Add a function to check the fs between two Waveforms
parent
e8570494
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
madarrays/waveform.py
+16
-9
16 additions, 9 deletions
madarrays/waveform.py
with
16 additions
and
9 deletions
madarrays/waveform.py
+
16
−
9
View file @
df5fa127
...
...
@@ -60,6 +60,14 @@ from .mad_array import MadArray
VALID_IO_FS
=
{
1
,
8000
,
16000
,
32000
,
48000
,
11025
,
22050
,
44100
,
88200
}
def
_check_compatibility_fs
(
w1
,
w2
):
"""
Raise an exception if the sampling frequency of the two Waveforms
are different.
"""
if
w1
.
fs
!=
w2
.
fs
:
errmsg
=
'
Waveforms do not have the same fs: {} and {}.
'
raise
ValueError
(
errmsg
.
format
(
w1
.
fs
,
w2
.
fs
))
class
Waveform
(
MadArray
):
"""
Subclass of MadArray to handle mono and stereo audio signals.
...
...
@@ -158,16 +166,14 @@ class Waveform(MadArray):
def
__array_ufunc__
(
self
,
ufunc
,
method
,
*
inputs
,
**
kwargs
):
output
=
super
().
__array_ufunc__
(
ufunc
,
method
,
*
inputs
,
**
kwargs
)
if
isinstance
(
output
,
MadArray
):
if
len
(
inputs
)
==
2
:
if
(
isinstance
(
inputs
[
0
],
Waveform
)
and
isinstance
(
inputs
[
1
],
Waveform
)
and
inputs
[
0
].
fs
!=
inputs
[
1
].
fs
):
errmsg
=
'
Waveforms do not have the same fs: {} and {}
'
raise
ValueError
(
errmsg
.
format
(
inputs
[
0
].
fs
,
inputs
[
1
].
fs
))
isinstance
(
inputs
[
1
],
Waveform
)):
_check_compatibility_fs
(
*
inputs
)
output
=
super
().
__array_ufunc__
(
ufunc
,
method
,
*
inputs
,
**
kwargs
)
if
isinstance
(
output
,
MadArray
):
output
=
output
.
view
(
Waveform
)
output
.
fs
=
inputs
[
0
].
fs
if
isinstance
(
inputs
[
0
],
Waveform
)
\
else
inputs
[
1
].
fs
...
...
@@ -773,8 +779,9 @@ class Waveform(MadArray):
return
Waveform
(
self
)
def
__eq__
(
self
,
other
):
# Test the compatability between Waveform
_
=
self
+
other
if
isinstance
(
other
,
Waveform
):
_check_compatibility_fs
(
self
,
other
)
return
super
().
__eq__
(
other
)
def
is_equal
(
self
,
other
):
...
...
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