Commit 8e57c9b7 authored by valentin.emiya's avatar valentin.emiya

fix bug in resample test (now understood)

parent 131e78e1
Pipeline #607 passed with stage
in 20 seconds
......@@ -243,34 +243,32 @@ class TestWaveform:
w.resample(fs=fs)
assert w.fs == fs
assert w.length == int(np.floor(fs * self.length / self.fs))
assert w.length == int(np.floor(fs / self.fs * self.length))
assert not w.is_stereo()
print(self.length, self.fs)
assert w.duration == pytest.approx(self.length / self.fs, 1e-4)
np.testing.assert_equal(
w.time_axis,
np.arange(np.floor(fs * self.length / self.fs)) / fs)
np.arange(np.floor(fs / self.fs * self.length)) / fs)
# Stereo
w = Waveform(self.x_stereo, fs=self.fs)
w.resample(fs=fs)
assert w.fs == fs
assert w.length == int(np.floor(fs * self.length / self.fs))
assert w.length == int(np.floor(fs / self.fs * self.length))
assert w.is_stereo()
assert w.duration == pytest.approx(self.length / self.fs, 1e-4)
np.testing.assert_equal(
w.time_axis,
np.arange(np.floor(fs * self.length / self.fs)) / fs)
np.arange(np.floor(fs / self.fs * self.length)) / fs)
# Floating values with ratios that are exact rationals
for (old_fs, new_fs) in [(1, 1.5), (0.5, 3), (100.1, 200.2)]:
print('Testing resampling {}/{}, signal length = {}'
.format(new_fs, old_fs, w.shape[0]))
w = Waveform(self.x_mono, fs=old_fs)
w.resample(fs=new_fs)
assert w.fs == new_fs
assert w.length == int(new_fs * self.length / old_fs)
assert w.length == int(new_fs / old_fs * self.length)
# Floating values with ratios that are not well approximated
# by rationals
......
......@@ -310,15 +310,15 @@ class Waveform(MadArray):
UserWarning
"""
assert np.issubdtype(type(fs), np.integer) or np.issubdtype(type(fs),
np.float)
assert np.issubdtype(type(fs), np.integer) \
or np.issubdtype(type(fs), np.floating)
if fs <= 0:
errmsg = '`fs` should be a positive number (given: {})'
raise ValueError(errmsg.format(fs))
if np.issubdtype(type(fs), np.float) or np.issubdtype(type(self.fs),
np.float):
if np.issubdtype(type(fs), np.floating) \
or np.issubdtype(type(self.fs), np.floating):
# Find a good rational number to approximate the ratio between
# sampling frequencies
fs_ratio = Fraction(fs/self.fs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment