Exemple #1
0
def messy_random_concat_test():
    s = WAV(african)

    max_length = 20e3

    def messy_track():
        t = 0
        temp = 0

        while temp < max_length:
            duration = 400 + np.random.random() * 3e3
            temp += duration
            start = 4e3 + (30 - 4) * np.random.random() * 1e3
            t |= s[start:start + duration]

        return t

    L = messy_track() + messy_track()
    R = messy_track() + messy_track()

    s = L * Repan(0, None) + R * Repan(None, 1)

    t = sum([(1 - 8 / 10) * s * Shift(duration=100 * x) *
             MovingAverage(width=2 * x + 1) for x in range(5)])
    t += 0.6 * s * Downsample(factor=5) * MovingAverage(width=5)

    audio = t.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #2
0
def dummy_reverb_test():
    #amp = lambda x:
    #wav = WAV(african) + WAV(african)*Amplitude(amp)*Shift(duration=500)
    #wav = WAV(african)*SineAM(frequency=0.12, size=0.25)
    #wav += WAV(african)*SineAM(frequency=0.12, size=0.25, phase=np.pi)*Shift(duration=500)*FIR(1,1,1,1,1,1,1,1,1)

    wav = sum([(1 - 8 / 10) * WAV(african) * Shift(duration=100 * x) *
               MovingAverage(2 * x + 1) for x in range(5)])
    wav += 0.6 * WAV(african) * Downsample(factor=5) * MovingAverage(5)

    audio = wav.mixdown(sample_rate=44100, byte_width=2)
    play_Audio(audio, is_wait=True)
Exemple #3
0
def repan_reverb_test():
    # TODO these aren't relevant for new pan
    wav = sum([
        (1 - 8 / 10) * WAV(african) * Shift(duration=100 * x) *
        MovingAverage(2 * x + 1) * Pan(*(1, 0.3)[::(1 if x % 2 == 0 else -1)])
        for x in range(5)
    ])
    wav += 0.6 * WAV(african) * Pan(
        0, None) * Downsample(factor=5) * MovingAverage(5)
    wav += 0.6 * WAV(african) * Pan(None, 1)

    audio = wav.mixdown(sample_rate=44100, byte_width=2)
    play_Audio(audio, is_wait=True)
Exemple #4
0
def chorale_example():
    sig = Triangle  # Square?

    beat = 0.5e3  # 120 bpm
    fermata = 0.1  # make fermatas in the melody slightly longer
    pause = 0.6  # and breathe for a moment before starting the next phrase

    s = sig(
        f"r D5 D=2 C#=1 B-13=2 A=1 D E=2 F#-13={2+fermata} r={pause} F#=1 F#=2 F#=1 E=2 F#-13=1 G F#-13=2 E={2+fermata} r={pause} "
        f"D+16=1 E=2 F#-13=1 E=2 D+16=1 B-13 C#=2 D+9={2+fermata} r={pause} A'=1 F#-13=2 D+16=1 E=2 G=1 F#-13 E=2 D=3",
        beat)
    a = sig(
        f"r A4 B-16=2 A+16=1 G=2 F#-13=1 F# B-13 A A={2+fermata} r={pause} C#=1 B=2 B=1 B A A A D A A={2+fermata} r={pause} "
        f"B=1 A=2 A=1 B-13 A=0.5 G F#=1 B-13 B A#-13 B={2+fermata} r={pause} A=1 A=2 B=1 A=2 A=1 A B-13 A F#-13=3",
        beat)
    t = sig(
        f"r F#4-13 F#=2 F#=1 D=2 D=1 D D C#-13 D={2+fermata} r={pause} C#=1 D+16=2 D+16=1 D C#-13 D E A, D C#-13={2+fermata} r={pause} "
        f"F#=1 E=2 D=1 D C#-13 D+16 D G+5 F# F#={2+fermata} r={pause} E=1 F#-13=2 F#=1 E=2 C#-13=1 A B C#-13 D=3",
        beat)
    b = sig(
        f"r D3 B-16 D F# G B-13 D B-16 G A D,={2+fermata} r={pause} A#'-13=1 B=2 A=1 G#-13 A F#-13 C#-13 D F#-13 A={2+fermata} r={pause} "
        f"B=1 C#-13=2 D=1 G, A B G E F# B,={2+fermata} r={pause} C#'-13=1 D C# B C#-13 B A D G, A D,=3",
        beat)

    chorale = s * Pan(25) + b * Pan(-25) + t * Pan(80) + a * Pan(-80)

    from gensound.filters import MovingAverage
    chorale *= MovingAverage(5)  #*Reverse()
    #export_test(chorale.mixdown(44100), chorale_example)
    chorale.play()  # can you spot the parallel octaves?
