示例#1
0
def demo_tones():
    synth = WaveSynth()
    with Output(nchannels=1) as out:
        for wave in [
                synth.square_h, synth.square, synth.sine, synth.triangle,
                synth.sawtooth, synth.sawtooth_h
        ]:
            print(wave.__name__)
            for note, freq in list(notes[4].items())[6:]:
                print("   {:f} hz".format(freq))
                sample = wave(freq, duration=0.4).fadein(0.02).fadeout(0.1)
                out.play_sample(sample)
        print("pulse")
        for note, freq in list(notes[4].items())[6:]:
            print("   {:f} hz".format(freq))
            sample = synth.pulse(freq, duration=0.4,
                                 pulsewidth=0.1).fadein(0.02).fadeout(0.1)
            out.play_sample(sample)
        print("harmonics (only even)")
        for note, freq in list(notes[3].items())[6:]:
            print("   {:f} hz".format(freq))
            harmonics = [(n, 1 / n) for n in range(1, 5 * 2, 2)]
            sample = synth.harmonics(freq, 0.4,
                                     harmonics).fadein(0.02).fadeout(0.1)
            out.play_sample(sample)
        print("noise")
        sample = synth.white_noise(duration=1.5).fadein(0.1).fadeout(0.1)
        out.play_sample(sample)
示例#2
0
def harmonics():
    synth = WaveSynth()
    freq = 1500
    num_harmonics = 6
    h_all = synth.harmonics(freq, 1, [(n, 1/n) for n in range(1, num_harmonics+1)])
    even_harmonics = [(1, 1)]  # always include fundamental tone harmonic
    even_harmonics.extend([(n, 1/n) for n in range(2, num_harmonics*2, 2)])
    h_even = synth.harmonics(freq, 1, even_harmonics)
    h_odd = synth.harmonics(freq, 1, [(n, 1/n) for n in range(1, num_harmonics*2, 2)])
    h_all.join(h_even).join(h_odd)
    import matplotlib.pyplot as plot
    plot.title("Spectrogram")
    plot.ylabel("Freq")
    plot.xlabel("Time")
    plot.specgram(h_all.get_frame_array(), Fs=synth.samplerate, noverlap=90, cmap=plot.cm.gist_heat)
    plot.show()
示例#3
0
def harmonics():
    synth = WaveSynth()
    freq = 1500
    num_harmonics = 6
    h_all = synth.harmonics(freq, 1,
                            [(n, 1 / n) for n in range(1, num_harmonics + 1)])
    even_harmonics = [(1, 1)]  # always include fundamental tone harmonic
    even_harmonics.extend([(n, 1 / n) for n in range(2, num_harmonics * 2, 2)])
    h_even = synth.harmonics(freq, 1, even_harmonics)
    h_odd = synth.harmonics(freq, 1, [(n, 1 / n)
                                      for n in range(1, num_harmonics * 2, 2)])
    h_all.join(h_even).join(h_odd)
    import matplotlib.pyplot as plot
    plot.title("Spectrogram")
    plot.ylabel("Freq")
    plot.xlabel("Time")
    plot.specgram(h_all.get_frame_array(),
                  Fs=synth.samplerate,
                  noverlap=90,
                  cmap=plot.cm.gist_heat)
    plot.show()
示例#4
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()
示例#5
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()
示例#6
0
def demo_tones():
    synth = WaveSynth()
    with Output(nchannels=1) as out:
        for wave in [synth.square_h, synth.square, synth.sine, synth.triangle, synth.sawtooth, synth.sawtooth_h]:
            print(wave.__name__)
            for note, freq in list(notes[4].items())[6:]:
                print("   {:f} hz".format(freq))
                sample = wave(freq, duration=0.4).fadein(0.02).fadeout(0.1)
                out.play_sample(sample)
        print("pulse")
        for note, freq in list(notes[4].items())[6:]:
            print("   {:f} hz".format(freq))
            sample = synth.pulse(freq, duration=0.4, pulsewidth=0.1).fadein(0.02).fadeout(0.1)
            out.play_sample(sample)
        print("harmonics (only even)")
        for note, freq in list(notes[3].items())[6:]:
            print("   {:f} hz".format(freq))
            harmonics = [(n, 1/n) for n in range(1, 5*2, 2)]
            sample = synth.harmonics(freq, 0.4, harmonics).fadein(0.02).fadeout(0.1)
            out.play_sample(sample)
        print("noise")
        sample = synth.white_noise(duration=1.5).fadein(0.1).fadeout(0.1)
        out.play_sample(sample)