Exemple #1
0
def geometric_delay(sig, dur, copies, pamp=.5):
    """
  Delay effect by copying data (with Streamix).

  Parameters
  ----------
  sig:
    Input signal (an iterable).
  dur:
    Duration, in samples.
  copies:
    Number of times the signal will be replayed in the given duration. The
    signal is played copies + 1 times.
  pamp:
    The relative remaining amplitude fraction for the next played Stream,
    based on the idea that total amplitude should sum to 1. Defaults to 0.5.

  """
    out = Streamix()
    sig = thub(sig, copies + 1)
    out.add(0, sig * pamp)  # Original
    remain = 1 - pamp
    for unused in xrange(copies):
        gain = remain * pamp
        out.add(dur / copies, sig * gain)
        remain -= gain
    return out
def geometric_delay(sig, dur, copies, pamp=0.5):
    """
  Delay effect by copying data (with Streamix).

  Parameters
  ----------
  sig:
    Input signal (an iterable).
  dur:
    Duration, in samples.
  copies:
    Number of times the signal will be replayed in the given duration. The
    signal is played copies + 1 times.
  pamp:
    The relative remaining amplitude fraction for the next played Stream,
    based on the idea that total amplitude should sum to 1. Defaults to 0.5.

  """
    out = Streamix()
    sig = thub(sig, copies + 1)
    out.add(0, sig * pamp)  # Original
    remain = 1 - pamp
    for unused in xrange(copies):
        gain = remain * pamp
        out.add(dur / copies, sig * gain)
        remain -= gain
    return out
Exemple #3
0
def metadata2ttl(mdata, **kwargs):
  """ Metadata object to Turtle (ttl) source code string. """
  frags = thub(ttl_single_uri_data(mdata, **kwargs), 2)
  plugin_metadata_code = "".join(frags)
  prefixes = get_prefixes(frags)
  prefix_template = "@prefix {prefix}: <{uri}>.\n"
  prefixes_code = "".join(prefix_template.format(prefix=prefix,
                                                 uri=ttl_prefixes[prefix])
                          for prefix in prefixes)
  plugin_uri = "\n<{}>\n".format(mdata.uri)
  return "".join([prefixes_code, plugin_uri, plugin_metadata_code])
Exemple #4
0
def mgl_seq(x):
  """
  Sequence whose sum is the Madhava-Gregory-Leibniz series.

    [x,  -x^3/3, x^5/5, -x^7/7, x^9/9, -x^11/11, ...]

  Returns
  -------
    An endless sequence that has the property
    ``atan(x) = sum(mgl_seq(x))``.
    Usually you would use the ``atan()`` function, not this one.

  """
  odd_numbers = thub(count(start=1, step=2), 2)
  return Stream(1, -1) * x ** odd_numbers / odd_numbers
def mgl_seq(x):
  """
  Sequence whose sum is the Madhava-Gregory-Leibniz series.

    [x,  -x^3/3, x^5/5, -x^7/7, x^9/9, -x^11/11, ...]

  Returns
  -------
    An endless sequence that has the property
    ``atan(x) = sum(mgl_seq(x))``.
    Usually you would use the ``atan()`` function, not this one.

  """
  odd_numbers = thub(count(start=1, step=2), 2)
  return Stream(1, -1) * x ** odd_numbers / odd_numbers
Exemple #6
0
def limiter(sig, threshold=.1, size=256, env=envelope.rms, cutoff=pi/2048):
  sig = thub(sig, 2)
  return sig * Stream( 1. if el <= threshold else threshold / el
                       for el in maverage(size)(env(sig, cutoff=cutoff)) )
Exemple #7
0
def limiter(sig, threshold=.1, size=256, env=envelope.rms, cutoff=pi / 2048):
    sig = thub(sig, 2)
    return sig * Stream(1. if el <= threshold else threshold / el
                        for el in maverage(size)(env(sig, cutoff=cutoff)))
