def whispers(space): return sp.scale_normalize( sp.noise(space) * 0.03 - sp.sin( space + sp.noise(space) * 0.0001, sp.arp(space, np.array([98, 99, 98, 99, 97, 98, 99, 97, 96, 99] * 10)) * 5.) * 0.45 * sp.pulse(sp.sin(space, 0.01) * 50, 120, 0.25) * 0.02)
def melody(space): return sp.scale_normalize( sp.reverb(sp.saw(song, melody_pattern(song, steps=7, reps=25)), 1. / 60., 5) - sp.reverb(sp.saw(song, melody_pattern(song, 0.5, 2, 15, 7)), 1. / 55., 5)) * sp.square(space + sp.sin(space, 1. / 40.) * 40, 40)
import sys import numpy as np import shaded as sp import sounddevice as sd import soundfile as sf def play(sound, sample_rate=sp.SAMPLE_RATE): """Helper to play serially""" sd.play(sound) time.sleep(len(sound) / sample_rate) space = sp.space(3) one_hz = (sp.sin(space, 1.) / 2. + 0.5) #beating concertA = sp.sin(space, 440) #concert A sin wave for three seconds modulatedA = concertA * one_hz #beating w/ a sin wave buzz = sp.sigmoid( sp.sin(space, 60), sp.sin(space, 60) + 220) * 0.5 #buzzing by modulating frequency div = (sp.sin(space, 17) / sp.sin(space, 3) ) * 0.2 * concertA #dividing signals to generate complex waveforms complex_beat = sp.noise(space) * (sp.sigmoid( space, 2) - sp.sin(space, 0.4) - sp.sin(space, 0.25, 1)) + sp.sin( space, 440) * (sp.sin(space, 3) - sp.sin(space, 4.25)) + sp.sin( space, 310) * (sp.sin(space, 3, 1.254)) #complex beat fmod = sp.sin( space, sp.sin(space, 2) * 220 ) #because of broadcasting, you can use waves to control the frequency of other waves
import shaded as sd from sounddevice import play import soundfile as sf import numpy as np song = sd.space(13) overall_env = sd.smoothstep(0, 1, song) - sd.smoothstep(12, 14.8, song) bass_line = sd.arp(song, [110, 130.81, 146.83, 110] * 5) #this time, the "*" means we're repeating bass_line_wave = sd.smooth_normalize( sd.sin(song, bass_line) * sd.pulse(song, 3, 0.333, normalize=False)) drums = sd.noise(song) * sd.sigmoid(song, 10) * sd.sigmoid( song, 12, 0.25 * 2 * np.pi) * 0.2 melody_a = sd.arp(song, [440, 880, 440, 220]) melody_b = sd.arp(song, [523.25, 392.00, 659.25] * 6) string = sd.saw(song, melody_a) * 0.25 + sd.saw(song, melody_b) * 0.25 full_song = bass_line_wave * sd.smoothstep( 2, 3, song) + drums * 0.25 + string * 0.5 * (sd.smoothstep(4, 6, song) - sd.smoothstep(8, 10, song)) sf.write('working/demo.wav', full_song, int(44100), 'FLOAT')
def closing_scream(space): return sp.saw(space, 990 - sp.sin(space, 3)) - sp.saw( space / 5. * sp.sin(space, 0.1), 890) - sp.saw(space, 650)
def whisper_slide(space): return (sp.sin(space, 0.01) * sp.sin(space, 0.02) * sp.sin( space, sp.arp(space, [0.125, 0.5, 0.9, 3., 3.2, 0.125, 0.52, 0.4, 3., 9, 0.125])))
def melody_rhthym(space): return sp.sigmoid(space, 0.25) * sp.gated_pulse(space, 1, 0.3333) + sp.sin( space, 1, np.pi)
def drum_line(space): return ( sp.saw(space + sp.noise(space) * 0.004 + sp.saw(space, 12) * 5., 40) * sp.gated_pulse(space, 4, 0.25) * sp.sin(space, 4) + sp.gated_pulse(space, 4, 0.125, np.pi * 0.1))
def closing_scream(space): return sp.saw(space, 990 - sp.sin(space, 3)) - sp.saw( space / 5. * sp.sin(space, 0.1), 890) - sp.saw(space, 650) def rpeak(space): dur = len(space) / sp.SAMPLE_RATE return sp.saw(space, dur / 20., np.pi / 4.) * sp.gate( space, dur / 20. * 19.) song = sp.space(120) bass_line = sp.reverb( bass_prog(song, 20) * bass_beat(song) * bass_enter_exit(song, 7), 1. / 15., 10) drums = sp.reverb(drum_line(song), -1. / 30., 7) mel = melody(song) * melody_rhthym(song) * melody_gate(song, 3., 100) whispered = sp.reverb(whispers(song) * whisper_slide(song), 1. / 50., 12, 0.7) closing = sp.reverb(closing_scream(song), -1., 10) * rpeak(song) composition = (bass_line + drums * 0.5 + mel - whispered * 0.25 + closing + np.roll(closing, int(-30 * sp.SAMPLE_RATE)) + np.roll(closing, int(-60 * sp.SAMPLE_RATE)) - np.fmod( np.roll(closing, int(17 * sp.SAMPLE_RATE)), 0.75)) * sp.sin( song, 1. / 60.) sf.write('working/the_barron.wav', composition, int(sp.SAMPLE_RATE), 'FLOAT') play(composition)