예제 #1
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, samplerate=22050) as out:
        synth = WaveSynth(samplerate=22050)
        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)
예제 #2
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)
    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)
예제 #3
0
def envelope():
    from matplotlib import pyplot as plot
    synth = WaveSynth()
    freq = 440
    s = synth.triangle(freq, duration=1)
    s.envelope(0.05, 0.1, 0.6, 0.4)
    plot.title("ADSR envelope")
    plot.plot(s.get_frame_array())
    plot.show()
    with Output(nchannels=1) as out:
        out.play_sample(s)
예제 #4
0
def envelope():
    from matplotlib import pyplot as plot
    synth = WaveSynth()
    freq = 440
    s = synth.triangle(freq, duration=1)
    s.envelope(0.05, 0.1, 0.6, 0.4)
    plot.title("ADSR envelope")
    plot.plot(s.get_frame_array())
    plot.show()
    with Output(nchannels=1) as out:
        out.play_sample(s)
예제 #5
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)
    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)
예제 #6
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, samplerate=22050) as out:
        synth = WaveSynth(samplerate=22050)
        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)
예제 #7
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)
    # 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)
예제 #8
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)
    # 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)
예제 #9
0
def bias():
    from matplotlib import pyplot as plot
    synth = WaveSynth(samplerate=1000)
    waves = []
    waves.append(synth.sine(2, 4, 0.02, bias=0.1))
    waves.append(synth.triangle(2, 4, 0.02, bias=0.2))
    waves.append(synth.pulse(2, 4, 0.02, bias=0.3, pulsewidth=0.45))
    waves.append(synth.harmonics(2, 4, [(n, 1/n) for n in range(1, 8)], 0.02, bias=0.4))
    waves.append(synth.sawtooth(2, 4, 0.02, bias=0.5))
    waves.append(synth.sawtooth_h(2, 4, 7, 0.02, bias=0.6))
    waves.append(synth.square(2, 4, 0.02, bias=0.7))
    waves.append(synth.square_h(2, 4, 7, 0.02, bias=0.8))
    waves.append(synth.white_noise(4, amplitude=0.02, bias=0.9))
    for wave in waves:
        plot.plot(wave.get_frame_array())
    plot.title("All waveforms biased to levels above zero")
    plot.show()
예제 #10
0
def demo_plot():
    from matplotlib import pyplot as plot
    plot.title("Various waveforms")
    synth = WaveSynth(samplerate=1000)
    freq = 4
    s = synth.sawtooth(freq, duration=1)
    plot.plot(s.get_frame_array())
    s = synth.sine(freq, duration=1)
    plot.plot(s.get_frame_array())
    s = synth.triangle(freq, duration=1)
    plot.plot(s.get_frame_array())
    s = synth.square(freq, duration=1)
    plot.plot(s.get_frame_array())
    s = synth.square_h(freq, duration=1)
    plot.plot(s.get_frame_array())
    s = synth.pulse(freq, duration=1, pulsewidth=0.2)
    plot.plot(s.get_frame_array())
    plot.show()
예제 #11
0
def demo_plot():
    from matplotlib import pyplot as plot
    plot.title("Various waveforms")
    synth = WaveSynth(samplerate=1000)
    freq = 4
    s = synth.sawtooth(freq, duration=1)
    plot.plot(s.get_frame_array())
    s = synth.sine(freq, duration=1)
    plot.plot(s.get_frame_array())
    s = synth.triangle(freq, duration=1)
    plot.plot(s.get_frame_array())
    s = synth.square(freq, duration=1)
    plot.plot(s.get_frame_array())
    s = synth.square_h(freq, duration=1)
    plot.plot(s.get_frame_array())
    s = synth.pulse(freq, duration=1, pulsewidth=0.2)
    plot.plot(s.get_frame_array())
    plot.show()
예제 #12
0
def bias():
    from matplotlib import pyplot as plot
    synth = WaveSynth(samplerate=1000)
    waves = []
    waves.append(synth.sine(2, 4, 0.02, bias=0.1))
    waves.append(synth.triangle(2, 4, 0.02, bias=0.2))
    waves.append(synth.pulse(2, 4, 0.02, bias=0.3, pulsewidth=0.45))
    waves.append(
        synth.harmonics(2,
                        4, [(n, 1 / n) for n in range(1, 8)],
                        0.02,
                        bias=0.4))
    waves.append(synth.sawtooth(2, 4, 0.02, bias=0.5))
    waves.append(synth.sawtooth_h(2, 4, 7, 0.02, bias=0.6))
    waves.append(synth.square(2, 4, 0.02, bias=0.7))
    waves.append(synth.square_h(2, 4, 7, 0.02, bias=0.8))
    waves.append(synth.white_noise(4, amplitude=0.02, bias=0.9))
    for wave in waves:
        plot.plot(wave.get_frame_array())
    plot.title("All waveforms biased to levels above zero")
    plot.show()