Exemple #1
0
def test_reverse_channels():
    s = WAV(african)[15e3:25e3]
    s[0] += (WAV(african)[15e3:35e3:2] * Gain(-6))[1]
    s[1] += (WAV(african)[15e3:45e3:3] * Gain(-6))[0]
    s = s[1::-1]
    audio = s.mixdown(sample_rate=24000, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #2
0
def test_to_mono():
    s = WAV(african)[15e3:25e3]
    ### s = sum(s) # raises error - we do not know how many channels there are
    s = s[0] + s[1]  # use this
    #s *= Mono() # or this
    audio = s.mixdown(sample_rate=24000, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #3
0
def log_amp_test():
    # tests logarithmic scaling of amplitude factors
    signal = WAV(african) * Repan(0, None)  #switch L/R
    signal += 0.125 * WAV(african) * Repan(None, 1)
    audio = signal.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.5)
    play_Audio(audio, is_wait=True)
    pass
Exemple #4
0
def test_amplitude_param():
    s = WAV(african)[15e3:25e3]
    c1 = Constant(1, 3e3) | Line(1, 0.01, duration=7e3)
    c2 = SineCurve(frequency=3, depth=0.3, baseline=0.7, duration=10e3)
    s *= Amplitude(c1, c2)
    audio = s.mixdown(sample_rate=24000, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #5
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 #6
0
def test_gain_dB():
    s = Signal()

    for i in range(10):
        s |= Sine(duration=1e3) * Gain(-6 * i)

    audio = s.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #7
0
def test_gain_param():
    s = WAV(african)[15e3:28e3]
    c1 = Line(-80, 0, duration=8e3)
    c2 = Line(-40, -6, duration=4e3)
    s *= Gain(c1, c2)
    s[1, 4e3:] *= Gain(-6)
    audio = s.mixdown(sample_rate=24000, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #8
0
def curve_continuity_test():
    c = Line(220, 330, 4e3) | Constant(330, 4e3)
    s = Sine(frequency=c, duration=8e3)

    c2 = Constant(220, 2e3) | Line(220, 330, 9e3) | Constant(330, 2e3)
    s = Sine(frequency=c2, duration=18e3)
    audio = s.mixdown(sample_rate=11025, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #9
0
def step_test():
    times = (1, 3)

    t = sum([Step() * Shift(duration=time * 1000)
             for time in times]) * Extend(1000)
    #t = Step(1)
    audio = t.mixdown(sample_rate=11025, byte_width=2)
    play_Audio(audio)
Exemple #10
0
def after_test_1():
    signal = Sine(frequency=midC(-7), duration=6e3)
    s2 = Signal.concat(
        *[Sine(frequency=midC(k - 4), duration=1e3) for k in range(6)])
    signal += s2

    print(signal)
    audio = signal.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio, is_wait=True)
Exemple #11
0
def cancellation_test():
    #signal = Sine(duration=5000) - 0.999*Sine(duration=5000)
    #signal += 0.01*Sine(frequency=130,duration=1000)
    signal = WAV(african) - WAV(african) * Repan(1, 0)
    #signal += 0.5*WAV(african) # basically neautralized the center "channel"
    #signal += 5.0*WAV(african) # strengthens center

    audio = signal.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio, is_wait=True)
Exemple #12
0
def concat_overload_test():
    #s = Sine(frequency=250, duration=2e3) | Triangle(frequency=300, duration=3e3)
    s = WAV(african)

    s = s[5e3:5.5e3] | s[6e3:6.8e3] | s[11e3:13e3] * Reverse() + Sine(
        frequency=300, duration=2e3) | s[9e3:10.8e3]

    audio = s.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #13
0
def after_test_2():
    # test ** as repeat
    s = Signal.concat(Sine(midC(-7 + 12), 1e3), Sine(midC(-3), 1e3),
                      Sine(midC(-8 + 12), 1e3), Sine(midC(-1), 1e3))
    s **= 5
    s += WAV(african)

    print(s)
    audio = s.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio, is_wait=True)
Exemple #14
0
def pan_stereo_test():
    s = WAV(african)[10e3:30e3]
    t = s[0] * Pan(Line(-100, 50, 20e3)) + s[1] * Pan(Line(0, 100, 20e3))

    # stereo signal panned in space from (-100,0) to (50,100)
    # the stereo field moves right gradually as well as expanding
    # from an opening of 90 degrees to 45 degrees (with headphones)
    Pan.panLaw = -3
    audio = t.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #15
0
def envelope_test():
    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**(-3 + 3 * (min(n, 3)) / 3)
    wav = Sine(duration=5000) * Amplitude(env)

    audio = wav.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.03)
    play_Audio(audio, is_wait=True)
Exemple #16
0
def melody_test():
    step = 500
    notes = (midC(0), midC(-3), midC(-7), midC(4), midC(7), midC(-1), midC(2))
    t = sum([
        Sine(frequency=f, duration=step + 100) *
        Fade(is_in=True, duration=step * 5) *
        Fade(is_in=False, duration=step + 100) * Shift(duration=(1 + i) * step)
        for (i, f) in enumerate(notes)
    ])
    audio = t.mixdown(sample_rate=11025, byte_width=2)
    play_Audio(audio)
Exemple #17
0
def simple_test(f=220, seconds=5):
    t = 0.7 * Sine(frequency=230, duration=seconds * 1000) * SineAM(
        frequency=1, size=0.2)[0:2]
    t[1] += Triangle(frequency=380, duration=seconds * 1000) * SineAM(
        frequency=0.4, size=0.3)
    t[0] += Square(frequency=300, duration=seconds * 1000) * SineAM(
        frequency=0.7, size=0.2)
    t *= Fade(is_in=True, duration=3 * 1000)
    #t *= Fade(is_in=False, duration=20)
    t *= Shift(duration=1 * 1000)
    play_Audio(t.mixdown())
