示例#1
0
文件: test.py 项目: verdigris/splat
 def test_overtones(self):
     """sources.overtones"""
     freq = 1237.5
     lvl0 = dB(-0.5)
     ot = [(1.3, 0.0, dB(-2.5)), (5.7, 10.0, dB(-12.9))]
     ot_sig = [(1.3, 0.0, dB(-2.5)), (5.7, lambda x: 10.0, dB(-12.9))]
     frag_float = splat.data.Fragment(duration=1.0)
     splat.sources.overtones(frag_float, lvl0, freq, ot)
     frag_mixed = splat.data.Fragment(duration=1.0)
     splat.sources.overtones(frag_mixed, lvl0, freq, ot, lambda x: 0.0)
     frag_signal = splat.data.Fragment(duration=1.0)
     splat.sources.overtones(frag_signal, lvl0, freq, ot_sig, lambda x: 0.0)
     frag_freq = splat.data.Fragment(duration=1.0, channels=1)
     frag_freq.offset(1237.5)
     frag_frag = splat.data.Fragment(duration=1.0)
     splat.sources.overtones(frag_frag, lvl0, frag_freq, ot)
     self.assert_md5([frag_float, frag_mixed, frag_signal, frag_frag], "8974a1eea0db97af1aa171f531685e9d")
示例#2
0
文件: test.py 项目: ralic/splat-1
 def test_overtones(self):
     """sources.overtones"""
     freq = 1237.5
     lvl0 = dB(-0.5)
     ot = [(1.3, 0.0, dB(-2.5)), (5.7, 10.0, dB(-12.9))]
     ot_sig = [(1.3, 0.0, dB(-2.5)), (5.7, lambda x: 10.0, dB(-12.9))]
     frag_float = splat.data.Fragment(duration=1.0)
     splat.sources.overtones(frag_float, lvl0, freq, ot)
     frag_mixed = splat.data.Fragment(duration=1.0)
     splat.sources.overtones(frag_mixed, lvl0, freq, ot, lambda x: 0.0)
     frag_signal = splat.data.Fragment(duration=1.0)
     splat.sources.overtones(frag_signal, lvl0, freq, ot_sig, lambda x: 0.0)
     frag_freq = splat.data.Fragment(duration=1.0, channels=1)
     frag_freq.offset(1237.5)
     frag_frag = splat.data.Fragment(duration=1.0)
     splat.sources.overtones(frag_frag, lvl0, frag_freq, ot)
     self.assert_md5([frag_float, frag_mixed, frag_signal, frag_frag],
                     '8974a1eea0db97af1aa171f531685e9d')
示例#3
0
文件: test.py 项目: verdigris/splat
 def test_triangle(self):
     """sources.triangle"""
     freq = 1237.5
     lvl0 = dB(-0.5)
     frag_float = splat.data.Fragment(duration=1.0)
     splat.sources.triangle(frag_float, lvl0, freq)
     frag_signal = splat.data.Fragment(duration=1.0)
     splat.sources.triangle(frag_signal, lvl0, freq, lambda x: 0.0)
     frag_freq = splat.data.Fragment(duration=1.0, channels=1)
     frag_freq.offset(freq)
     frag_frag = splat.data.Fragment(duration=1.0)
     splat.sources.triangle(frag_frag, lvl0, frag_freq)
     self.assert_md5([frag_float, frag_signal, frag_frag], "4bce3885732ba2f5450e79e42155adaa")
示例#4
0
文件: test.py 项目: verdigris/splat
 def test_square(self):
     """sources.square"""
     freq = 1237.9
     lvl0 = dB(-0.5)
     frag_float = splat.data.Fragment(duration=1.0)
     splat.sources.square(frag_float, lvl0, freq)
     frag_signal = splat.data.Fragment(duration=1.0)
     splat.sources.square(frag_signal, lvl0, freq, lambda x: 0.0)
     frag_freq = splat.data.Fragment(duration=1.0, channels=1)
     frag_freq.offset(freq)
     frag_frag = splat.data.Fragment(duration=1.0)
     splat.sources.square(frag_frag, lvl0, frag_freq)
     self.assert_md5([frag_float, frag_signal, frag_frag], "6a6ab2e991baf48a6fe2c1d18700e40e")
