def playtonesvol(imu): notes = [Note('C6'), Note('C3')] amp = 0.5 #Amplitude sine = source.sine(notes[0], 1) arr = numpy.array(sine) thrd = None while True: src = source.sine(notes[0], 1)*0 acc = imu.getacc() #print "acc is {}".format(acc) ax, ay, az = acc if ax > 1.5: src+=source.sine(notes[0], 1) elif ax < -1.5: src+=source.sine(notes[1], 1) #volume buckets [-9<=, -8, ..., 0, ..., 8, 9>= ] vol = ay if vol <= -9: vol = -9 elif vol >= 9: vol = 9 vol = (vol + 9)/18.0 #shift and normalize data = numpy.array(src) * vol if thrd == None or not thrd.isAlive(): thrd = threading.Thread(target=play, args=(data,)) thrd.start()
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: #Hit.cache[key] = source.pluck(self.note, self.length) #Hit.cache[key] = source.square(self.note, self.length) Hit.cache[key] = source.sine(self.note, self.length) return Hit.cache[key]
def organ_sound(freq, time): """get sound font of a church organ by layering the first 32 harmonics with correct scaling on top of each other""" frequencies = [] sinewave = 0 harmonic_scalings = get_organ_harmonic_scalings() amplitude_scaling = 1 / 350000000 # anti-saturation for i, harmonic_scaling in enumerate(harmonic_scalings): frequencies.append((i + 1) * freq) sinewave += sine(frequencies[i], time) * convert_from_db(harmonic_scaling) return sinewave * amplitude_scaling
def playtones(imu): notes = [Note('C6'), Note('C5'), Note('C4'), Note('C3')] amp = 0.5 #Amplitude sine = source.sine(notes[0], 1) arr = numpy.array(sine) thrd = None while True: src = source.sine(notes[0], 1)*0 acc = imu.getacc() #print "acc is {}".format(acc) ax, ay, az = acc if ax > 1.5: src+=source.sine(notes[0], 1) elif ax < -1.5: src+=source.sine(notes[1], 1) if ay > 1.5: src+=source.sine(notes[2], 1) elif ay < -1.5: src+=source.sine(notes[3], 1) data = numpy.array(src) * amp if thrd == None or not thrd.isAlive(): thrd = threading.Thread(target=play, args=(data,)) thrd.start()
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_note(note): print "Rendering %r" % note note_data = source.sine(note.frequency(), NOTE_LENGTH) * 0.2 for i in xrange(len(note_data)): note_data[i] *= 1.0 - (float(i) / len(note_data)) factor = 1.0 data = note_data for i in xrange(ECHO_TIMES): factor *= ECHO_DECAY data = numpy.append(data, note_data * factor) fname = "out/%s%d.wav" % (note.note, note.octave) save.save_wave(data, fname) return fname
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!"
import numpy from musical.theory import Note, Scale from musical.audio import source, playback # Define key and scale key = Note('D3') scale = Scale(key, 'major') note = key chunks = [] for i in xrange(len(scale)/3): third = scale.transpose(note, 2) chunks.append(source.sine(note, 0.5) + source.pluck(third, 0.5)) note = scale.transpose(note, 1) fifth = scale.transpose(key, 4) chunks.append(source.sine(key, 1.5) + source.pluck(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!"