def test_triangle_freqs_with_double_value(self): """make sure set_triangle_bands works with 2 duplicate freqs""" samplerate = 22050 freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000] f = filterbank(len(freq_list)-2, 1024) with assert_warns(UserWarning): f.set_triangle_bands(fvec(freq_list), samplerate)
def test_triangle_freqs_with_too_many_filters(self): """make sure set_triangle_bands warns when too many filters""" samplerate = 22050 freq_list = [0, 100, 1000, 4000, 8000, 10000] f = filterbank(len(freq_list)-1, 1024) with assert_warns(UserWarning): f.set_triangle_bands(fvec(freq_list), samplerate)
def test_triangle_freqs_with_large_freq(self): """make sure set_triangle_bands warns when freq > nyquist""" samplerate = 22050 freq_list = [0, samplerate//4, samplerate // 2 + 1] f = filterbank(len(freq_list)-2, 1024) with assert_warns(UserWarning): f.set_triangle_bands(fvec(freq_list), samplerate)
def test_samplerate_hopsize(self, hop_size, samplerate, soundfile): orig_samplerate = parse_file_samplerate(soundfile) try: if orig_samplerate is not None and orig_samplerate < samplerate: # upsampling should emit a warning with assert_warns(UserWarning): f = source(soundfile, samplerate, hop_size) else: f = source(soundfile, samplerate, hop_size) except RuntimeError as e: err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})' skipTest(err_msg.format(hop_size, samplerate, str(e))) assert f.samplerate != 0 read_frames = self.read_from_source(f) if 'f_' in soundfile and samplerate == 0: import re f = re.compile(r'.*_\([0:9]*f\)_.*') match_f = re.findall('([0-9]*)f_', soundfile) if len(match_f) == 1: expected_frames = int(match_f[0]) assert_equal(expected_frames, read_frames)
def test_read_and_write_multi(self, hop_size, samplerate, path): orig_samplerate = parse_file_samplerate(soundfile) try: if orig_samplerate is not None and orig_samplerate < samplerate: # upsampling should emit a warning with assert_warns(UserWarning): f = source(soundfile, samplerate, hop_size) else: f = source(soundfile, samplerate, hop_size) except RuntimeError as e: err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})' skipTest(err_msg.format(str(e), hop_size, samplerate)) if samplerate == 0: samplerate = f.samplerate sink_path = get_tmp_sink_path() g = sink(sink_path, samplerate, channels = f.channels) total_frames = 0 while True: vec, read = f.do_multi() g.do_multi(vec, read) total_frames += read if read < f.hop_size: break del_tmp_sink_path(sink_path)
def test_read_and_write_multi(self, hop_size, samplerate, path): orig_samplerate = parse_file_samplerate(soundfile) try: if orig_samplerate is not None and orig_samplerate < samplerate: # upsampling should emit a warning with assert_warns(UserWarning): f = source(soundfile, samplerate, hop_size) else: f = source(soundfile, samplerate, hop_size) except RuntimeError as e: err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})' skipTest(err_msg.format(str(e), hop_size, samplerate)) if samplerate == 0: samplerate = f.samplerate sink_path = get_tmp_sink_path() g = sink(sink_path, samplerate, channels=f.channels) total_frames = 0 while True: vec, read = f.do_multi() g.do_multi(vec, read) total_frames += read if read < f.hop_size: break del_tmp_sink_path(sink_path)
def test_hztomel_negative(self): with assert_warns(UserWarning): assert_equal(meltohz(-1, htk=True), 0) with assert_warns(UserWarning): assert_equal(hztomel(-1, htk=True), 0) assert_almost_equal(hztomel(1000, htk=True), 1000., decimal=1)
def test_meltohz_negative(self): with assert_warns(UserWarning): assert_equal(meltohz(-1, htk=True), 0) assert_almost_equal(meltohz(2000, htk=True), 3428.7, decimal=1) assert_almost_equal(meltohz(1000, htk=True), 1000., decimal=1)
def test_hztomel_negative(self): with assert_warns(UserWarning): assert_equal(hztomel(-1), 0)
def test_meltohz_negative(self): with assert_warns(UserWarning): assert_equal(meltohz(-1), 0)