コード例 #1
0
def new_note_track(env, synth):
    """
  Audio track with the frequencies.

  Parameters
  ----------
  env:
    Envelope Stream (which imposes the duration).
  synth:
    One-argument function that receives a frequency (in rad/sample) and
    returns a Stream instance (a synthesized note).

  Returns
  -------
  Endless Stream instance that joins synthesized notes.

  """
    list_env = list(env)
    return chain.from_iterable(synth(freq) * list_env for freq in freq_gen())
コード例 #2
0
def new_note_track(env, synth):
    """
  Audio track with the frequencies.

  Parameters
  ----------
  env:
    Envelope Stream (which imposes the duration).
  synth:
    One-argument function that receives a frequency (in rad/sample) and
    returns a Stream instance (a synthesized note).

  Returns
  -------
  Endless Stream instance that joins synthesized notes.

  """
    list_env = list(env)
    return chain.from_iterable(synth(freq) * list_env for freq in freq_gen())
コード例 #3
0
        remain -= gain
    return out


#
# Audio mixture
#
tracks = 3  # besides unpitched track
dur_note = 120 * ms
dur_perc = 100 * ms
smix = Streamix()

# Pitched tracks based on a 1:2 triangular wave
table = TableLookup(line(100, -1, 1).append(line(200, 1, -1)).take(inf))
for track in xrange(tracks):
    env = adsr(dur_note, a=20 * ms, d=10 * ms, s=.8, r=30 * ms) / 1.7 / tracks
    smix.add(0, geometric_delay(new_note_track(env, table), 80 * ms, 2))

# Unpitched tracks
pfuncs = [unpitched_low] * 4 + [unpitched_high]
snd = chain.from_iterable(
    choice(pfuncs)(dur_perc, randint(0, 1)) for unused in zeros())
smix.add(0, geometric_delay(snd * (1 - 1 / 1.7), 20 * ms, 1))

#
# Finishes (save in a wave file)
#
data = lowpass(5000 * Hz)(smix).limit(180 * s)
fname = "audiolazy_save_and_memoize_synth.wav"
save_to_16bit_wave_file(fname, data, rate)
コード例 #4
0
        remain -= gain
    return out


#
# Audio mixture
#
tracks = 3  # besides unpitched track
dur_note = 120 * ms
dur_perc = 100 * ms
smix = Streamix()

# Pitched tracks based on a 1:2 triangular wave
table = TableLookup(line(100, -1, 1).append(line(200, 1, -1)).take(inf))
for track in xrange(tracks):
    env = adsr(dur_note, a=20 * ms, d=10 * ms, s=0.8, r=30 * ms) / 1.7 / tracks
    smix.add(0, geometric_delay(new_note_track(env, table), 80 * ms, 2))

# Unpitched tracks
pfuncs = [unpitched_low] * 4 + [unpitched_high]
snd = chain.from_iterable(choice(pfuncs)(dur_perc, randint(0, 1)) for unused in zeros())
smix.add(0, geometric_delay(snd * (1 - 1 / 1.7), 20 * ms, 1))


#
# Finishes (save in a wave file)
#
data = lowpass(5000 * Hz)(smix).limit(180 * s)
fname = "audiolazy_save_and_memoize_synth.wav"
save_to_16bit_wave_file(fname, data, rate)
コード例 #5
0
ファイル: gtpm.py プロジェクト: danilobellini/gtpm
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)
  ks_snd = distortion(karplus_strong(freq * Hz,
コード例 #6
0
ファイル: gtpm.py プロジェクト: danilobellini/gtpm
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)
    ks_snd = distortion(karplus_strong(freq * Hz, tau=.2 * s,