예제 #1
0
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()
예제 #2
0
def pwm():
    from matplotlib import pyplot as plot
    synth = WaveSynth(samplerate=1000)
    pwm_lfo = Sine(0.05, amplitude=0.49, bias=0.5, samplerate=synth.samplerate)
    s1 = synth.pulse(4, amplitude=0.6, duration=20, pwm_lfo=pwm_lfo)
    plot.figure(figsize=(16, 4))
    plot.title("Pulse width modulation")
    plot.ylim([-35000, 35000])
    plot.plot(s1.get_frame_array())
    plot.show()
    with Output(nchannels=1) as out:
        synth = WaveSynth()
        lfo2 = Sine(0.2, amplitude=0.48, bias=0.5)
        s1 = synth.pulse(440/6, amplitude=0.5, duration=6, fm_lfo=None, pwm_lfo=lfo2)
        out.play_sample(s1)
        # s1.write_wav("pwmtest.wav")
        out.wait_all_played()
예제 #3
0
def lfo_func():
    rate = 1000
    s = Sine(1, amplitude=100, bias=40, samplerate=rate)
    s = AbsFilter(s)
    s = ClipFilter(s, minimum=20, maximum=80)
    s = DelayFilter(s, 0.5)
    s = list(itertools.islice(s, rate*2))
    import matplotlib.pyplot as plot
    a = plot.subplot(111)
    a.set_ylim([-50, 100])
    a.plot(s)
    plot.show()
예제 #4
0
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()
예제 #5
0
 def filter(self, source):
     wave = self.input_waveform.get()
     freq = self.input_rate.get()
     amp = self.input_depth.get() / 2.0
     samplerate = self.gui.synth.samplerate
     bias = 1.0 - amp
     if amp == 0.0 or freq == 0.0 or wave in (None, "", "<none>", "<off>"):
         return source
     if wave == "sine":
         modulator = Sine(freq, amp, bias=bias, samplerate=samplerate)
     elif wave == "triangle":
         modulator = Triangle(freq, amp, bias=bias, samplerate=samplerate)
     elif wave == "sawtooth":
         modulator = SawtoothH(freq, 9, amp, bias=bias, samplerate=samplerate)
     elif wave == "square":
         modulator = SquareH(freq, 9, amp, bias=bias, samplerate=samplerate)
     return AmpModulationFilter(source, modulator)
예제 #6
0
def lfo_func():
    rate = 1000
    s = Sine(1, amplitude=100, bias=40, samplerate=rate)
    s = AbsFilter(s)
    s = ClipFilter(s, minimum=20, maximum=80)
    s = DelayFilter(s, 0.5)
    s = list(itertools.islice(s.blocks(), math.ceil(rate*2/params.norm_osc_blocksize)))
    import matplotlib.pyplot as plot
    a = plot.subplot(111)
    a.set_ylim([-50, 100])
    a.plot(sum(s, []))
    plot.show()
예제 #7
0
def modulate_amp():
    from matplotlib import pyplot as plot
    synth = WaveSynth()
    freq = 220
    s1 = synth.triangle(freq, duration=2)
    m = synth.sine(2, duration=2, amplitude=0.4, bias=0.5)
    s1.modulate_amp(m)
    plot.title("Amplitude modulation by another waveform")
    plot.plot(s1.get_frame_array())
    plot.show()
    with Output(nchannels=1) as out:
        out.play_sample(s1)
        out.wait_all_played()
    s1 = synth.triangle(freq, duration=2)
    m = Sine(3, amplitude=0.4, bias=0.5)
    s1.modulate_amp(m)
    plot.title("Amplitude modulation by an oscillator")
    plot.plot(s1.get_frame_array())
    plot.show()
    with Output(nchannels=1) as out:
        out.play_sample(s1)
        out.wait_all_played()
예제 #8
0
def fm():
    synth = WaveSynth(samplerate=8000)
    from matplotlib import pyplot as plot
    freq = 2000
    lfo1 = Sine(1, amplitude=0.4, samplerate=synth.samplerate)
    s1 = synth.sine(freq, duration=3, fm_lfo=lfo1)
    plot.title("Spectrogram")
    plot.ylabel("Freq")
    plot.xlabel("Time")
    plot.specgram(s1.get_frame_array(), Fs=synth.samplerate, noverlap=90, cmap=plot.cm.gist_heat)
    plot.show()
    with Output(nchannels=1, mixing="sequential") as out:
        synth = WaveSynth()
        freq = 440
        lfo1 = Linear(5, samplerate=synth.samplerate)
        lfo1 = EnvelopeFilter(lfo1, 1, 0.5, 0.5, 0.5, 1)
        s1 = synth.sine(freq, duration=3, fm_lfo=lfo1)
        s_all = s1.copy()
        out.play_sample(s1)
        lfo1 = Sine(1, amplitude=0.2, samplerate=synth.samplerate)
        s1 = synth.sine(freq, duration=2, fm_lfo=lfo1)
        s_all.join(s1)
        out.play_sample(s1)
        lfo1 = Sine(freq/17, amplitude=0.5, samplerate=synth.samplerate)
        s1 = synth.sine(freq, duration=2, fm_lfo=lfo1)
        s_all.join(s1)
        out.play_sample(s1)
        lfo1 = Sine(freq/6, amplitude=0.5, samplerate=synth.samplerate)
        s1 = synth.sine(freq, duration=2, fm_lfo=lfo1)
        s_all.join(s1)
        out.play_sample(s1)
        lfo1 = Sine(1, amplitude=0.4, samplerate=synth.samplerate)
        s1 = synth.triangle(freq, duration=2, fm_lfo=lfo1)
        s_all.join(s1)
        out.play_sample(s1)
        freq = 440*2
        lfo1 = Sine(freq/80, amplitude=0.4, samplerate=synth.samplerate)
        s1 = synth.triangle(freq, duration=2, fm_lfo=lfo1)
        s_all.join(s1)
        out.play_sample(s1)
        # s_all.write_wav("fmtestall.wav")
        out.wait_all_played()
