def play_interval(self, interval): # Finds 2 note frequencies in Hz with the given configuration if self.is_up is None: direction = random.choice([-1, 1]) else: direction = 1 if self.is_up else -1 note1 = lz.MIDI_A4 + random.randint(-15, 5) # Semitones (MIDI pitch) note2 = note1 + interval * direction freq1 = lz.midi2freq(note1) * Hz freq2 = lz.midi2freq(note2) * Hz # Creates the audio generators for each note audio1 = SYNTH_ENVELOPE * synth_table(freq1) audio2 = SYNTH_ENVELOPE * synth_table(freq2) # Play it in another thread audio = lz.chain(audio1, audio2, SYNTH_PAUSE_AT_END) player.play(audio, rate=rate)
def makeit(midipitches, rhythm, truetempo, tunenumber): frequencies = [] for i in range(len(midipitches)): frequencies.append(midi2freq(midipitches[i])) times = [] for j in range(len(rhythm)): times.append((60 / truetempo) * 4 * rhythm[j]) thestring = "OHz=[" for k in range(len(frequencies)): thestring = thestring + " " + str(frequencies[k]) thestring = thestring + ";" for l in range(len(times)): thestring = thestring + " " + str(times[l]) thestring = thestring + "]" print(thestring) tunenumber += 1 with open("tunes/matricies/tune" + str(tunenumber) + ".txt", "w") as matrix_file: matrix_file.write(thestring)
""" from audiolazy import (str2midi, midi2freq, saw_table, sHz, Streamix, Stream, line, AudioIO, chunks) import sys try: import tkinter except ImportError: import Tkinter as tkinter keys = "awsedftgyhujkolp;" # Chromatic scale first_note = str2midi("C3") pairs = list(enumerate(keys.upper(), first_note + 12)) + \ list(enumerate(keys, first_note)) notes = {k: midi2freq(idx) for idx, k in pairs} synth = saw_table txt = """ Press keys W E T Y U O P A S D F G H J K L ; The above should be seen as piano keys. Using lower/upper letters changes the octave. """
def GenerateOpenSCAD(var, cs, SA, HL, pipe, TU, SD, M, F, T): SEGMENTS = 48 # solidpython variable for midinr in var: inputorder = var.index(midinr) f = midi2freq(int(midinr)) # get frequency by midi nr WL = cs / f # wavelength in mm ILA = WL / 2 # internal length L69 = ((cs / midi2freq(69)) / 2) # internal length of midi nr 69 IW = L69 * 2**((69 - int(midinr)) / M) / 12 # internal width IL = cs / (2 * f) # calculate internal length def openclosedmeasurements(): if pipe == "Closed": l = 0.52 * IL + IW + F mh = (3.018 - (0.233 * (math.log(f))))**5 return l, mh elif pipe == "Open": l = 1.03 * IL - IW + F mh = 550 / 2**(math.log(f)) return l, mh L, MH = openclosedmeasurements() # L = length; MH=Mouth Height a, b, c, A, B, C = solve(a=T - HL, A=SA * degree, B=90 * degree) LL = c # length labium Wb = IW + 2 * T # width back Ws = IW # width sides BPl = F + IW # bottom plug length BPw = IW # bottom plug width BPt = IW # bottom plug thickness Cl = F + IW # cover length Cw = IW + 2 * T # cover width Gl = F + 2 * IW # gasket length Gw = IW + 2 * T # gasket width Fl = L - MH - F - IW # Front length if inputorder == 0: startpoint = 0 scadcode = assembly(startpoint, Wb, L, T, Ws, Cw, Cl, Fl, HL, LL, IW, TU, SD, pipe) startpoint = 2 * Wb + 2 * Ws + IW + 5 * 10 else: scadcode = scadcode.add( assembly(startpoint, Wb, L, T, Ws, Cw, Cl, Fl, HL, LL, IW, TU, SD, pipe)) startpoint = startpoint + (2 * Wb + 2 * Ws + IW + 5 * 10) scad_string_dirty = scad_render(scadcode) scad_string = scad_string_dirty.replace( scad_string_dirty[scad_string_dirty.find("<") + 1:scad_string_dirty.find(">")], basename(scad_string_dirty[scad_string_dirty.find("<") + 1:scad_string_dirty.find(">")])) static_directory = '/static' out_dir = os.getcwd() + static_directory in_memory = io.BytesIO() z = zipfile.ZipFile(in_memory, 'w', zipfile.ZIP_DEFLATED) z.writestr('pipes.scad', scad_string) z.write(os.path.join(out_dir, "prism.scad"), "prism.scad") z.close() in_memory.seek(0) return (in_memory)
inoisy_thub = thub(inoisy_stream.append(0).limit(beat_duration), starting_beats) inoisy = chain.from_iterable(repeat(inoisy_thub).limit(starting_beats)) smix.add(.1 * s, inoisy) smix.add(starting_beats * beat_duration - dur, []) # Event timing # Wavetable lookup initialization square_table = TableLookup([1] * 256 + [-1] * 256) harmonics = dict(enumerate([1, 3, 2, 1, .3, .1, .7, .9, 1, 1, .5, .4, .2], 1)) table = sin_table.harmonize(harmonics).normalize() mem_table = (3 * saw_table + (sin_table - saw_table) ** 3).normalize() # Notes synth midi_tuning = str2midi([gs.tune for gs in guitar]) midi_pitches = [midi_tuning[string_idx] + fret for string_idx, fret in notes] for freq in midi2freq(midi_pitches): ks_memory = .1 * gauss_noise() + .9 * mem_table(freq * Hz) ks_snd = distortion(karplus_strong(freq * Hz, tau=.2 * s, memory=ks_memory)) tl_snd = .5 * table(freq * Hz) * env smix.add(dur, .5 * ks_snd + .5 * tl_snd) # Shows synthesis wavetables pylab.subplot(2, 1, 1) pylab.plot(table.table) pylab.title("Table lookup waveform") pylab.axis(xmax=len(table) - 1) pylab.subplot(2, 1, 2) pylab.plot(mem_table.table) pylab.title("Karplus-strong memory (besides noise)")
inoisy_thub = thub( inoisy_stream.append(0).limit(beat_duration), starting_beats) inoisy = chain.from_iterable(repeat(inoisy_thub).limit(starting_beats)) smix.add(.1 * s, inoisy) smix.add(starting_beats * beat_duration - dur, []) # Event timing # Wavetable lookup initialization square_table = TableLookup([1] * 256 + [-1] * 256) harmonics = dict(enumerate([1, 3, 2, 1, .3, .1, .7, .9, 1, 1, .5, .4, .2], 1)) table = sin_table.harmonize(harmonics).normalize() mem_table = (3 * saw_table + (sin_table - saw_table)**3).normalize() # Notes synth midi_tuning = str2midi([gs.tune for gs in guitar]) midi_pitches = [midi_tuning[string_idx] + fret for string_idx, fret in notes] for freq in midi2freq(midi_pitches): ks_memory = .1 * gauss_noise() + .9 * mem_table(freq * Hz) ks_snd = distortion(karplus_strong(freq * Hz, tau=.2 * s, memory=ks_memory)) tl_snd = .5 * table(freq * Hz) * env smix.add(dur, .5 * ks_snd + .5 * tl_snd) # Shows synthesis wavetables pylab.subplot(2, 1, 1) pylab.plot(table.table) pylab.title("Table lookup waveform") pylab.axis(xmax=len(table) - 1) pylab.subplot(2, 1, 2) pylab.plot(mem_table.table) pylab.title("Karplus-strong memory (besides noise)") pylab.axis(xmax=len(mem_table) - 1)