def test_vocoder(): """Test noise and tone vocoding """ data = np.random.randn(10000) env = np.random.randn(10000) b, a = butter(4, 0.001, 'lowpass') data *= lfilter(b, a, env) # bad limits assert_raises(ValueError, vocode_ci, data, 44100, freq_lims=(200, 30000)) # bad mode assert_raises(ValueError, vocode_ci, data, 44100, mode='foo') voc1 = vocode_ci(data, 20000, mode='noise', order=2) voc2 = vocode_ci(data, 20000, mode='tone', order=4, rand_seed=0) # XXX This is about the best we can do for now... assert_array_equal(voc1.shape, data.shape) assert_array_equal(voc2.shape, data.shape)
======================== This shows how to make simple vocoded stimuli. @author: larsoner """ import numpy as np from expyfun.stimuli import vocode_ci, play_sound, window_edges, read_wav from expyfun import fetch_data_file data, fs = read_wav(fetch_data_file('audio/dream.wav')) data = window_edges(data[0], fs) t = np.arange(data.size) / float(fs) data_ci = vocode_ci(data, fs, mode='noise', order=4, verbose=True) # Uncomment this to play the original, too: #snd = play_sound(data, fs, norm=False, wait=False) snd = play_sound(data_ci, fs, norm=False, wait=False) import matplotlib.pyplot as mpl mpl.ion() ax1 = mpl.subplot(2, 1, 1) ax1.plot(t, data) ax1.set_title('Original') ax2 = mpl.subplot(2, 1, 2, sharex=ax1, sharey=ax1) ax2.plot(t, data_ci) ax2.set_title('Vocoded') ax2.set_xlabel('Time (sec)')