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)
Exemple #2
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)
  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)
Exemple #4
0
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,
                                     memory=ks_memory))
  tl_snd = .5 * table(freq * Hz) * env
  smix.add(dur, .5 * ks_snd + .5 * tl_snd)

# Shows synthesis wavetables
pylab.subplot(2, 1, 1)
pylab.plot(table.table)
pylab.title("Table lookup waveform")
pylab.axis(xmax=len(table) - 1)
pylab.subplot(2, 1, 2)
pylab.plot(mem_table.table)
pylab.title("Karplus-strong memory (besides noise)")
pylab.axis(xmax=len(mem_table) - 1)
pylab.tight_layout()
pylab.show()

# Voila!
smix.add(dur, zeros(.2 * s)) # Avoid ending click
with AudioIO(True) as player:
  player.play(smix, rate=rate)
Exemple #5
0
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,
                                       memory=ks_memory))
    tl_snd = .5 * table(freq * Hz) * env
    smix.add(dur, .5 * ks_snd + .5 * tl_snd)

# Shows synthesis wavetables
pylab.subplot(2, 1, 1)
pylab.plot(table.table)
pylab.title("Table lookup waveform")
pylab.axis(xmax=len(table) - 1)
pylab.subplot(2, 1, 2)
pylab.plot(mem_table.table)
pylab.title("Karplus-strong memory (besides noise)")
pylab.axis(xmax=len(mem_table) - 1)
pylab.tight_layout()
pylab.show()

# Voila!
smix.add(dur, zeros(.2 * s))  # Avoid ending click
with AudioIO(True) as player:
    player.play(smix, rate=rate)
step = 60. / beat * s

# Open the choral file
choral_file = corpus.getBachChorales()[random.randint(0, 399)]
choral = corpus.parse(choral_file)
print u"Playing", choral.metadata.title

# Creates the score from the music21 data
score = reduce(operator.concat,
               [[(pitch.frequency * Hz, # Note
                  note.offset * step, # Starting time
                  note.quarterLength * step, # Duration
                  Fermata in note.expressions) for pitch in note.pitches]
                                               for note in choral.flat.notes]
              )

# Mix all notes into song
song = lz.Streamix()
last_start = 0
for freq, start, dur, has_fermata in score:
  delta = start - last_start
  if has_fermata:
    delta *= 2
  song.add(delta, lz.karplus_strong(freq, memory=ks_mem(freq)) * lz.ones(dur))
  last_start = start

# Play the song!
with lz.AudioIO(True) as player:
  song = song.append(lz.zeros(.5 * s)) # To avoid a click at the end
  player.play(song, rate=rate)
  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)