Exemple #5
0
def test_transform_chain():
    s = WAV(african)[10e3:20e3]
    t = MovingAverage(5) * Fade(duration=0.5e3)
    t *= Gain(Line(0, -10, 3e3) | Line(-10, 0, 5e3))
    s *= t
    audio = s.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #6
0
def slice_test():
    hihat = WAV(african)[:1061] * MovingAverage(5)
    hihat **= 30

    part = WAV(african)[5 * 1061:5 * 1061 + 3 * 1061]
    part **= 20
    s = WAV(african) + part * Shift(4 * 1061) * Gain(-6) - hihat
    #s = hihat
    audio = s.mixdown(sample_rate=32000, byte_width=2, max_amplitude=0.2)
    #play_Audio(audio)
    export_test(audio, slice_test)
Exemple #7
0
def t1():
    t = Triangle(frequency=midC(-1.5),
                 duration=5000) * MovingAverage(21) * SineAM(frequency=0.8,
                                                             size=0.3)

    env = lambda n: (n / 1000) if n < 1000 else (0.5 + np.sin(2 * np.pi * 2 * n
                                                              / 1000) / 2)
    env = lambda n: (0.5 + np.sin(2 * np.pi * 2 * n) / 2)
    env = lambda n: (0 if n == 0 else np.sin(n) * (min(n, 1)))
    env = lambda n: np.e**(-0.3 + 0.3 * (min(n, 0.3)) / 0.3)
    t += 0.01 * Sawtooth(frequency=midC(-1.5), duration=5000) * Amplitude(env)

    audio = t.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.01)
    play_Audio(audio)
Exemple #8
0
def test_ADSR():
    notes = [-3, -6, 1, 4, 3, -1, 1, 9, 8, 4, 6] * 2
    melody = Signal.concat(*[
        Square(frequency=midC(notes[i]), duration=0.5e3) * ADSR(attack=0.03e3,
                                                                decay=0.1e3,
                                                                sustain=0.8,
                                                                release=0.02e3,
                                                                hold=0.1e3)
        for i in range(len(notes))
    ])
    melody[1] = Signal.concat(*[
        Square(frequency=midC(notes[(i + 2) % (len(notes))]), duration=0.5e3) *
        ADSR(attack=0.03e3, decay=0.1e3, sustain=0.8, release=0.02e3, hold=0)
        for i in range(len(notes))
    ])
    melody *= MovingAverage(5)
    audio = melody.mixdown(sample_rate=24000, byte_width=2, max_amplitude=0.2)
    #play_Audio(audio)
    export_test(audio, test_ADSR)
Exemple #9
0
def after_test_3():
    b1 = 1.2e3
    b2 = 1e3
    b3 = 0.8e3
    b4 = 1.4e3

    p1 = [-6, -3, -8, -1, 1]
    p2 = [9, 4, 6, 8, 11]
    p3 = [12 + 1, 12 + 4, 12 + 6, 12 + 8, 12 + 1, 12 + 3, 12 + 11]
    p4 = [-12 + 2, -12 - 1, -12 + 1, -12 - 3]

    s = Signal.concat(*[Sine(midC(p), b1) for p in p1])**5
    s += 0.8 * Signal.concat(*[Sine(midC(p), b2) for p in p2])**6 * Shift(000)
    s += 0.3 * Signal.concat(*[Sine(midC(p), b3) for p in p3])**6
    s += 2 * Signal.concat(*[Sine(midC(p), b4) for p in p4])**5
    s *= MovingAverage(11)

    print(s)
    audio = s.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio, is_wait=False)
Exemple #10
0
def convolution_test():
    signal = WAV(african) * Convolution(
        forward=False, add=0.3, is_both_ways=False) * MovingAverage(11)
    signal -= 0.1 * WAV(african)
    audio = signal.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio, is_wait=True)
Exemple #11
0
def reverse_test():
    wav = WAV(african) * Reverse() * Downsample(factor=5) * MovingAverage(5)
    wav += WAV(african) * Shift(duration=150) * FIR(1, 1, 1, 1, 1, 1, 1, 1, 1)

    audio = wav.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.09)
    play_Audio(audio, is_wait=True)