示例#5
0
文件: test.py 项目: ralic/splat-1
 def test_square(self):
     """sources.square"""
     freq = 1237.9
     lvl0 = dB(-0.5)
     frag_float = splat.data.Fragment(duration=1.0)
     splat.sources.square(frag_float, lvl0, freq)
     frag_signal = splat.data.Fragment(duration=1.0)
     splat.sources.square(frag_signal, lvl0, freq, lambda x: 0.0)
     frag_freq = splat.data.Fragment(duration=1.0, channels=1)
     frag_freq.offset(freq)
     frag_frag = splat.data.Fragment(duration=1.0)
     splat.sources.square(frag_frag, lvl0, frag_freq)
     self.assert_md5([frag_float, frag_signal, frag_frag],
                     '6a6ab2e991baf48a6fe2c1d18700e40e')
示例#6
0
文件: test.py 项目: ralic/splat-1
 def test_triangle(self):
     """sources.triangle"""
     freq = 1237.5
     lvl0 = dB(-0.5)
     frag_float = splat.data.Fragment(duration=1.0)
     splat.sources.triangle(frag_float, lvl0, freq)
     frag_signal = splat.data.Fragment(duration=1.0)
     splat.sources.triangle(frag_signal, lvl0, freq, lambda x: 0.0)
     frag_freq = splat.data.Fragment(duration=1.0, channels=1)
     frag_freq.offset(freq)
     frag_frag = splat.data.Fragment(duration=1.0)
     splat.sources.triangle(frag_frag, lvl0, frag_freq)
     self.assert_md5([frag_float, frag_signal, frag_frag],
                     '4bce3885732ba2f5450e79e42155adaa')
示例#7
0
文件: test.py 项目: verdigris/splat
 def test_sine(self):
     """sources.sine"""
     freq = 1237.9
     ph = 0.123
     lvl0 = dB(-0.5)
     frag_float = splat.data.Fragment(duration=1.0)
     splat.sources.sine(frag_float, lvl0, freq, ph)
     frag_signal = splat.data.Fragment(duration=1.0)
     splat.sources.sine(frag_signal, lvl0, freq, lambda x: ph)
     frag_freq = splat.data.Fragment(duration=1.0, channels=1)
     frag_freq.offset(freq)
     frag_frag = splat.data.Fragment(duration=1.0)
     splat.sources.sine(frag_frag, lvl0, frag_freq, ph)
     self.assert_md5([frag_float, frag_signal, frag_frag], "ebd3117927861068cf77af5ed2e7c5d7")
示例#8
0
文件: test.py 项目: ralic/splat-1
 def test_sine(self):
     """sources.sine"""
     freq = 1237.9
     ph = 0.123
     lvl0 = dB(-0.5)
     frag_float = splat.data.Fragment(duration=1.0)
     splat.sources.sine(frag_float, lvl0, freq, ph)
     frag_signal = splat.data.Fragment(duration=1.0)
     splat.sources.sine(frag_signal, lvl0, freq, lambda x: ph)
     frag_freq = splat.data.Fragment(duration=1.0, channels=1)
     frag_freq.offset(freq)
     frag_frag = splat.data.Fragment(duration=1.0)
     splat.sources.sine(frag_frag, lvl0, frag_freq, ph)
     self.assert_md5([frag_float, frag_signal, frag_frag],
                     'ebd3117927861068cf77af5ed2e7c5d7')
示例#9
0
文件: test.py 项目: verdigris/splat
 def test_frag_normalize(self):
     """Fragment.normalize"""
     levels = dB(-3.0)
     places = int(self._places / 2)
     small_places = 2
     frag = splat.data.Fragment(channels=1)
     splat.gen.SineGenerator(frag=frag).run(0.0, 1.0, 123.4, levels=levels)
     sample_n = int(len(frag) / 2)
     x = frag[sample_n][0]
     frag_peak = frag.get_peak()[0]
     peak, avg = (frag_peak[item] for item in ['peak', 'avg'])
     self.assertAlmostEqual(avg, 0.0, small_places)
     self.assertAlmostEqual(levels, peak, places)
     frag.normalize()
     frag_peak = frag.get_peak()[0]
     norm_peak, norm_avg = (frag_peak[item] for item in ['peak', 'avg'])
     ref_peak = splat.dB2lin(-0.05)
     self.assertAlmostEqual(norm_peak, ref_peak, places)
     self.assertAlmostEqual(norm_avg, 0.0, places)
     y = frag[sample_n][0]
     ref = x * ref_peak / levels
     self.assertAlmostEqual(y, ref, small_places)
