Ejemplo n.º 1
0
 def test_pulse(self):
     """Confirm that duty cycles work"""
     space = sp.space(3)
     fif = sp.pulse(space, 100)
     tw5 = sp.pulse(space, 100, 0.25)
     fif_high = len(np.where(fif == 1.)[0])
     tw5_high = len(np.where(tw5 == 1.)[0])
     self.assertAlmostEqual(fif_high / len(space), 0.5, 2)
     self.assertAlmostEqual(tw5_high / len(space), 0.25, 2)
Ejemplo n.º 2
0
import time
import sys
import numpy as np
import shaded as sp
import sounddevice as sd
import soundfile as sf


def play(sound, sample_rate=sp.SAMPLE_RATE):
    """Helper to play serially"""
    sd.play(sound)
    time.sleep(len(sound) / sample_rate)


space = sp.space(3)

one_hz = (sp.sin(space, 1.) / 2. + 0.5)  #beating
concertA = sp.sin(space, 440)  #concert A sin wave for three seconds
modulatedA = concertA * one_hz  #beating w/ a sin wave
buzz = sp.sigmoid(
    sp.sin(space, 60),
    sp.sin(space, 60) + 220) * 0.5  #buzzing by modulating frequency
div = (sp.sin(space, 17) / sp.sin(space, 3)
       ) * 0.2 * concertA  #dividing signals to generate complex waveforms
complex_beat = sp.noise(space) * (sp.sigmoid(
    space, 2) - sp.sin(space, 0.4) - sp.sin(space, 0.25, 1)) + sp.sin(
        space, 440) * (sp.sin(space, 3) - sp.sin(space, 4.25)) + sp.sin(
            space, 310) * (sp.sin(space, 3, 1.254))  #complex beat
fmod = sp.sin(
    space,
    sp.sin(space, 2) * 220
Ejemplo n.º 3
0
 def test_square_range(self):
     """Confirm that square waves fall in the correct range- -1,1."""
     sq = sp.square(sp.space(3), 100)
     self.assertEqual(np.max(sq), 1.)
     self.assertEqual(np.min(sq), -1.)
Ejemplo n.º 4
0
import shaded as sd
from sounddevice import play
import soundfile as sf
import numpy as np
song = sd.space(13)
overall_env = sd.smoothstep(0, 1, song) - sd.smoothstep(12, 14.8, song)

bass_line = sd.arp(song, [110, 130.81, 146.83, 110] *
                   5)  #this time, the "*" means we're repeating
bass_line_wave = sd.smooth_normalize(
    sd.sin(song, bass_line) * sd.pulse(song, 3, 0.333, normalize=False))

drums = sd.noise(song) * sd.sigmoid(song, 10) * sd.sigmoid(
    song, 12, 0.25 * 2 * np.pi) * 0.2

melody_a = sd.arp(song, [440, 880, 440, 220])
melody_b = sd.arp(song, [523.25, 392.00, 659.25] * 6)
string = sd.saw(song, melody_a) * 0.25 + sd.saw(song, melody_b) * 0.25

full_song = bass_line_wave * sd.smoothstep(
    2, 3, song) + drums * 0.25 + string * 0.5 * (sd.smoothstep(4, 6, song) -
                                                 sd.smoothstep(8, 10, song))

sf.write('working/demo.wav', full_song, int(44100), 'FLOAT')
Ejemplo n.º 5
0
        sp.arp(space,
               [0.125, 0.5, 0.9, 3., 3.2, 0.125, 0.52, 0.4, 3., 9, 0.125])))


def closing_scream(space):
    return sp.saw(space, 990 - sp.sin(space, 3)) - sp.saw(
        space / 5. * sp.sin(space, 0.1), 890) - sp.saw(space, 650)


def rpeak(space):
    dur = len(space) / sp.SAMPLE_RATE
    return sp.saw(space, dur / 20., np.pi / 4.) * sp.gate(
        space, dur / 20. * 19.)


song = sp.space(120)
bass_line = sp.reverb(
    bass_prog(song, 20) * bass_beat(song) * bass_enter_exit(song, 7), 1. / 15.,
    10)
drums = sp.reverb(drum_line(song), -1. / 30., 7)
mel = melody(song) * melody_rhthym(song) * melody_gate(song, 3., 100)
whispered = sp.reverb(whispers(song) * whisper_slide(song), 1. / 50., 12, 0.7)
closing = sp.reverb(closing_scream(song), -1., 10) * rpeak(song)

composition = (bass_line + drums * 0.5 + mel - whispered * 0.25 + closing +
               np.roll(closing, int(-30 * sp.SAMPLE_RATE)) +
               np.roll(closing, int(-60 * sp.SAMPLE_RATE)) - np.fmod(
                   np.roll(closing, int(17 * sp.SAMPLE_RATE)), 0.75)) * sp.sin(
                       song, 1. / 60.)

sf.write('working/the_barron.wav', composition, int(sp.SAMPLE_RATE), 'FLOAT')