# coding: utf-8
from audiolazy import count, takewhile, thub


def prime_gen():
    """ Gerador de números primos """
    yield 2
    primes = []
    for value in count(start=3, step=2):
        stream_primes = takewhile(lambda x: x * x <= value, primes)
        if all(value % stream_primes != 0):
            primes.append(value)
            yield value


primes = thub(prime_gen(), 2)

for idx, p in enumerate(primes, 1):
    print(u"{:>5}º primo: {}".format(idx, p))
    if idx == 200:
        break

for idx, p in enumerate(primes, 1):
    print(u"{:>5}º primo ao quadrado: {}".format(idx, p**2))
    if idx == 200:
        break
Exemple #9
0
ms = 1e-3 * s
kHz = 1e3 * Hz
beat_duration = 60. / beat * s # In samples
dur = beat_duration / notes_per_beat # Per note
smix = Streamix() # That's our sound mixture
env = adsr(dur, a=40*ms, d=35*ms, s=.6, r=70*ms).take(inf) # Envelope

# Effects used
def distortion(sig, multiplier=18):
  return atan(multiplier * sig) * (2 / pi)

# Intro count synth
filt = (1 - z ** -2) * .5
if starting_beats > 0:
  inoisy_stream = filt(gauss_noise()) * env
  inoisy_thub = thub(inoisy_stream.append(0).limit(beat_duration),
                     starting_beats)
  inoisy = chain.from_iterable(repeat(inoisy_thub).limit(starting_beats))
  smix.add(.1 * s, inoisy)
  smix.add(starting_beats * beat_duration - dur, []) # Event timing

# Wavetable lookup initialization
square_table = TableLookup([1] * 256 + [-1] * 256)
harmonics = dict(enumerate([1, 3, 2, 1, .3, .1, .7, .9, 1, 1, .5, .4, .2], 1))
table = sin_table.harmonize(harmonics).normalize()
mem_table = (3 * saw_table + (sin_table - saw_table) ** 3).normalize()

# Notes synth
midi_tuning = str2midi([gs.tune for gs in guitar])
midi_pitches = [midi_tuning[string_idx] + fret for string_idx, fret in notes]
for freq in midi2freq(midi_pitches):
  ks_memory = .1 * gauss_noise() + .9 * mem_table(freq * Hz)
Exemple #10
0
beat_duration = 60. / beat * s  # In samples
dur = beat_duration / notes_per_beat  # Per note
smix = Streamix()  # That's our sound mixture
env = adsr(dur, a=40 * ms, d=35 * ms, s=.6, r=70 * ms).take(inf)  # Envelope


# Effects used
def distortion(sig, multiplier=18):
    return atan(multiplier * sig) * (2 / pi)


# Intro count synth
filt = (1 - z**-2) * .5
if starting_beats > 0:
    inoisy_stream = filt(gauss_noise()) * env
    inoisy_thub = thub(
        inoisy_stream.append(0).limit(beat_duration), starting_beats)
    inoisy = chain.from_iterable(repeat(inoisy_thub).limit(starting_beats))
    smix.add(.1 * s, inoisy)
    smix.add(starting_beats * beat_duration - dur, [])  # Event timing

# Wavetable lookup initialization
square_table = TableLookup([1] * 256 + [-1] * 256)
harmonics = dict(enumerate([1, 3, 2, 1, .3, .1, .7, .9, 1, 1, .5, .4, .2], 1))
table = sin_table.harmonize(harmonics).normalize()
mem_table = (3 * saw_table + (sin_table - saw_table)**3).normalize()

# Notes synth
midi_tuning = str2midi([gs.tune for gs in guitar])
midi_pitches = [midi_tuning[string_idx] + fret for string_idx, fret in notes]
for freq in midi2freq(midi_pitches):
    ks_memory = .1 * gauss_noise() + .9 * mem_table(freq * Hz)