示例#10
0
文件: test.py 项目: ralic/splat-1
 def test_frag_normalize(self):
     """Fragment.normalize"""
     levels = dB(-3.0)
     places = int(self._places / 2)
     small_places = 2
     frag = splat.data.Fragment(channels=1)
     splat.gen.SineGenerator(frag=frag).run(0.0, 1.0, 123.4, levels=levels)
     sample_n = (len(frag) / 2)
     x = frag[sample_n][0]
     frag_peak = frag.get_peak()[0]
     peak, avg = (frag_peak[item] for item in ['peak', 'avg'])
     self.assertAlmostEqual(avg, 0.0, small_places)
     self.assertAlmostEqual(levels, peak, places)
     frag.normalize()
     frag_peak = frag.get_peak()[0]
     norm_peak, norm_avg = (frag_peak[item] for item in ['peak', 'avg'])
     ref_peak = splat.dB2lin(-0.05)
     self.assertAlmostEqual(norm_peak, ref_peak, places)
     self.assertAlmostEqual(norm_avg, 0.0, places)
     y = frag[sample_n][0]
     ref = x * ref_peak / levels
     self.assertAlmostEqual(y, ref, small_places)
示例#11
0
def run_tests(freq=123.45,
              duration=30.0,
              phase=23.456,
              pts=None,
              overtones=None,
              verbose=False):
    if pts is None:
        pts = [0.0, 0.2, 0.234, 0.456, 0.45602, 0.7124, 0.89, 0.90001]
    if overtones is None:
        overtones = [(1.0, 0.0, 0.45), (2.58, 12.345, 0.45), (200.0, 0.0, 1.0)]

    cases = []

    # -------------------------------------------------------------------------

    frag = splat.data.Fragment(channels=1)
    gen = splat.gen.SineGenerator(frag=frag)
    gen.run(0.0, duration, freq, phase)
    frag.save('sine-{}.wav'.format(splat.SAMPLE_WIDTH), normalize=False)
    cases.append('sine')

    if verbose:
        print('sine')
    for t in pts:
        t = duration * t
        n = frag.s2n(t)
        t = float(n) / frag.rate
        st = 2 * cmath.pi * freq * (t + phase)
        y1 = frag[n][0]
        y2 = math.sin(st)
        delta = abs(y2 - y1)
        if delta != 0.0:
            delta_dB = "{:.3f}".format(splat.lin2dB(delta))
        else:
            delta_dB = 'infinity'
        if verbose:
            print(t, y1, y2, delta_dB)

    # -------------------------------------------------------------------------

    frag = splat.data.Fragment(channels=1)
    gen = splat.gen.OvertonesGenerator(frag=frag)
    gen.overtones = overtones
    gen.run(0.0, duration, freq)
    frag.save('overtones-{}.wav'.format(splat.SAMPLE_WIDTH), normalize=False)
    cases.append('overtones')

    max_ratio = frag.rate / 2.0 / freq
    ot_clipped = []
    for ot in gen.overtones:
        if ot[0] < max_ratio:
            ot_clipped.append(ot)

    if verbose:
        print('overtones')
    for t in pts:
        t = duration * t
        n = frag.s2n(t)
        y1 = frag[n][0]
        y2 = sum(a * math.sin(2 * cmath.pi * freq * r * (t + ph))
                 for r, ph, a in ot_clipped)
        delta = abs(y2 - y1)
        if delta != 0.0:
            delta_dB = "{:.3f}".format(splat.lin2dB(delta))
        else:
            delta_dB = 'infinity'
        if verbose:
            print(t, y1, y2, delta_dB)

    # -------------------------------------------------------------------------

    duration = 1.0
    sig = splat.data.Fragment(channels=1)
    splat.gen.TriangleGenerator(frag=sig).run(0.0, duration, 12.0, levels=0.5)
    sig.offset(0.5)

    mod = splat.data.Fragment(channels=1)
    splat.gen.TriangleGenerator(frag=mod).run(0.0, duration, 4.0, levels=0.002)
    mod.offset(0.5)

    frag = splat.data.Fragment()
    splat.gen.SineGenerator(frag=frag).run(0.0,
                                           duration,
                                           456.0,
                                           levels=sig,
                                           phase=lambda x: math.sin(x))
    frag.save('sine-signal-{}.wav'.format(splat.SAMPLE_WIDTH), normalize=False)
    cases.append('sine-signal')

    frag = splat.data.Fragment()
    gen = splat.gen.OvertonesGenerator(frag=frag)
    gen.overtones = overtones
    gen.run(0.0, duration, 456.0, levels=sig)
    frag.save('overtones-mixed1-{}.wav'.format(splat.SAMPLE_WIDTH),
              normalize=False)
    cases.append('overtones-mixed1')

    frag = splat.data.Fragment()
    gen = splat.gen.OvertonesGenerator(frag=frag)
    gen.overtones = overtones
    gen.run(0.0, duration, 456.0, levels=sig, phase=mod)
    frag.save('overtones-mixed2-{}.wav'.format(splat.SAMPLE_WIDTH),
              normalize=False)
    cases.append('overtones-mixed2')

    sig2 = splat.data.Fragment(channels=1)
    splat.gen.TriangleGenerator(frag=sig2).run(0.0, duration, 1.8, levels=0.1)
    sig2.offset(-sig2.get_peak()[0]['min'])
    overtones.append((0.54, 0.0, sig2))

    frag = splat.data.Fragment()
    gen = splat.gen.OvertonesGenerator(frag=frag)
    gen.overtones = overtones
    gen.run(0.0, duration, 456.0, levels=sig, phase=mod)
    frag.save('overtones-signal-{}.wav'.format(splat.SAMPLE_WIDTH),
              normalize=False)
    cases.append('overtones-signal')

    frag = splat.data.Fragment()
    gen = splat.gen.SineGenerator(frag=frag)
    gen.run(0.0, 5.678, 1234.56, levels=dB(-3))
    ratio = 1.987
    new_len = int(len(frag) * ratio)
    rem = new_len % 4
    if rem:
        new_len -= rem
    else:
        new_len -= 4
    frag.resample(ratio=ratio)
    frag.resize(length=new_len)
    frag.save('resample-float-{}.wav'.format(splat.SAMPLE_WIDTH))
    cases.append('resample-float')

    frag = splat.data.Fragment()
    gen = splat.gen.SineGenerator(frag=frag)
    gen.run(0.0, 5.678, 1234.56, levels=dB(-3))
    ratio = 1.987
    frag.resample(ratio=lambda x: ratio)
    frag.save('resample-signal-{}.wav'.format(splat.SAMPLE_WIDTH))
    cases.append('resample-signal')

    return cases
