コード例 #1
0
 def test_wavread(self):
     fn = data_file_path('beijing_f3_50_a.wav')
     samples, Fs = wavread(fn)
     expected = loadmat('beijing_f3_50_a-wavread-expected')
     self.assertEqual(Fs, expected['Fs'])
     # XXX may need to use allclose here instead of array_equal.
     if not np.array_equal(samples, expected['y']):
         # Produce a useful error message for debugging.
         self.assertEqual(list(samples), list(expected['y']))
コード例 #2
0
 def test_second_peak_index(self):
     data = loadmat("twomax_data")
     x = data["x"]
     for i in range(142, 146):
         # Zap the values in the second peak range to exercise the branch.
         x[i] = 0.0001 * i
     mag, index = two_max(x, int(data["lowerbound"]) - 1, int(data["upperbound"]) - 1, data["unitlen"])
     np.testing.assert_array_almost_equal(mag, np.append(data["mag"], 0.0145))
     np.testing.assert_array_equal(index, [int(data["index"]) - 1, 145])
コード例 #3
0
 def test_with_matlab_data(self):
     data = loadmat("shrp_data")
     f0_time, f0_value, shr, f0_candidates = shrp(
         data["Y"],
         int(data["Fs"]),
         [int(x) for x in data["F0MinMax"]],
         int(data["frame_length"]),
         int(data["timestep"]),
         data["SHR_Threshold"],
         data["ceiling"],
         data["med_smooth"],
         data["CHECK_VOICING"],
     )
     np.testing.assert_array_almost_equal(f0_time, data["f0_time"])
     np.testing.assert_array_almost_equal(f0_value, data["f0_value"])
     np.testing.assert_array_almost_equal(shr, data["SHR"])
     np.testing.assert_array_almost_equal(f0_candidates, data["f0_candidates"])
コード例 #4
0
 def matlab_fn_as_matlab_input_data(self, filename):
     data = loadmat(filename)
     peak_index, shr, shshift, index = compute_shr(
         data["log_spectrum"],
         data["min_bin"],
         data["startpos"].astype(int) - 1,
         data["endpos"].astype(int) - 1,
         int(data["lowerbound"]) - 1,
         int(data["upperbound"]) - 1,
         int(data["N"]),
         int(data["shift_units"]),
         data["SHR_Threshold"],
     )
     np.testing.assert_array_equal(peak_index, int(data["peak_index"]) - 1)
     np.testing.assert_array_almost_equal(shr, data["SHR"])
     np.testing.assert_array_almost_equal(shshift, data["shshift"])
     np.testing.assert_array_almost_equal(index, data["index"] - 1)
コード例 #5
0
 def matlab_fn_as_matlab_input_data(self, filename):
     data = loadmat(filename)
     mag, index = two_max(data["x"], int(data["lowerbound"]) - 1, int(data["upperbound"]) - 1, data["unitlen"])
     np.testing.assert_array_almost_equal(mag, data["mag"])
     np.testing.assert_array_almost_equal(index, int(data["index"]) - 1)
コード例 #6
0
 def test_with_matlab_data(self):
     data = loadmat("toframes_data")
     res = toframes(data["input"], data["curpos"].astype(int) - 1, int(data["segmentlen"]), "hamm")
     np.testing.assert_array_almost_equal(res, data["frames"])
コード例 #7
0
 def test_with_matlab_data(self):
     data = loadmat("shr_pitch_data")
     wav_data, fps = wavread(data_file_path("beijing_f3_50_a.wav"))
     shr, f0 = shr_pitch(wav_data, fps, 25, 1, 50, 550, 0.4, 5, 200)
     np.testing.assert_array_almost_equal(f0, data["F0"])
     np.testing.assert_array_almost_equal(shr, data["SHR"])
コード例 #8
0
 def test_with_matlab_data(self):
     data = loadmat("GetLogSpectrum_data")
     interp_amplitude = get_log_spectrum(
         data["segment"], data["fftlen"], data["limit"] - 1, data["logf"], data["interp_logf"]
     )
     np.testing.assert_array_almost_equal(interp_amplitude, data["interp_amplitude"])