Beispiel #1
0
 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)
Beispiel #2
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()
Beispiel #3
0
def chords():
    synth = WaveSynth()
    with Output(nchannels=1, mixing="sequential", queue_size=1) as out:
        for rootnote in octave_notes:
            chord_keys = major_chord_keys(rootnote, 4)
            print("chord", rootnote, ["{0} {1}".format(note, octave) for note, octave in chord_keys])
            freqs = [notes[octave][key] for key, octave in chord_keys]
            for i in range(1, len(freqs)):
                assert freqs[i] > freqs[i-1]
            samples = [synth.sine(freq, 1.5, amplitude=0.333) for freq in freqs]
            s = samples[0].mix(samples[1]).mix(samples[2]).fadein(0.1).fadeout(0.1)
            out.play_sample(s)
        out.wait_all_played()
Beispiel #4
0
def bias():
    from matplotlib import pyplot as plot
    synth = WaveSynth(samplerate=1000)
    waves = [synth.sine(2, 4, 0.02, bias=0.1),
             synth.triangle(2, 4, 0.02, bias=0.2),
             synth.pulse(2, 4, 0.02, bias=0.3, pulsewidth=0.45),
             synth.harmonics(2, 4, [(n, 1 / n) for n in range(1, 8)], 0.02, bias=0.4),
             synth.sawtooth(2, 4, 0.02, bias=0.5),
             synth.sawtooth_h(2, 4, 7, 0.02, bias=0.6),
             synth.square(2, 4, 0.02, bias=0.7),
             synth.square_h(2, 4, 7, 0.02, bias=0.8),
             synth.white_noise(frequency=100, duration=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()
Beispiel #5
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()
Beispiel #6
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()
Beispiel #7
0
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()