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 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_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 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 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 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 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)
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 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)
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)
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 song2_origin(self): sampler = Sampler() s2 = Sound.from_file(song_name2) sampler.play(s2)
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 song3_origin(self): sampler = Sampler() s3 = Sound.from_file(song_name3) sampler.play(s3)
def song1_lowKey(self): sampler = Sampler() s1 = Sound.from_file(song_name1) s1.pitch_shift = -1 sampler.play(s1)
def song4_origin(self): sampler = Sampler() s4 = Sound.from_file(song_name4) sampler.play(s4)
def song4_hiSpd(self): sampler = Sampler() s4 = Sound.from_file(song_name4) s4.stretch_factor = 2 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 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 song2_lowKey(self): sampler = Sampler() s2 = Sound.from_file(song_name2) s2.pitch_shift = -1 sampler.play(s2)
def song3_lowKey(self): sampler = Sampler() s3 = Sound.from_file(song_name3) s3.pitch_shift = -1 sampler.play(s3)
def song2_lowSpd(self): sampler = Sampler() s2 = Sound.from_file(song_name2) s2.stretch_factor = 0.5 sampler.play(s2)
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 song3_lowSpd(self): sampler = Sampler() s3 = Sound.from_file(song_name3) s3.stretch_factor = 0.5 sampler.play(s3)
def song1_lowSpd(self): sampler = Sampler() s4 = Sound.from_file(song_name4) s4.stretch_factor = 0.5 sampler.play(s4)
def song1_origin(self): sampler = Sampler() s1 = Sound.from_file(song_name1) sampler.play(s1)
def song1_hiSpd(self): sampler = Sampler() s1 = Sound.from_file(song_name1) s1.stretch_factor = 2 sampler.play(s1)
if __name__ == "__main__": # 0 : up # 1 : right # 2 : down # 3 : left filepath = "mvp.csv" fs = 44100 x, y = get_csv_data(filepath) slopes = find_slopes(x, y) randvar = np.random.normal(0, 1, 100) 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()
def song4_lowKey(self): sampler = Sampler() s4 = Sound.from_file(song_name4) s4.pitch_shift = -1 sampler.play(s4)