Exemplo n.º 1
0
inertia_filter = maverage(rint(inertia_dur))

api = sys.argv[1] if sys.argv[1:] else None  # Choose API via command-line
chunks.size = 1 if api == "jack" else 16

with AudioIO() as player:
    first_coeffs = formants[vowels[0]]

    # These are signals to be changed during the synthesis
    f1 = ControlStream(first_coeffs[0] * Hz)
    f2 = ControlStream(first_coeffs[1] * Hz)
    gain = ControlStream(0)  # For fading in

    # Creates the playing signal
    filt = CascadeFilter([
        resonator.z_exp(inertia_filter(f1).skip(inertia_dur), 400 * Hz),
        resonator.z_exp(inertia_filter(f2).skip(inertia_dur), 2000 * Hz),
    ])
    sig = filt((saw_table)(100 * Hz)) * inertia_filter(gain)

    th = player.play(sig)
    for vowel in vowels:
        coeffs = formants[vowel]
        print("Now playing: ", vowel)
        f1.value = coeffs[0] * Hz
        f2.value = coeffs[1] * Hz
        gain.value = 1  # Fade in the first vowel, changes nothing afterwards
        sleep(2)

    # Fade out
    gain.value = 0
Exemplo n.º 2
0
wp = pylab.array([100 * Hz, 240 * Hz]) # Bandpass range in rad/sample
ws = pylab.array([80 * Hz, 260 * Hz]) # Bandstop range in rad/sample

# Let's use wp/pi since SciPy defaults freq from 0 to 1 (Nyquist frequency)
order, new_wp_divpi = buttord(wp/pi, ws/pi, gpass=dB10(.6), gstop=dB10(.4))
ssfilt = butter(order, new_wp_divpi, btype="bandpass")
filt_butter = ZFilter(ssfilt[0].tolist(), ssfilt[1].tolist())

# Some debug information
new_wp = new_wp_divpi * pi
print("Butterworth filter order:", order) # Should be 3
print("Bandpass ~3dB range (in Hz):", new_wp / Hz)

# Resonator using only the frequency and bandwidth from the Butterworth filter
freq = new_wp.mean()
bw = new_wp[1] - new_wp[0]
filt_reson = resonator.z_exp(freq, bw)

# Plots with MatPlotLib
kwargs = {
  "min_freq": 10 * Hz,
  "max_freq": 800 * Hz,
  "rate": rate, # Ensure frequency unit in plot is Hz
}
filt_butter.plot(pylab.figure("From scipy.signal.butter"), **kwargs)
filt_reson.plot(pylab.figure("From audiolazy.resonator.z_exp"), **kwargs)
filt_butter.zplot(pylab.figure("Zeros/Poles from scipy.signal.butter"))
filt_reson.zplot(pylab.figure("Zeros/Poles from audiolazy.resonator.z_exp"))
pylab.ioff()
pylab.show()
Exemplo n.º 3
0
rate = 44100
s, Hz = sHz(rate)
inertia_dur = .5 * s
inertia_filter = maverage(rint(inertia_dur))

with AudioIO() as player:
  first_coeffs = formants[vowels[0]]

  # These are signals to be changed during the synthesis
  f1 = ControlStream(first_coeffs[0] * Hz)
  f2 = ControlStream(first_coeffs[1] * Hz)
  gain = ControlStream(0) # For fading in

  # Creates the playing signal
  filt = CascadeFilter([
    resonator.z_exp(inertia_filter(f1).skip(inertia_dur), 400 * Hz),
    resonator.z_exp(inertia_filter(f2).skip(inertia_dur), 2000 * Hz),
  ])
  sig = filt((saw_table)(100 * Hz)) * inertia_filter(gain)

  th = player.play(sig)
  for vowel in vowels:
    coeffs = formants[vowel]
    print("Now playing: ", vowel)
    f1.value = coeffs[0] * Hz
    f2.value = coeffs[1] * Hz
    gain.value = 1 # Fade in the first vowel, changes nothing afterwards
    sleep(2)

  # Fade out
  gain.value = 0
wp = pylab.array([100 * Hz, 240 * Hz])  # Bandpass range in rad/sample
ws = pylab.array([80 * Hz, 260 * Hz])  # Bandstop range in rad/sample

# Let's use wp/pi since SciPy defaults freq from 0 to 1 (Nyquist frequency)
order, new_wp_divpi = buttord(wp / pi, ws / pi, gpass=dB10(.6), gstop=dB10(.4))
ssfilt = butter(order, new_wp_divpi, btype="bandpass")
filt_butter = ZFilter(ssfilt[0].tolist(), ssfilt[1].tolist())

# Some debug information
new_wp = new_wp_divpi * pi
print("Butterworth filter order:", order)  # Should be 3
print("Bandpass ~3dB range (in Hz):", new_wp / Hz)

# Resonator using only the frequency and bandwidth from the Butterworth filter
freq = new_wp.mean()
bw = new_wp[1] - new_wp[0]
filt_reson = resonator.z_exp(freq, bw)

# Plots with MatPlotLib
kwargs = {
    "min_freq": 10 * Hz,
    "max_freq": 800 * Hz,
    "rate": rate,  # Ensure frequency unit in plot is Hz
}
filt_butter.plot(pylab.figure("From scipy.signal.butter"), **kwargs)
filt_reson.plot(pylab.figure("From audiolazy.resonator.z_exp"), **kwargs)
filt_butter.zplot(pylab.figure("Zeros/Poles from scipy.signal.butter"))
filt_reson.zplot(pylab.figure("Zeros/Poles from audiolazy.resonator.z_exp"))
pylab.ioff()
pylab.show()
Exemplo n.º 5
0
  "ɒ": [700, 760],
  "ʌ": [600, 1170],
  "ɔ": [500, 700],
  "ɤ": [460, 1310],
  "o": [360, 640],
  "ɯ": [300, 1390],
  "u": [250, 595],
}

inertia_filter = maverage(rint(.5 * s))

with AudioIO() as player:
  f1, f2 = ControlStream(0), ControlStream(pi)
  gain = ControlStream(0)
  filt = CascadeFilter([
    resonator.z_exp(inertia_filter(f1), 400 * Hz),
    resonator.z_exp(inertia_filter(f2), 2000 * Hz),
  ])
  sig = filt((saw_table)(100 * Hz)) * inertia_filter(gain)

  player.play(sig)

  vowels = "aɛiɒu"
  for vowel in vowels:
    coeffs = formants[vowel]
    print ("Now playing: ", vowel)
    f1.value = coeffs[0] * Hz
    f2.value = coeffs[1] * Hz
    gain.value = 1
    sleep(2)
Exemplo n.º 6
0
    "ɒ": [700, 760],
    "ʌ": [600, 1170],
    "ɔ": [500, 700],
    "ɤ": [460, 1310],
    "o": [360, 640],
    "ɯ": [300, 1390],
    "u": [250, 595],
}

inertia_filter = maverage(rint(.5 * s))

with AudioIO() as player:
    f1, f2 = ControlStream(0), ControlStream(pi)
    gain = ControlStream(0)
    filt = CascadeFilter([
        resonator.z_exp(inertia_filter(f1), 400 * Hz),
        resonator.z_exp(inertia_filter(f2), 2000 * Hz),
    ])
    sig = filt((saw_table)(100 * Hz)) * inertia_filter(gain)

    player.play(sig)

    vowels = "aɛiɒu"
    for vowel in vowels:
        coeffs = formants[vowel]
        print("Now playing: ", vowel)
        f1.value = coeffs[0] * Hz
        f2.value = coeffs[1] * Hz
        gain.value = 1
        sleep(2)