def render(self): # Render hit of "key" for "length" amound of seconds # XXX: Currently only uses a string pluck key = (str(self.note), self.length) if key not in Hit.cache: if self.soundType == 'pluck': Hit.cache[key] = source.pluck(self.note, self.length) elif self.soundType == 'square': Hit.cache[key] = source.square(self.note, self.length) elif self.soundType == 'sawtooth': Hit.cache[key] = source.sawtooth(self.note, self.length) else: Hit.cache[key] = source.sine(self.note, self.length) return Hit.cache[key]
def render(self): """Render hit of "key" for "length" amound of seconds""" key = (str(self.note), self.length) if key not in Hit.cache: Hit.cache[key] = source.square(self.note, self.length) return Hit.cache[key]
import numpy from musical.theory import Note, Scale from musical.audio import source, playback # Define key and scale key = Note('C4') scale = Scale(key, 'major') note = key chunks = [] for i in xrange(len(scale)): third = scale.transpose(note, 2) chunks.append(source.sine(note, 0.5) + source.square(third, 0.5)) note = scale.transpose(note, 1) fifth = scale.transpose(key, 4) chunks.append(source.sine(key, 1.5) + source.square(fifth, 1.5)) print "Rendering audio..." data = numpy.concatenate(chunks) # Reduce volume to 50% data = data * 0.5 print "Playing audio..." playback.play(data) print "Done!"