示例#1
0
 def player(self, value):
     # Also initialize playing thread
     self._player = value
     self.volume_ctrl = ControlStream(.2)
     self.carrier_ctrl = ControlStream(220)
     self.mod_ctrl = ControlStream(440)
     sound = sinusoid(freq=self.carrier_ctrl * Hz,
                      phase=sinusoid(self.mod_ctrl * Hz)) * self.volume_ctrl
     self.playing_thread = player.play(sound)
示例#2
0
 def player(self, value):
   # Also initialize playing thread
   self._player = value
   self.volume_ctrl = ControlStream(.2)
   self.carrier_ctrl = ControlStream(220)
   self.mod_ctrl = ControlStream(440)
   sound = sinusoid(freq=self.carrier_ctrl * Hz,
                    phase=sinusoid(self.mod_ctrl * Hz)
                   ) * self.volume_ctrl
   self.playing_thread = player.play(sound)
示例#3
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)
示例#4
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)
示例#5
0
def partial():
  smix.add(octave_duration, partial_cached()) # Next track/partial event
  # Octave-based frequency values sequence
  scale = 2 ** line(duration, finish=True)
  partial_freq = (scale - 1) * (max_freq - min_freq) + min_freq
  # Envelope to "hide" the partial beginning/ending
  env = [k ** 2 for k in window.hamming(int(round(duration)))]
  # The generator, properly:
  for el in env * sinusoid(partial_freq) / noctaves:
    data.append(el)
    yield el
示例#6
0
def partial():
    smix.add(octave_duration, partial_cached())  # Next track/partial event
    # Octave-based frequency values sequence
    scale = 2**line(duration, finish=True)
    partial_freq = (scale - 1) * (max_freq - min_freq) + min_freq
    # Envelope to "hide" the partial beginning/ending
    env = [k**2 for k in window.hamming(int(round(duration)))]
    # The generator, properly:
    for el in env * sinusoid(partial_freq) / noctaves:
        data.append(el)
        yield el
示例#7
0
def unpitched_low(dur, idx):
    """
  Non-harmonic bass/lower frequency sound as a list (due to memoization).

  Parameters
  ----------
  dur:
    Duration, in samples.
  idx:
    Zero or one (integer), for a small difference to the sound played.

  Returns
  -------
  A list with the synthesized note.

  """
    env = sinusoid(lag2freq(dur * 2)).limit(dur)**2
    freq = 40 + 20 * sinusoid(1000 * Hz, phase=uniform(-pi, pi))  # Hz
    result = (low_table(freq * Hz) + low_table(freq * 1.1 * Hz)) * env * .5
    return list(result)
def unpitched_low(dur, idx):
    """
  Non-harmonic bass/lower frequency sound as a list (due to memoization).

  Parameters
  ----------
  dur:
    Duration, in samples.
  idx:
    Zero or one (integer), for a small difference to the sound played.

  Returns
  -------
  A list with the synthesized note.

  """
    env = sinusoid(lag2freq(dur * 2)).limit(dur) ** 2
    freq = 40 + 20 * sinusoid(1000 * Hz, phase=uniform(-pi, pi))  # Hz
    result = (low_table(freq * Hz) + low_table(freq * 1.1 * Hz)) * env * 0.5
    return list(result)
LPTV (Linear Periodically Time Variant) filter example (a.k.a. PLTV)
"""

from audiolazy import sHz, sinusoid, Stream, AudioIO, z, pi, chunks
import time, sys

# Basic initialization
rate = 44100
s, Hz = sHz(rate)

# Some time-variant coefficients
cycle_a1 = [.1, .2, .1, 0, -.1, -.2, -.1, 0]
cycle_a2 = [.1, 0, -.1, 0, 0]
a1 = Stream(*cycle_a1)
a2 = Stream(*cycle_a2) * 2
b1 = sinusoid(18 * Hz)  # Sine phase
b2 = sinusoid(freq=7 * Hz, phase=pi / 2)  # Cosine phase

# The filter
filt = (1 + b1 * z**-1 + b2 * z**-2 + .7 * z**-5)
filt /= (1 - a1 * z**-1 - a2 * z**-2 - .1 * z**-3)

# A really simple input
input_data = sinusoid(220 * Hz)

# Let's play it!
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:
    th = player.play(input_data, rate=rate)
    time.sleep(1)  # Wait a sec
示例#10
0
LPTV (Linear Periodically Time Variant) filter example (a.k.a. PLTV)
"""

from audiolazy import sHz, sinusoid, Stream, AudioIO, z, pi
import time

# Basic initialization
rate = 44100
s, Hz = sHz(rate)

# Some time-variant coefficients
cycle_a1 = [.1, .2, .1, 0, -.1, -.2, -.1, 0]
cycle_a2 = [.1, 0, -.1, 0, 0]
a1 = Stream(*cycle_a1)
a2 = Stream(*cycle_a2) * 2
b1 = sinusoid(18 * Hz) # Sine phase
b2 = sinusoid(freq=7 * Hz, phase=pi/2) # Cosine phase

# The filter
filt = (1 + b1 * z ** -1 + b2 * z ** -2 + .7 * z ** -5)
filt /= (1 - a1 * z ** -1 - a2 * z ** -2 - .1 * z ** -3)

# A really simple input
input_data = sinusoid(220 * Hz)

# Let's play it!
with AudioIO() as player:
  th = player.play(input_data, rate=rate)
  time.sleep(1) # Wait a sec
  th.stop()
  time.sleep(1) # One sec "paused"
示例#11
0
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