Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def demo_song():
    synth = WaveSynth()
    notes = {note: key_freq(49+i) for i, note in enumerate(['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#'])}
    tempo = 0.3

    def instrument(freq, duration):
        harmonics = [(1, 1), (2, 1/2), (4, 1/4), (6, 1/6)]
        a = synth.harmonics(freq, duration, harmonics)
        return a.envelope(0.05, 0.2, 0.8, 0.5)

    print("Synthesizing tones...")
    quarter_notes = {note: instrument(notes[note], tempo) for note in notes}
    half_notes = {note: instrument(notes[note], tempo*2) for note in notes}
    full_notes = {note: instrument(notes[note], tempo*4) for note in notes}
    song = "A A B. A D. C#.. ;  A A B. A E. D.. ;  A A A. F#.. D C#.. B ;  G G F#.. D E D ; ; "\
        "A A B. A D C#.. ; A A B. A E D. ; A A A. F#.. D C#.. B ; G G F#.. D E D ; ; "
    with Output(synth.samplerate, synth.samplewidth, 1) as out:
        for note in song.split():
            if note == ";":
                print()
                time.sleep(tempo*2)
                continue
            print(note, end="  ", flush=True)
            if note.endswith(".."):
                sample = full_notes[note[:-2]]
            elif note.endswith("."):
                sample = half_notes[note[:-1]]
            else:
                sample = quarter_notes[note]
            out.play_sample(sample)
        print()
Ejemplo n.º 4
0
def demo_song():
    synth = WaveSynth()
    notes = {
        note: key_freq(49 + i)
        for i, note in enumerate(
            ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#'])
    }
    tempo = 0.3

    def instrument(freq, duration):
        harmonics = [(1, 1), (2, 1 / 2), (4, 1 / 4), (6, 1 / 6)]
        a = synth.harmonics(freq, duration, harmonics)
        return a.envelope(0.05, 0.2, 0.8, 0.5)

    print("Synthesizing tones...")
    quarter_notes = {note: instrument(notes[note], tempo) for note in notes}
    half_notes = {note: instrument(notes[note], tempo * 2) for note in notes}
    full_notes = {note: instrument(notes[note], tempo * 4) for note in notes}
    song = "A A B. A D. C#.. ;  A A B. A E. D.. ;  A A A. F#.. D C#.. B ;  G G F#.. D E D ; ; "\
        "A A B. A D C#.. ; A A B. A E D. ; A A A. F#.. D C#.. B ; G G F#.. D E D ; ; "
    with Output(synth.samplerate, synth.samplewidth, 1) as out:
        for note in song.split():
            if note == ";":
                print()
                time.sleep(tempo * 2)
                continue
            print(note, end="  ", flush=True)
            if note.endswith(".."):
                sample = full_notes[note[:-2]]
            elif note.endswith("."):
                sample = half_notes[note[:-1]]
            else:
                sample = quarter_notes[note]
            out.play_sample(sample)
        print()
Ejemplo n.º 5
0
import time
from collections import OrderedDict
from synthesizer.sample import Sample
from synthesizer.playback import Output
from synthesizer.synth import WaveSynth, key_freq, octave_notes, major_chord_keys, note_freq, key_num
from synthesizer.synth import Sine, Triangle, Pulse, Square, SquareH, Sawtooth, SawtoothH, WhiteNoise, Linear, Harmonics
from synthesizer.synth import FastSine, FastPulse, FastSawtooth, FastSquare, FastTriangle
from synthesizer.synth import EchoFilter, EnvelopeFilter, AbsFilter, ClipFilter, DelayFilter

# some note frequencies for octaves 1 to 7
notes = [
    None,
    OrderedDict(
        (note, key_freq(4 + i)) for i, note in enumerate(octave_notes)),
    OrderedDict(
        (note, key_freq(16 + i)) for i, note in enumerate(octave_notes)),
    OrderedDict(
        (note, key_freq(28 + i)) for i, note in enumerate(octave_notes)),
    OrderedDict(
        (note, key_freq(40 + i)) for i, note in enumerate(octave_notes)),
    OrderedDict(
        (note, key_freq(52 + i)) for i, note in enumerate(octave_notes)),
    OrderedDict(
        (note, key_freq(64 + i)) for i, note in enumerate(octave_notes)),
    OrderedDict(
        (note, key_freq(76 + i)) for i, note in enumerate(octave_notes))
]


def demo_tones():
    synth = WaveSynth()
Ejemplo n.º 6
0
import time
from collections import OrderedDict
from synthesizer.sample import Output, Sample
from synthesizer.synth import WaveSynth, key_freq, octave_notes, major_chord_keys, note_freq, key_num
from synthesizer.synth import Sine, Triangle, Pulse, Square, SquareH, Sawtooth, SawtoothH, WhiteNoise, Linear, Harmonics
from synthesizer.synth import FastSine, FastPulse, FastSawtooth, FastSquare, FastTriangle
from synthesizer.synth import EchoFilter, EnvelopeFilter, AbsFilter, ClipFilter, DelayFilter


# some note frequencies for octaves 1 to 7
notes = [
    None,
    OrderedDict((note, key_freq(4+i)) for i, note in enumerate(octave_notes)),
    OrderedDict((note, key_freq(16+i)) for i, note in enumerate(octave_notes)),
    OrderedDict((note, key_freq(28+i)) for i, note in enumerate(octave_notes)),
    OrderedDict((note, key_freq(40+i)) for i, note in enumerate(octave_notes)),
    OrderedDict((note, key_freq(52+i)) for i, note in enumerate(octave_notes)),
    OrderedDict((note, key_freq(64+i)) for i, note in enumerate(octave_notes)),
    OrderedDict((note, key_freq(76+i)) for i, note in enumerate(octave_notes))
]


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)