コード例 #1
0
def ks_synth(freq):
    """
  Synthesize the given frequency into a Stream by using a model based on
  Karplus-Strong.
  """
    ks_mem = (sum(lz.sinusoid(x * freq) for x in [1, 3, 9]) +
              lz.white_noise() + lz.Stream(-1, 1)) / 5
    return lz.karplus_strong(freq, memory=ks_mem)
コード例 #2
0
ファイル: play_bach_choral.py プロジェクト: ARK1988/audiolazy
def ks_synth(freq):
  """
  Synthesize the given frequency into a Stream by using a model based on
  Karplus-Strong.
  """
  ks_mem = (sum(lz.sinusoid(x * freq) for x in [1, 3, 9]) +
            lz.white_noise() + lz.Stream(-1, 1)) / 5
  return lz.karplus_strong(freq, memory=ks_mem)
コード例 #3
0
wp = np.array([freq + tol, 2 * freq - tol])  # Bandpass range in rad/sample
ws = np.array([freq - tol, 2 * freq + tol])  # Bandstop range in rad/sample
order, new_wp_divpi = buttord(wp / pi, ws / pi, gpass=dB10(0.6), gstop=dB10(0.4))
ssfilt = butter(order, new_wp_divpi, btype="bandpass")
filt_high = ZFilter(ssfilt[0].tolist(), ssfilt[1].tolist())

## Likewise, using the equation directly this one would be:
# filt_high = ((2.13e-3 * (1 - z ** -6) - 6.39e-3 * (z ** -2 - z ** -4)) /
#             (1 - 4.99173 * z ** -1 + 10.7810 * z ** -2 - 12.8597 * z ** -3
#                + 8.93092 * z ** -4 - 3.42634 * z ** -5 + .569237 * z ** -6))

gain_low = ControlStream(0)
gain_high = ControlStream(0)

low = filt_low(white_noise())
high = filt_high(white_noise())
low /= 2 * max(low.take(2000))
high /= 2 * max(high.take(2000))

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(api=api) as player:
    player.play(low * gain_low + high * gain_high)
    gain_low.value = 1
    while True:
        gain_high.value = 0
        sleep(1)
        for unused in xrange(5):  # Keeps low playing
            sleep(0.1)
            gain_high.value = 0
コード例 #4
0
wp = np.array([freq + tol, 2 * freq - tol])  # Bandpass range in rad/sample
ws = np.array([freq - tol, 2 * freq + tol])  # Bandstop range in rad/sample
order, new_wp_divpi = buttord(wp / pi, ws / pi, gpass=dB10(.6), gstop=dB10(.4))
ssfilt = butter(order, new_wp_divpi, btype="bandpass")
filt_high = ZFilter(ssfilt[0].tolist(), ssfilt[1].tolist())

## Likewise, using the equation directly this one would be:
#filt_high = ((2.13e-3 * (1 - z ** -6) - 6.39e-3 * (z ** -2 - z ** -4)) /
#             (1 - 4.99173 * z ** -1 + 10.7810 * z ** -2 - 12.8597 * z ** -3
#                + 8.93092 * z ** -4 - 3.42634 * z ** -5 + .569237 * z ** -6))

gain_low = ControlStream(0)
gain_high = ControlStream(0)

low = filt_low(white_noise())
high = filt_high(white_noise())
low /= 2 * max(low.take(2000))
high /= 2 * max(high.take(2000))

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(api=api) as player:
    player.play(low * gain_low + high * gain_high)
    gain_low.value = 1
    while True:
        gain_high.value = 0
        sleep(1)
        for unused in xrange(5):  # Keeps low playing
            sleep(.1)
            gain_high.value = 0
コード例 #5
0
ファイル: play_bach_choral.py プロジェクト: douglaz/audiolazy
def ks_mem(freq):
  """ Alternative memory for Karplus-Strong """
  return (sum(lz.sinusoid(x * freq) for x in [1, 3, 9]) +
          lz.white_noise() + lz.Stream(-1, 1)) / 5