def song1_lowKey(self):
     self.btnnum1_lowKey.configure(image=self.btnnum1_lowKey_change_gif)
     sampler = Sampler()
     s1 = Sound.from_file(song_name1)
     s1.pitch_shift = -1
     sampler.play(s1)
     self.btnnum1_lowKey.configure(image=self.btnnum1_lowKey_gif)
 def song2_lowKey(self):
     self.btnnum2_lowKey.configure(image=self.btnnum2_lowKey_change_gif)
     sampler = Sampler()
     s2 = Sound.from_file(song_name2)
     s2.pitch_shift = -1
     sampler.play(s2)
     self.btnnum2_lowKey.configure(image=self.btnnum2_lowKey_gif)
 def song1_hiSpd(self):
     self.btnnum1_hiSpd.configure(image=self.btnnum1_hiSpd_change_gif)
     sampler = Sampler()
     s1 = Sound.from_file(song_name1)
     s1.stretch_factor = 2
     sampler.play(s1)
     self.btnnum1_hiSpd.configure(image=self.btnnum1_hiSpd_gif)
 def song3_lowKey(self):
     self.btnnum3_lowKey.configure(image=self.btnnum3_lowKey_change_gif)
     sampler = Sampler()
     s3 = Sound.from_file(song_name3)
     s3.pitch_shift = -1
     sampler.play(s3)
     self.btnnum3_lowKey.configure(image=self.btnnum3_lowKey_gif)
 def song2_hiSpd(self):
     self.btnnum2_hiSpd.configure(image=self.btnnum2_hiSpd_change_gif)
     sampler = Sampler()
     s2 = Sound.from_file(song_name2)
     s2.stretch_factor = 2
     sampler.play(s2)
     self.btnnum2_hiSpd.configure(image=self.btnnum2_hiSpd_gif)
 def song3_hiSpd(self):
     self.btnnum3_hiSpd.configure(image=self.btnnum3_hiSpd_change_gif)
     sampler = Sampler()
     s3 = Sound.from_file(song_name3)
     s3.stretch_factor = 2
     sampler.play(s3)
     self.btnnum3_hiSpd.configure(image=self.btnnum3_hiSpd_gif)
 def song4_lowKey(self):
     self.btnnum4_lowKey.configure(image=self.btnnum4_lowKey_change_gif)
     sampler = Sampler()
     s4 = Sound.from_file(song_name4)
     s4.pitch_shift = -1
     sampler.play(s4)
     self.btnnum4_lowKey.configure(image=self.btnnum4_lowKey_gif)
 def song4_lowSpd(self):
     self.btnnum4_lowSpd.configure(image=self.btnnum4_lowSpd_change_gif)
     sampler = Sampler()
     s4 = Sound.from_file(song_name4)
     s4.stretch_factor = 0.5
     sampler.play(s4)
     self.btnnum4_lowSpd.configure(image=self.btnnum4_lowSpd_gif)
Exemple #9
0
def pitch_shift():
    sampler = Sampler()
    wav_file = kRecordedWav
    s1 = Sound.from_file(wav_file)
    sampler.play(s1)
    # Add random effects to be interesting
    while s1.playing:
        s1.pitch_shift = random.choice(
            [random.randint(-5, -3),
             random.randint(15, 20)])
        s1.stretch_factor = random.choice([.8, 1.2])
        time.sleep(.8)
Exemple #10
0
class TestTimeStretch(unittest.TestCase):
    def setUp(self):
        self.s1 = Sound.from_file(example_audio_file())

        freq, dt, sr = 440.0, 10.0, 22050
        t = numpy.linspace(0, dt, sr * dt)
        self.s2 = Sound(numpy.sin(2 * numpy.pi * freq * t), sr)

        self.sounds = [self.s1, self.s2, copy.deepcopy(self.s1)]

        self.sampler = Sampler(backend='dummy')

    def test_sampling(self):
        for s in self.sounds:
            self.sampler.play(s)
            time.sleep(random.random())
            s.pitch_shift = random.random() * 24 - 12
            time.sleep(random.random())
            s.stretch_factor = random.random() * 5

        while self.sampler.sounds:
            time.sleep(.1)