示例#12
0
文件: bm.py 项目: gctucker/splat
 def setUp(self):
     super(GenMixin, self).setUp()
     self.freq = 1234.0
     self.mod = splat.data.Fragment(duration=self.frag.duration, channels=1)
     splat.sources.sine(self.mod, dB(-9.0), 1.0)
     self.mod.offset(0.5)
示例#13
0
def run_tests(freq=123.45, duration=30.0, phase=23.456, pts=None,
              overtones=None, verbose=False):
    if pts is None:
        pts = [0.0, 0.2, 0.234, 0.456, 0.45602, 0.7124, 0.89, 0.90001]
    if overtones is None:
        overtones = [(1.0, 0.0, 0.45), (2.58, 12.345, 0.45), (200.0, 0.0, 1.0)]

    cases = []

    # -------------------------------------------------------------------------

    frag = splat.data.Fragment(channels=1)
    gen = splat.gen.SineGenerator(frag=frag)
    gen.run(0.0, duration, freq, phase)
    frag.save('sine-{}.wav'.format(splat.SAMPLE_WIDTH), normalize=False)
    cases.append('sine')

    if verbose:
        print('sine')
    for t in pts:
        t = duration * t
        n = frag.s2n(t)
        t = float(n) / frag.rate
        st = 2 * cmath.pi * freq * (t + phase)
        y1 = frag[n][0]
        y2 = math.sin(st)
        delta = abs(y2 - y1)
        if delta != 0.0:
            delta_dB = "{:.3f}".format(splat.lin2dB(delta))
        else:
            delta_dB = 'infinity'
        if verbose:
            print(t, y1, y2, delta_dB)

    # -------------------------------------------------------------------------

    frag = splat.data.Fragment(channels=1)
    gen = splat.gen.OvertonesGenerator(frag=frag)
    gen.overtones = overtones
    gen.run(0.0, duration, freq)
    frag.save('overtones-{}.wav'.format(splat.SAMPLE_WIDTH), normalize=False)
    cases.append('overtones')

    max_ratio = frag.rate / 2.0 / freq
    ot_clipped = []
    for ot in gen.overtones:
        if ot[0] < max_ratio:
            ot_clipped.append(ot)

    if verbose:
        print('overtones')
    for t in pts:
        t = duration * t
        n = frag.s2n(t)
        y1 = frag[n][0]
        y2 = sum(a * math.sin(2 * cmath.pi * freq * r * (t + ph))
                 for r, ph, a in ot_clipped)
        delta = abs(y2 - y1)
        if delta != 0.0:
            delta_dB = "{:.3f}".format(splat.lin2dB(delta))
        else:
            delta_dB = 'infinity'
        if verbose:
            print(t, y1, y2, delta_dB)

    # -------------------------------------------------------------------------

    duration = 1.0
    sig = splat.data.Fragment(channels=1)
    splat.gen.TriangleGenerator(frag=sig).run(0.0, duration, 12.0, levels=0.5)
    sig.offset(0.5)

    mod = splat.data.Fragment(channels=1)
    splat.gen.TriangleGenerator(frag=mod).run(0.0, duration, 4.0, levels=0.002)
    mod.offset(0.5)

    frag = splat.data.Fragment()
    splat.gen.SineGenerator(frag=frag).run(0.0, duration, 456.0, levels=sig,
                                           phase=lambda x: math.sin(x))
    frag.save('sine-signal-{}.wav'.format(splat.SAMPLE_WIDTH), normalize=False)
    cases.append('sine-signal')

    frag = splat.data.Fragment()
    gen = splat.gen.OvertonesGenerator(frag=frag)
    gen.overtones = overtones
    gen.run(0.0, duration, 456.0, levels=sig)
    frag.save('overtones-mixed1-{}.wav'.format(splat.SAMPLE_WIDTH),
              normalize=False)
    cases.append('overtones-mixed1')

    frag = splat.data.Fragment()
    gen = splat.gen.OvertonesGenerator(frag=frag)
    gen.overtones = overtones
    gen.run(0.0, duration, 456.0, levels=sig, phase=mod)
    frag.save('overtones-mixed2-{}.wav'.format(splat.SAMPLE_WIDTH),
              normalize=False)
    cases.append('overtones-mixed2')

    sig2 = splat.data.Fragment(channels=1)
    splat.gen.TriangleGenerator(frag=sig2).run(0.0, duration, 1.8, levels=0.1)
    sig2.offset(-sig2.get_peak()[0]['min'])
    overtones.append((0.54, 0.0, sig2))

    frag = splat.data.Fragment()
    gen = splat.gen.OvertonesGenerator(frag=frag)
    gen.overtones = overtones
    gen.run(0.0, duration, 456.0, levels=sig, phase=mod)
    frag.save('overtones-signal-{}.wav'.format(splat.SAMPLE_WIDTH),
              normalize=False)
    cases.append('overtones-signal')

    frag = splat.data.Fragment()
    gen = splat.gen.SineGenerator(frag=frag)
    gen.run(0.0, 5.678, 1234.56, levels=dB(-3))
    ratio = 1.987
    new_len = int(len(frag) * ratio)
    rem = new_len % 4
    if rem:
        new_len -= rem
    else:
        new_len -= 4
    frag.resample(ratio=ratio)
    frag.resize(length=new_len)
    frag.save('resample-float-{}.wav'.format(splat.SAMPLE_WIDTH))
    cases.append('resample-float')

    frag = splat.data.Fragment()
    gen = splat.gen.SineGenerator(frag=frag)
    gen.run(0.0, 5.678, 1234.56, levels=dB(-3))
    ratio = 1.987
    frag.resample(ratio=lambda x: ratio)
    frag.save('resample-signal-{}.wav'.format(splat.SAMPLE_WIDTH))
    cases.append('resample-signal')

    return cases