Exemple #18
0
def averagesample_test(filename):
    wav = WAV(filename)
    #wav *= FIR(5,4,3,2,1,2,3,4,5)
    wav *= FIR(1, 1, 1, 1, 1, 1, 1, 1, 1)
    #wav *= FIR(25,16,9,4,1,4,9,16,25)
    #wav *= FIR(1,0,0,0,0,0,0,0,1)
    #wav *= FIR(1,-1,1,-1,1,-1,1,-1,1)
    #wav *= FIR(-1,-1,-1,-1,10,-1,-1,-1,-1) # high pass!
    audio = wav.mixdown(sample_rate=44100, byte_width=2)

    play_Audio(audio, is_wait=True)
Exemple #19
0
def slice_set_test():
    s = WAV(african)
    # careful with 5e3, creates float slices

    #s[5e3:18e3] = s[5e3:18e3]*Repan() + s[5e3:18e3]*Downsample(5)*Gain(-3)
    #s[5e3:18e3] *= Repan(1,0)
    s[5e3:18e3] = s[5e3:18e3] * Repan(1, None) + s[5e3:18e3] * Repan(None, 0)
    # TODO found a bug here? does it really keep both copies of the slice separate?
    # also test s = s[0:50] & sine() & s[50:100]

    audio = s.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #20
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 #21
0
def concat_scalar_test():
    s = WAV(african)

    gap = 0.03
    L = s[10e3:11e3] | gap | s[11e3:12e3] | gap | s[12e3:13e3] | gap | s[13e3:14e3] \
        | gap | s[14e3:15e3] | gap | s[15e3:16e3] | gap | s[16e3:24e3]
    R = s[10e3:18e3] | gap | s[18e3:19e3] | gap | s[19e3:20e3] | gap | s[20e3:21e3] \
        | gap | s[21e3:24e3]

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

    audio = s.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #22
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 #23
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 #24
0
def pan_test():
    seconds = 10
    t = Sine(frequency=230,
             duration=seconds * 1000)[0:2]  #*SineAM(frequency=1, size=0.2)

    top = seconds * 11025

    pans = (lambda x: np.log(1 + (np.e - 1) * (top - x) / top),
            lambda x: np.log(1 + (np.e - 1) * x / top))

    #t *= Pan(*pans) # not relevant for new Pan

    audio = t.mixdown(sample_rate=11025, byte_width=2)
    play_Audio(audio, is_wait=True)
Exemple #25
0
def solfege_test_1():
    num_notes = 20
    duration = 0.5e3
    silence = 0.5e3
    starting_note = 0
    Note = Triangle

    notes = [Note(starting_note, duration) * Extend(silence)]
    for i in range(num_notes):
        starting_note += np.random.randint(-4, 5)
        notes.append(Note(midC(starting_note), duration) * Extend(silence))

    s = Signal.concat(*notes)
    audio = s.mixdown(sample_rate=22050, byte_width=2, max_amplitude=0.2)
    play_Audio(audio, is_wait=False)
Exemple #26
0
def only_signal_harmonics(f=220, seconds=10):
    params = [
        (0.34, 1, 2, 0.45),
        (0.2, 1.94, 3, 0.7),
        (0.2, 3, 2.3, 0.3),
        (0.15, 3.9994, 2.1, 0.67),
        (0.19, 5.1, 0.8, 0.46),
        (0.12, 5.96, 1.3, 0.34),
        (1 / 7, 7, 1.2, 0.5),
        (0.119, 8.1, 2.9, 0.23),
        (0.2, 9, 1.3, 0.4),
        (1 / 10, 9.87, 0.65, 0.4),
    ]

    t = sum([p[0]*Triangle(frequency=f*p[1], duration=seconds*1000)*\
             SineAM(frequency=p[2], size=p[3])*\
             Fade(is_in=True, duration=3)*\
             Shift(duration=1*1000) for p in params])
    audio = t.mixdown(sample_rate=11025, byte_width=2)
    play_Audio(audio)
Exemple #27
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 #28
0
def channel_slice_test():
    # series of tests
    #s = WAV(african)[5e3:15e3]

    # t = s[0]
    # t = s[1,1e3:7e3]
    # t = s[1e3:7e3]

    #s[1] = 0.132*WhiteNoise(duration=10e3)#*Gain(-20)

    #s[0,3e3:7e3] = s[1,2e3:6e3]
    #s[0,1e3:6e3] += 0.13*Sine(frequency=midC(8))
    #s[0,1e3:5e3] *= Reverse()
    #s[1] = s[0]*Gain(-6)
    # etc...

    ##########
    s = 0.1 * Sine()
    s[1] = WAV(african)[0, 5e3:15e3]

    audio = s.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)
Exemple #29
0
def timing_test():
    t = 0.7 * Sine(frequency=230, duration=3 * 1000) * SineAM(frequency=1,
                                                              size=0.2)[0:2]
    t += Square(frequency=250, duration=3 * 1000) * Shift(duration=3 * 1000)
    audio = t.mixdown(sample_rate=11025, byte_width=2)
    play_Audio(audio, is_wait=True)
Exemple #30
0
def syntactical_channel_rearrange_test():
    s = WAV(african)[10e3:20e3]
    s[0], s[1] = s[1], s[0]

    audio = s.mixdown(sample_rate=44100, byte_width=2, max_amplitude=0.2)
    play_Audio(audio)