Exemplo n.º 1
0
def test_vocoder():
    """Test noise, tone, and click 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
    pytest.raises(ValueError, vocode, data, 44100, freq_lims=(200, 30000))
    # bad mode
    pytest.raises(ValueError, vocode, data, 44100, mode='foo')
    # bad seed
    pytest.raises(TypeError, vocode, data, 44100, seed='foo')
    pytest.raises(ValueError, vocode, data, 44100, scale='foo')
    voc1 = vocode(data, 20000, mode='noise', scale='log')
    voc2 = vocode(data, 20000, mode='tone', order=4, seed=0, scale='hz')
    voc3 = vocode(data, 20000, mode='poisson', seed=np.random.RandomState(123))
    # 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)
    assert_array_equal(voc3.shape, data.shape)
Exemplo n.º 2
0
def test_vocoder():
    """Test noise, tone, and click 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, data, 44100, freq_lims=(200, 30000))
    # bad mode
    assert_raises(ValueError, vocode, data, 44100, mode='foo')
    # bad seed
    assert_raises(TypeError, vocode, data, 44100, seed='foo')
    assert_raises(ValueError, vocode, data, 44100, scale='foo')
    voc1 = vocode(data, 20000, mode='noise', scale='log')
    voc2 = vocode(data, 20000, mode='tone', order=4, seed=0, scale='hz')
    voc3 = vocode(data, 20000, mode='poisson', seed=np.random.RandomState(123))
    # 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)
    assert_array_equal(voc3.shape, data.shape)
Exemplo n.º 3
0
"""

import numpy as np
import matplotlib.pyplot as mpl

from expyfun.stimuli import vocode, play_sound, window_edges, read_wav, rms
from expyfun import fetch_data_file

print(__doc__)


data, fs = read_wav(fetch_data_file('audio/dream.wav'))
data = window_edges(data[0], fs)
t = np.arange(data.size) / float(fs)
# noise vocoder
data_noise = vocode(data, fs, mode='noise')
data_noise = data_noise * 0.01 / rms(data_noise)
# sinewave vocoder
data_tone = vocode(data, fs, mode='tone')
data_tone = data_tone * 0.01 / rms(data_tone)
# poisson vocoder
data_click = vocode(data, fs, mode='poisson', rate=400)
data_click = data_click * 0.01 / rms(data_click)

# combine all three
cutoff = data.shape[-1] // 3
data_allthree = data_noise.copy()
data_allthree[cutoff:2 * cutoff] = data_tone[cutoff:2 * cutoff]
data_allthree[2 * cutoff:] = data_click[2 * cutoff:]
snd = play_sound(data_allthree, fs, norm=False, wait=False)
Exemplo n.º 4
0
@author: larsoner
"""

import numpy as np
import matplotlib.pyplot as plt

from expyfun.stimuli import vocode, play_sound, window_edges, read_wav, rms
from expyfun import fetch_data_file

print(__doc__)

data, fs = read_wav(fetch_data_file('audio/dream.wav'))
data = window_edges(data[0], fs)
t = np.arange(data.size) / float(fs)
# noise vocoder
data_noise = vocode(data, fs, mode='noise')
data_noise = data_noise * 0.01 / rms(data_noise)
# sinewave vocoder
data_tone = vocode(data, fs, mode='tone')
data_tone = data_tone * 0.01 / rms(data_tone)
# poisson vocoder
data_click = vocode(data, fs, mode='poisson', rate=400)
data_click = data_click * 0.01 / rms(data_click)

# combine all three
cutoff = data.shape[-1] // 3
data_allthree = data_noise.copy()
data_allthree[cutoff:2 * cutoff] = data_tone[cutoff:2 * cutoff]
data_allthree[2 * cutoff:] = data_click[2 * cutoff:]
snd = play_sound(data_allthree, fs, norm=False, wait=False)