示例#14
0
文件: dew_drop.py 项目: ralic/splat-1
def main(argv):
    parser = argparse.ArgumentParser("Dew Drop tune using irrational rythm.")
    parser.add_argument('--save-as',
                        default='dew_drop.wav',
                        help="output file name, leave blank to not save")
    parser.add_argument('--no-reverb',
                        action='store_true',
                        help="do not generate the reverb effect")
    parser.add_argument('--dump-scale',
                        action='store_true',
                        help="dump the frequency of the notes in the scale")
    parser.add_argument('--rate', type=int, default=48000, help="sample rate")
    parser.add_argument('--voices',
                        default='123',
                        help="voices to run (string with 1, 2 and 3)")
    args = parser.parse_args(argv[1:])

    gen = splat.gen.OvertonesGenerator(splat.data.Fragment(2, args.rate, 18.0))
    s = splat.scales.LogScale(fund=440.0)

    if args.dump_scale is True:
        # print frequencies of all the notes of the scale over 3 octaves
        for octave in range(-2, 1):
            for note in ['A', 'B', 'C#', 'D', 'E', 'F#', 'G#']:
                note_name = "{0}{1}".format(note, octave)
                print('{0:4s}: {1:.3f}'.format(note_name, s[note_name]))
            print("-------------")

    if '1' in args.voices:
        print("Voice 1")
        gen.levels = (dB(-2.5), dB(-2.5))
        gen.ot_decexp(2.0)
        set_fade(gen, 0.04)
        gen.run(0.0, 1.62, s['A-2'])
        gen.run(1.62, 3.24, s['D-2'])
        gen.run(3.24, 4.248, s['F#-2'])
        gen.run(4.248, 5.868, s['E-2'])
        gen.run(5.868, 6.858, s['D-2'])
        gen.run(6.858, 8.496, s['F#-2'])
        gen.run(8.496, 9.504, s['E-2'])
        gen.run(9.504, 11.124, s['B-2'])
        gen.run(11.124, 12.744, s['E-2'])
        gen.run(12.744, 13.752, s['A-2'])
        gen.run(13.752, 14.742, s['D-2'])
        gen.run(14.742, 16.38, s['E-2'])
        gen.run(16.38, 18.0, s['A-2'])

    if '2' in args.voices:
        print("Voice 2")
        gen.levels = (dB(0.0), dB(-2.5))
        gen.ot_decexp(1.6)
        set_fade(gen, 0.02)
        gen.run(0.0, 1.008, s['C#-1'])
        gen.run(1.008, 1.62, s['E-1'])
        gen.run(1.62, 2.628, s['A-1'])
        gen.run(2.628, 3.24, s['F#-2'])
        gen.run(3.24, 3.852, s['A-1'])
        gen.run(3.852, 4.248, s['C#-1'])
        gen.run(4.248, 4.86, s['B-1'])
        gen.run(4.86, 5.868, s['D-1'])
        gen.run(5.868, 6.858, s['B-1'])
        gen.run(6.858, 7.848, s['C#-1'])
        gen.run(7.848, 8.496, s['A-1'])
        gen.run(8.496, 9.504, s['G#-2'])
        gen.run(9.504, 10.494, s['D-1'])
        gen.run(10.494, 11.124, s['F#-1'])
        gen.run(11.124, 11.754, s['B-1'])
        gen.run(11.754, 12.744, s['D-1'])
        gen.run(12.744, 13.752, s['E-1'])
        gen.run(13.752, 14.364, s['F#-1'])
        gen.run(14.364, 15.372, s['A-1'])
        gen.run(15.372, 16.38, s['D-1'])
        gen.run(16.38, 18.0, s['C#-1'])

    if '3' in args.voices:
        print("Voice 3")
        gen.levels = (dB(-2.5), dB(0.0))
        gen.ot_decexp(1.2)
        set_fade(gen, 0.015)
        gen.run(0.0, 0.612, s['E'])
        gen.run(0.612, 1.008, s['D'])
        gen.run(1.008, 1.62, s['E'])
        gen.run(1.62, 2.232, s['D'])
        gen.run(3.24, 3.852, s['C#'])
        gen.run(3.852, 4.248, s['A'])
        gen.run(4.248, 4.86, s['B'])
        gen.run(4.86, 5.256, s['D'])
        gen.run(5.256, 5.868, s['E'])
        gen.run(5.868, 6.858, s['F#'])
        gen.run(8.496, 8.874, s['D'])
        gen.run(8.874, 9.504, s['E'])
        gen.run(9.504, 10.494, s['F#'])
        gen.run(10.494, 11.124, s['A'])
        gen.run(11.124, 11.754, s['B'])
        gen.run(11.754, 12.132, s['C#'])
        gen.run(12.132, 12.744, s['D'])
        gen.run(12.744, 13.752, s['C#'])
        gen.run(14.364, 15.372, s['B'])
        gen.run(15.372, 16.38, s['G#-1'])
        gen.run(16.38, 18.0, s['A'])

    if args.no_reverb is False:
        print("Reverb")
        d = splat.filters.reverb_delays()
        splat.filters.reverb(gen.frag, d)

    if args.save_as:
        print("Saving as {}".format(args.save_as))
        padded = splat.data.Fragment(2, args.rate, (gen.frag.duration + 1.0))
        padded.mix(gen.frag, 0.5)
        padded.save(args.save_as)