예제 #9
0
 def make_sample(freq):
     fmfm = Linear(0, 0.002, max_value=99999)
     fm = Sine(0.05, amplitude=0.5, fm_lfo=fmfm)
     s1 = synth.sawtooth(freq, duration, amplitude=0.6, fm_lfo=fm)
     s1.envelope(0.01, 0.1, 0.6, 2)
     return s1
예제 #10
0
def osc_bench():
    rate = 44100
    duration = 2.0

    def get_values(osc):
        values = list(itertools.islice(osc.blocks(), int(rate*duration/params.norm_osc_blocksize)))

    fm = FastSine(220)
    print("GENERATING {:g} SECONDS SAMPLE DATA {:d} HZ USING LFO.".format(duration, rate))
    print("  WAVEFORM: with-FM / no-FM / optimized")
    # sine
    print("      Sine:   ", end="")
    start = time.time()
    get_values(Sine(440, fm_lfo=fm))
    duration1 = time.time()-start
    start = time.time()
    get_values(Sine(440))
    duration2 = time.time()-start
    start = time.time()
    get_values(FastSine(440))
    duration3 = time.time()-start
    print("{:.3f} / {:.3f} / {:.3f}".format(duration1, duration2, duration3))
    # triangle
    print("  Triangle:   ", end="")
    start = time.time()
    get_values(Triangle(440, fm_lfo=fm))
    duration1 = time.time()-start
    start = time.time()
    get_values(Triangle(440))
    duration2 = time.time()-start
    start = time.time()
    get_values(FastTriangle(440))
    duration3 = time.time()-start
    print("{:.3f} / {:.3f} / {:.3f}".format(duration1, duration2, duration3))
    # square
    print("    Square:   ", end="")
    start = time.time()
    get_values(Square(440, fm_lfo=fm))
    duration1 = time.time()-start
    start = time.time()
    get_values(Square(440))
    duration2 = time.time()-start
    start = time.time()
    get_values(FastSquare(440))
    duration3 = time.time()-start
    print("{:.3f} / {:.3f} / {:.3f}".format(duration1, duration2, duration3))
    # sawtooth
    print("  Sawtooth:   ", end="")
    start = time.time()
    get_values(Sawtooth(440, fm_lfo=fm))
    duration1 = time.time()-start
    start = time.time()
    get_values(Sawtooth(440))
    duration2 = time.time()-start
    start = time.time()
    get_values(FastSawtooth(440))
    duration3 = time.time()-start
    print("{:.3f} / {:.3f} / {:.3f}".format(duration1, duration2, duration3))
    # pulse
    print("     Pulse:   ", end="")
    start = time.time()
    get_values(Pulse(440, fm_lfo=fm))
    duration1 = time.time()-start
    start = time.time()
    get_values(Pulse(440))
    duration2 = time.time()-start
    start = time.time()
    get_values(FastPulse(440))
    duration3 = time.time()-start
    print("{:.3f} / {:.3f} / {:.3f}".format(duration1, duration2, duration3))
    # square_h
    print("  Square_H:   ", end="")
    start = time.time()
    get_values(SquareH(440, fm_lfo=fm))
    duration1 = time.time()-start
    start = time.time()
    get_values(SquareH(440))
    duration2 = time.time()-start
    print("{:.3f} / {:.3f}".format(duration1, duration2))
    print("Sawtooth_H:   ", end="")
    start = time.time()
    get_values(SawtoothH(440, fm_lfo=fm))
    duration1 = time.time()-start
    start = time.time()
    get_values(SawtoothH(440))
    duration2 = time.time()-start
    print("{:.3f} / {:.3f}".format(duration1, duration2))
    print("     Noise:   ", end="")
    start = time.time()
    get_values(WhiteNoise(5000))
    duration1 = time.time()-start
    print("        {:.3f}".format(duration1))
    print("    Linear:   ", end="")
    start = time.time()
    get_values(Linear(0, 0.0001))
    duration1 = time.time()-start
    print("        {:.3f}".format(duration1))