def bells(): def makebell(freq): synth = WaveSynth() duration = 2 divider = 2.2823535 fm = Triangle(freq/divider, amplitude=0.5) s = synth.sine(freq, duration, fm_lfo=fm) # apply ADSR envelope that resembles bell amp curve, see http://www.hibberts.co.uk/make.htm s.envelope(0, duration*0.25, .5, duration*0.75) s.echo(2, 5, 0.06, 0.6) return s.make_32bit(False) b_l1 = makebell(key_freq(56)) b_l2 = makebell(key_freq(60)) b_h1 = makebell(key_freq(78)).amplify(0.7) b_h2 = makebell(key_freq(82)).amplify(0.7) b_h3 = makebell(key_freq(84)).amplify(0.7) bells = b_l1.mix_at(1.0, b_h1) bells.mix_at(1.5, b_h2) bells.mix_at(2, b_h3) bells.mix_at(3, b_l2) bells.mix_at(4, b_h2) bells.mix_at(4.5, b_h3) bells.mix_at(5, b_h1) bells.make_16bit() with Output.for_sample(bells) as out: out.play_sample(bells) out.wait_all_played()
def stereo_pan(): synth = WaveSynth() # panning a stereo source: wave = Sample("samples/SOS 020.wav").clip(6, 12).normalize().fadein(0.5).fadeout(0.5).lock() osc = Sine(0.4) panning = wave.copy().pan(lfo=osc).fadeout(0.2) with Output.for_sample(panning) as out: out.play_sample(panning) out.wait_all_played() # panning a generated mono source: fm = Sine(0.5, 0.1999, bias=0.2) wave = synth.triangle(220, 5, fm_lfo=fm).lock() osc = Sine(0.4) panning = wave.copy().pan(lfo=osc).fadeout(0.2) with Output.for_sample(panning) as out: out.play_sample(panning) out.wait_all_played()
def echo_lfo(): synth = WaveSynth(22050) s = Sine(440, amplitude=25000, samplerate=synth.samplerate) s = EnvelopeFilter(s, .2, .2, 0, 0, 1.5, stop_at_end=True) s = EchoFilter(s, .15, 5, 0.3, 0.6) s = ClipFilter(s, -32000, 32000) frames = [int(v) for v in s] import matplotlib.pyplot as plot plot.plot(frames) plot.show() samp = Sample.from_array(frames, synth.samplerate, 1) with Output.for_sample(samp) as out: out.play_sample(samp) out.wait_all_played()
def a440(): synth = WaveSynth(samplerate=44100, samplewidth=4) a440 = synth.sine(440, duration=2) with Output.for_sample(a440) as out: out.play_sample(a440) out.wait_all_played()
print("but you cannot mix any sounds. It's ideal for playback of a single sound source,") print("such as an audio clip or audio stream that comes in chunks.") out.play_sample(s1) out.play_sample(s2) out.play_sample(s3) out.play_sample(s4) out.play_sample(s5) out.play_sample(s5) out.play_sample(s5) out.play_sample(s6) print("\nwaiting till all sounds have played...") out.wait_all_played() print("\nEnter to continue:") input() with Output.for_sample(s1, mixing="mix") as out: if not out.supports_streaming: raise RuntimeError("need api that supports streaming") print("\nUsing time.sleep to time sounds.") sid6 = out.play_sample(s6_soft, repeat=True) out.play_sample(s1) time.sleep(0.5) out.play_sample(s2) time.sleep(0.5) out.play_sample(s3) time.sleep(0.5) out.play_sample(s4) time.sleep(0.3) out.play_sample(s5) time.sleep(0.3)