示例#15
0
文件: example.py 项目: gctucker/splat
import splat.data
import splat.filters
import splat.gen
import splat.interpol
import splat.scales
from splat import dB2lin as dB

# Create a harmonic scale to use note names rather than frequencies
scale = splat.scales.HarmonicScale()

# Create a triangle wave generator and produce some simple sound with it
triangle = splat.gen.TriangleGenerator()
triangle.filters = [splat.filters.linear_fade]
triangle.run(0.0, 2.8, scale['A-1'], levels=dB(-6.0))

# Create a spline to be used as an envelope (amplitude modulation) in dB
envelope_pts = [(0.0, -100.0), (0.5, -12.0), (1.0, -0.5, 0.0),
                (1.8, -6.0), (2.5, -100.0)]
envelope = splat.interpol.spline(envelope_pts, dB2lin=True)

# Create a sine wave generator and run it with the envelope
sine = splat.gen.SineGenerator()
sine.run(0.0, 2.5, scale['E-1'], levels=envelope.signal)

# Mix the generated fragments together, add some reverb and save the result
master = splat.data.Fragment()
master.mix(triangle.frag, 0.5)
master.mix(sine.frag, 0.75)
splat.filters.reverb(master, splat.filters.reverb_delays())
master.save('example.wav')
示例#16
0
 def setUp(self):
     super(GenMixin, self).setUp()
     self.freq = 1234.0
     self.mod = splat.data.Fragment(duration=self.frag.duration, channels=1)
     splat.sources.sine(self.mod, dB(-9.0), 1.0)
     self.mod.offset(0.5)