Exemple #11
0
class Player(object):
    def __init__(self, files):
        self.sampler = Sampler(44100)
        self._sounds = []
        for i in files:
            self.load(i)

    def load(self, fname):
        print('loading', fname)
        self._sounds += [Sound.from_file(fname).resample(44100)]
        return len(self._sounds) - 1

    def play(self, index):
        self.sampler.play(self._sounds[index])

    def is_playing(self, index):
        try:
            return self._sounds[index].playing
        except:
            return False

    def stop(self, index=None):
        try:
            if index:
                self.sampler.remove(self._sounds[index])
            else:
                for i in self._sounds:
                    self.sampler.remove(i)
        except:
            pass

    def pitch(self, index, val):
        self._sounds[index].pitch_shift = val

    def stretch(self, index, val):
        self._sounds[index].stretch_factor = val

    def sound(self, index):
        return self._sounds[index]
 def song3_origin(self):
     sampler = Sampler()
     s3 = Sound.from_file(song_name3)
     sampler.play(s3)
 def song2_origin(self):
     sampler = Sampler()
     s2 = Sound.from_file(song_name2)
     sampler.play(s2)
 def song4_origin(self):
     sampler = Sampler()
     s4 = Sound.from_file(song_name4)
     sampler.play(s4)
 def song3_origin(self):
     self.btnnum3_origin.configure(image=self.btnnum3_origin_change_gif)
     sampler = Sampler()
     s3 = Sound.from_file(song_name3)
     sampler.play(s3)
     self.btnnum3_origin.configure(image=self.btnnum3_origin_gif)
 def song3_lowSpd(self):
     sampler = Sampler()
     s3 = Sound.from_file(song_name3)
     s3.stretch_factor = 0.5
     sampler.play(s3)
 def song1_lowKey(self):
     sampler = Sampler()
     s1 = Sound.from_file(song_name1)
     s1.pitch_shift = -1
     sampler.play(s1)
 def song2_lowKey(self):
     sampler = Sampler()
     s2 = Sound.from_file(song_name2)
     s2.pitch_shift = -1
     sampler.play(s2)
keys_file = "sounds/1901_keys.mp3"
gtr1_file = "sounds/1901_gtr1.mp3"
triggers_file = "sounds/1901_triggers.mp3"
drumleft_file = "sounds/1901_drumsleft.mp3"

keys = Sound.from_file(keys_file)
gtr1 = Sound.from_file(gtr1_file)
triggers = Sound.from_file(triggers_file)
drumleft = Sound.from_file(drumleft_file)

sampler = Sampler()

t_end = time.time() + 60 * 1

#sampler.play(keys)
sampler.play(gtr1)
sampler.play(triggers)
sampler.play(drumleft)
print('played')

#set up cv
lowerBound_green = np.array([33, 80, 40])
upperBound_green = np.array([102, 255, 255])

lowerBound_red = np.array([0, 100, 100])
upperBound_red = np.array([5, 255, 255])

def SetUpRemoveAddSong(song, color):
    if color == "red":
        w = w_r
    elif color == "green":
    binned = bin_data(y, 10, .5)
    pitch_shifts = binned
    speed = 5
    sampler = Sampler()
    s1 = Sound.from_file("A.wav")
    xpoint = 0
    paused = False
    key = keyhit.KBHit()
    while True:
        print("arrow")
        if paused == False:
            arrow = key.getarrow()
            print("STARTING SAMPLER")
            while (paused == False):
                print("while paused is false")
                sampler.play(s1)
                since_start = time.clock()
                for pitch in pitch_shifts[0:]:
                    pausearrow = key.getarrow()
                    if pausearrow == arrow:
                        s1.pitch_shift = pitch
                        #print(pitch)
                        time.sleep(1 / speed)

                    elif (pausearrow == 2):
                        print("PAUSE")
                        paused = True
                        #stop_bool = True
                        pause_time = time.clock()
                        xpoint = xpoint + math.ceil(
                            (pause_time - since_start) / speed)
 def song1_origin(self):
     self.btnnum1_origin.configure(image=self.btnnum1_origin_change_gif)
     sampler = Sampler()
     s1 = Sound.from_file(song_name1)
     sampler.play(s1)
     self.btnnum1_origin.configure(image=self.btnnum1_origin_gif)
 def song2_lowSpd(self):
     sampler = Sampler()
     s2 = Sound.from_file(song_name2)
     s2.stretch_factor = 0.5
     sampler.play(s2)
 def song4_hiSpd(self):
     sampler = Sampler()
     s4 = Sound.from_file(song_name4)
     s4.stretch_factor = 2
     sampler.play(s4)
 def song4_lowKey(self):
     sampler = Sampler()
     s4 = Sound.from_file(song_name4)
     s4.pitch_shift = -1
     sampler.play(s4)
 def song4_origin(self):
     self.btnnum4_origin.configure(image=self.btnnum4_origin_change_gif)
     sampler = Sampler()
     s4 = Sound.from_file(song_name4)
     sampler.play(s4)
     self.btnnum4_origin.configure(image=self.btnnum4_origin_gif)
 def song1_hiSpd(self):
     sampler = Sampler()
     s1 = Sound.from_file(song_name1)
     s1.stretch_factor = 2
     sampler.play(s1)
 def song1_origin(self):
     sampler = Sampler()
     s1 = Sound.from_file(song_name1)
     sampler.play(s1)
 def song2_origin(self):
     self.btnnum2_origin.configure(image=self.btnnum2_origin_change_gif)
     sampler = Sampler()
     s2 = Sound.from_file(song_name2)
     sampler.play(s2)
     self.btnnum2_origin.configure(image=self.btnnum2_origin_gif)
 def song1_lowSpd(self):
     sampler = Sampler()
     s4 = Sound.from_file(song_name4)
     s4.stretch_factor = 0.5
     sampler.play(s4)
 def song3_lowKey(self):
     sampler = Sampler()
     s3 = Sound.from_file(song_name3)
     s3.pitch_shift = -1
     sampler.play(s3)