示例#17
0
import splat.gen
import splat.data
import splat.filters
import splat.interpol
from splat import dB2lin as dB

# Create a triangle wave generator and produce some simple sound with it
triangle = splat.gen.TriangleGenerator()
triangle.filters = [splat.filters.linear_fade]
triangle.run(0.0, 2.8, 220.0, levels=dB(-6.0))

# Create a spline to be used as an envelope (amplitude modulation) in dB
envelope_pts = [(0.0, -100.0), (0.5, -12.0), (1.0, -0.5, 0.0),
                (1.8, -6.0), (2.5, -100.0)]
envelope = splat.interpol.spline(envelope_pts, dB2lin=True)

# Create a sine wave generator and run it with the envelope
sine = splat.gen.SineGenerator()
sine.run(0.0, 2.5, 330.0, levels=tuple(envelope.value for i in range(2)))

# Mix the generated fragments together, add some reverb and save the result
master = splat.data.Fragment()
master.mix(triangle.frag, 0.5)
master.mix(sine.frag, 0.75)
splat.filters.reverb(master, splat.filters.reverb_delays())
master.normalize()
master.save('example.wav')
示例#18
0
def main(argv):
    parser = argparse.ArgumentParser("Dew Drop tune using irrational rythm.")
    parser.add_argument('--save-as', default='dew_drop.wav',
                        help="output file name, leave blank to not save")
    parser.add_argument('--no-reverb', action='store_true',
                        help="do not generate the reverb effect")
    parser.add_argument('--dump-scale', action='store_true',
                        help="dump the frequency of the notes in the scale")
    parser.add_argument('--rate', type=int, default=48000,
                        help="sample rate")
    parser.add_argument('--voices', default='123',
                        help="voices to run (string with 1, 2 and 3)")
    args = parser.parse_args(argv[1:])

    gen = splat.gen.OvertonesGenerator(splat.data.Fragment(2, args.rate, 18.0))
    s = splat.scales.LogScale(fund=440.0)

    if args.dump_scale is True:
        # print frequencies of all the notes of the scale over 3 octaves
        for octave in range(-2, 1):
            for note in ['A', 'B', 'C#', 'D', 'E', 'F#', 'G#']:
                note_name = "{0}{1}".format(note, octave)
                print('{0:4s}: {1:.3f}'.format(note_name, s[note_name]))
            print("-------------")

    if '1' in args.voices:
        print("Voice 1")
        gen.levels = (dB(-2.5), dB(-2.5))
        gen.ot_decexp(2.0)
        set_fade(gen, 0.04)
        gen.run(0.0, 1.62, s['A-2'])
        gen.run(1.62, 3.24, s['D-2'])
        gen.run(3.24, 4.248, s['F#-2'])
        gen.run(4.248, 5.868, s['E-2'])
        gen.run(5.868, 6.858, s['D-2'])
        gen.run(6.858, 8.496, s['F#-2'])
        gen.run(8.496, 9.504, s['E-2'])
        gen.run(9.504, 11.124, s['B-2'])
        gen.run(11.124, 12.744, s['E-2'])
        gen.run(12.744, 13.752, s['A-2'])
        gen.run(13.752, 14.742, s['D-2'])
        gen.run(14.742, 16.38, s['E-2'])
        gen.run(16.38, 18.0, s['A-2'])

    if '2' in args.voices:
        print("Voice 2")
        gen.levels = (dB(0.0), dB(-2.5))
        gen.ot_decexp(1.6)
        set_fade(gen, 0.02)
        gen.run(0.0, 1.008, s['C#-1'])
        gen.run(1.008, 1.62, s['E-1'])
        gen.run(1.62, 2.628, s['A-1'])
        gen.run(2.628, 3.24, s['F#-2'])
        gen.run(3.24, 3.852, s['A-1'])
        gen.run(3.852, 4.248, s['C#-1'])
        gen.run(4.248, 4.86, s['B-1'])
        gen.run(4.86, 5.868, s['D-1'])
        gen.run(5.868, 6.858, s['B-1'])
        gen.run(6.858, 7.848, s['C#-1'])
        gen.run(7.848, 8.496, s['A-1'])
        gen.run(8.496, 9.504, s['G#-2'])
        gen.run(9.504, 10.494, s['D-1'])
        gen.run(10.494, 11.124, s['F#-1'])
        gen.run(11.124, 11.754, s['B-1'])
        gen.run(11.754, 12.744, s['D-1'])
        gen.run(12.744, 13.752, s['E-1'])
        gen.run(13.752, 14.364, s['F#-1'])
        gen.run(14.364, 15.372, s['A-1'])
        gen.run(15.372, 16.38, s['D-1'])
        gen.run(16.38, 18.0, s['C#-1'])

    if '3' in args.voices:
        print("Voice 3")
        gen.levels = (dB(-2.5), dB(0.0))
        gen.ot_decexp(1.2)
        set_fade(gen, 0.015)
        gen.run(0.0, 0.612, s['E'])
        gen.run(0.612, 1.008, s['D'])
        gen.run(1.008, 1.62, s['E'])
        gen.run(1.62, 2.232, s['D'])
        gen.run(3.24, 3.852, s['C#'])
        gen.run(3.852, 4.248, s['A'])
        gen.run(4.248, 4.86, s['B'])
        gen.run(4.86, 5.256, s['D'])
        gen.run(5.256, 5.868, s['E'])
        gen.run(5.868, 6.858, s['F#'])
        gen.run(8.496, 8.874, s['D'])
        gen.run(8.874, 9.504, s['E'])
        gen.run(9.504, 10.494, s['F#'])
        gen.run(10.494, 11.124, s['A'])
        gen.run(11.124, 11.754, s['B'])
        gen.run(11.754, 12.132, s['C#'])
        gen.run(12.132, 12.744, s['D'])
        gen.run(12.744, 13.752, s['C#'])
        gen.run(14.364, 15.372, s['B'])
        gen.run(15.372, 16.38, s['G#-1'])
        gen.run(16.38, 18.0, s['A'])

    if args.no_reverb is False:
        print("Reverb")
        d = splat.filters.reverb_delays()
        splat.filters.reverb(gen.frag, d)

    if args.save_as:
        print("Saving as {}".format(args.save_as))
        padded = splat.data.Fragment(2, args.rate, (gen.frag.duration + 1.0))
        padded.mix(gen.frag, 0.5)
        padded.save(args.save_as)