def worker(): player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=0.7, use_osc2=False) return player.play_wave( synthesizer.generate_constant_wave(areatone, 0.14))
def __init__(self, pre=["C3", "E3", "G3"], post=["C3", "D3", "F3"]): self.pre = pre self.post = post self.player = Player() self.player.open_stream() self.synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False)
def __init__(self, oscillator): """ Instantiate the synthesizer and the player Parameters ---------- oscillator : str defines the shape of the Waveform """ self.player = Player() self.synthesizer = Synthesizer(osc1_waveform=WAVEFORM[oscillator])
def play_progression(chords, timings): player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=True, osc2_waveform=Waveform.sawtooth, osc2_freq_transpose=2.0) #play all notes :) for (i, _), duration in zip(chords, timings): if i == 'rest': time.sleep(RATE / 8) print('rest') else: print('chord : {} timing : {}'.format(i, duration * RATE)) simalt_notesplay(player, i, duration, synthesizer)
def playVoice(notes): player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.triangle, osc1_volume=1.0, use_osc2=False) for note in notes: player.play_wave(synthesizer.generate_constant_wave(synth(note), .5))
def play(chord): player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=0.4, use_osc2=False) player.play_wave(synthesizer.generate_chord(chord, 1))
class AudioDebug: def __init__(self, pre=["C3", "E3", "G3"], post=["C3", "D3", "F3"]): self.pre = pre self.post = post self.player = Player() self.player.open_stream() self.synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False) def play_chord(self, chord): self.player.play_wave(self.synthesizer.generate_chord(chord, 0.5)) def __call__(self, func): def logic(*args, **kwargs): print('pre') self.play_chord(self.pre) result = func(*args, **kwargs) print('post') self.play_chord(self.post) return result return logic
def play_beat(t): player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.sawtooth, osc1_volume=1.0, use_osc2=False) for i in range(int(t / RATE)): player.play_wave(synthesizer.generate_chord(['A3'], 0.1)) time.sleep(float(RATE - 0.1))
def eeg_callback(self, path, args): lE, lF, rF, rE = args print "%s %f %f %f %f" % (path, lE, lF, rF, rE) player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False) number = ra.uniform(0.2, 1.0) player.play_wave( synthesizer.generate_constant_wave((lF - 1200) * ((600 - 200) / (1200 - 750)) + 200), number) player.play_wave( synthesizer.generate_constant_wave((rF - 1200) * ((600 - 200) / (1200 - 750)) + 200), number)
def play_progression(progression): player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=10.0, use_osc2=False) for measure in progression: for chord in measure: player.play_wave( synthesizer.generate_chord(chord[0], abs(chord[1])))
def consumer(queue): player = Player() player.open_stream() while True: tone = queue.get() if tone is None: break player.play_wave(tone)
def playPiece(lines: List[TemporalisedLine]): mapping, indexLines = asUniqueValues(lines) lowerLines = indexLines[0:-1] upperLine = indexLines[-1] sm = makeSimMap(lowerLines, upperLine) player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.triangle, osc1_volume=1.0, use_osc2=False) for k in upperLine[0][:-1]: toPlay = [synth(mapping[n]) for n in sm[k].union([k])] player.play_wave(synthesizer.generate_chord([n for n in toPlay], 1 / len(lines))) # Play last note longer k = upperLine[0][-1] toPlay = [synth(mapping[n]) for n in sm[k].union([k])] player.play_wave(synthesizer.generate_chord([n for n in toPlay], 2 / len(lines)))
def main(): args = parse_args() chords = ChordProgression(args.chord) player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.triangle, osc1_volume=1.0, use_osc2=False) for chord in chords: notes = chord.components_with_pitch(root_pitch=3) print("Play {}".format(chord)) player.play_wave(synthesizer.generate_chord(notes, 1.0))
def main(protein_sequence): """Plays musical protein sequence.""" # Create dictionary that will map each amino acid to the various musical properties association = {} # Generate association between amino acid and musical properties association.update(get_association(protein_sequence, hydrophobic_aa, hydrophobic_chords, 'square')) association.update(get_association(protein_sequence, less_hydrophobic_aa, less_hydrophobic_notes, 'sine')) association.update(get_association(protein_sequence, non_hydrophobic_aa, non_hydrophobic_chords, 'sawtooth')) # Create Player and Synthesizer objects to be used when playing protein sequence player = Player() player.open_stream() synthesizer = { 'polar': { 'sine': Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False), 'sawtooth': Synthesizer(osc1_waveform=Waveform.sawtooth, osc1_volume=1.0, use_osc2=False), 'square': Synthesizer(osc1_waveform=Waveform.sawtooth, osc1_volume=1.0, use_osc2=False) }, 'nonpolar': { 'sine': Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=0.5, use_osc2=False), 'sawtooth': Synthesizer(osc1_waveform=Waveform.sawtooth, osc1_volume=0.5, use_osc2=False), 'square': Synthesizer(osc1_waveform=Waveform.sawtooth, osc1_volume=0.5, use_osc2=False) }, } # writer = Writer() # sounds = [] # Loop through and play out each amino acid in the protein sequence for idx, aa in enumerate(protein_sequence): if aa not in association: continue note, instrument, volume, length = association[aa] length = length if idx != len(protein_sequence) - 1 else 0.5 # Set length of last note to be 0.5s if type(note) == list: # Play chord sound = synthesizer[volume][instrument].generate_chord([notes[n] for n in note], length) print_notes(note, aa) else: # Play single note sound = synthesizer[volume][instrument].generate_constant_wave(notes[note], length) print_notes([note], aa) player.play_wave(sound)
# Define variable wait_time = 0 measures = 0 beats = 4 drumlist = [] notelist = [] counter = 0 seqloc = [1, 1, 1] drum_ready = 0 synth_ready = 0 notes = ['a', 'ais', 'b', 'c', 'cis', 'd', 'dis', 'e', 'f', 'fis', 'g', 'gis'] hertz = 0 # Initialise synth player = Player() player.open_stream() synth = Synthesizer(osc1_waveform=Waveform.triangle, osc1_volume=0.2, osc2_freq_transpose=0.48, use_osc2=True, osc2_waveform=Waveform.triangle, osc2_volume=0.1) # Define midi variables degrees = [] # MIDI note number for drums degreesn = [] #MIDI note number for notes track = 0 trackn = 1 channel = 0 time = [0] # In beats timen = [0] duration = 1 # In beats tempo = 60 # In BPM volume = 100 # 0-127, as per the MIDI standard
from synthesizer import Player, Synthesizer, Waveform player = Player() player.open_stream() # 以下をexcelからコピペする arr = [(523, 0.375), (0, 0.0535714285714286), (523, 0.428571428571429), (784, 0.375), (0, 0.0535714285714286), (784, 0.428571428571429), (880, 0.375), (0, 0.0535714285714286), (880, 0.428571428571429), (784, 0.857142857142857), (698, 0.375), (0, 0.0535714285714286), (698, 0.428571428571429), (659, 0.375), (0, 0.0535714285714286), (659, 0.428571428571429), (587, 0.375), (0, 0.0535714285714286), (587, 0.428571428571429), (523, 0.857142857142857)] arr = [(659, 0.4), (494, 0.2), (523, 0.2), (587, 0.4), (523, 0.2), (494, 0.2), (440, 0.35), (0, 0.05), (440, 0.2), (523, 0.2), (659, 0.4), (587, 0.2), (523, 0.2), (494, 0.35), (0, 0.05), (494, 0.2), (523, 0.2), (587, 0.4), (659, 0.4), (523, 0.4), (440, 0.3), (0, 0.1), (440, 0.6), (0, 0.4), (587, 0.4), (698, 0.2), (880, 0.4), (784, 0.2), (698, 0.2), (659, 0.35), (0, 0.05), (659, 0.2), (523, 0.2), (659, 0.35), (0, 0.05), (587, 0.2), (523, 0.2), (494, 0.35), (0, 0.05), (494, 0.2), (523, 0.2), (587, 0.4), (659, 0.4), (523, 0.4), (440, 0.35), (0, 0.05), (440, 0.8)] synth = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False) for p in arr: player.play_wave(synth.generate_constant_wave(p[0], p[1]))
for n in note_range: if n in note: note_string += n else: note_string += ' ' print(note_string) association.update(get_association(protein_sequence, hydrophobic_aa, major_chords)) association.update(get_association(protein_sequence, less_hydrophobic_aa, single_notes)) association.update(get_association(protein_sequence, part_hydrophobic_aa, extra_chords, 'sawtooth')) association.update(get_association(protein_sequence, non_hydrophobic_aa, minor_chords)) # print(association) player = Player() player.open_stream() synthesizer = { 'sine': Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False), 'sawtooth': Synthesizer(osc1_waveform=Waveform.sawtooth, osc1_volume=1.0, use_osc2=False) } for idx, aa in enumerate(protein_sequence): note, instrument = association[aa] length = 0.2 if idx != len(protein_sequence) - 1 else 1 if type(note) == list: sound = synthesizer[instrument].generate_chord([notes[n] for n in note], length) print_notes(note) else:
class MelodyPlayer(object): """ A class used to play the melody generated by Melody Attributes ---------- player : Player an object that plays the melody synthesizer : Synthesizer an object that characterizes the sound of the melody """ def __init__(self, oscillator): """ Instantiate the synthesizer and the player Parameters ---------- oscillator : str defines the shape of the Waveform """ self.player = Player() self.synthesizer = Synthesizer(osc1_waveform=WAVEFORM[oscillator]) def play_melody(self, melody, bpm): """ Plays the melody in a certain bpm Parameters ---------- melody : Melody the melody that will be played bpm : int beats per minute that determine the speed the melody is played """ self.player.open_stream() for note in melody.notes: wave_sound = self.generate_waves(note, bpm) self.player.play_wave(wave_sound) def save_melody(self, melody, bpm): """ Saves the melody as WAV Saves each note individually and then concatenate then in a sigle WAV file Parameters ---------- melody : Melody the melody that will be played bpm : int beats per minute that of the melody """ writer = Writer() outfile = "melody.wav" next_note = "note.wav" data = [] for note in melody.notes: sound = self.generate_waves(note, bpm) if note == melody.notes[0]: # Generates the first note writer.write_wave(outfile, sound) continue writer.write_wave(next_note, sound) infiles = [outfile, next_note] for infile in infiles: with wave.open(infile, 'rb') as w: data.append([w.getparams(), w.readframes(w.getnframes())]) self.append_note(outfile, data) # Deletes the note file os.remove(next_note) @staticmethod def append_note(outfile, data): """ Auxiliary method for save_melody Code found on https://bit.ly/2EoFjIU Parameters ---------- outfile : str path to output file data : list an array of WAV parameters """ with wave.open(outfile, 'wb') as output: output.setparams(data[0][0]) output.writeframes(data[0][1]) output.writeframes(data[1][1]) data.clear() def generate_waves(self, note, bpm): """ Generate the wave that represents a note Parameters --------- note : MusicalNote The note that will be turned into wave bpm : int beats per minute that determines the lenght Returns ------- ndarray an array that represents the normalized wave """ lenght = note.lenght["duration"] / 16 * 60 / bpm # If the note is not played, the frequency is 0 frequency = note.note["frequency"] if note.is_played else 0 return self.synthesizer.generate_constant_wave(frequency, lenght)
def test_enumerate_device(): player = Player() player.enumerate_device() ok_("enumerate_device() succeeded.")
import pickle from synthesizer import Player, Synthesizer, Waveform import multiprocessing from my_functions import mama_isnt_home, bluesly, chromatic, theremin, deep_purple, plotting_notes import time player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=0.7, use_osc2=False) notes = [] timeout = time.time() + 35 #seconds 32-35 is ok print("Timer engaged") while True: # timer to break the loop if time.time() > timeout: print("Timer finished") break # try/except to avoid errors while writing and reading at the same time try: with open("../input/outfile_area", "rb") as fa: area_out = pickle.load(fa) areatone, note = deep_purple(area_out) print(areatone, " Hz") notes.append(note) player.play_wave(synthesizer.generate_constant_wave( areatone, 0.05)) #areatone,note = transforming_to_tones(area_out)
def main(): player = Player() player.open_stream() print("play major chord") synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False) chord = ["C4", "E4", "G4"] player.play_wave(synthesizer.generate_chord(chord, 3.0)) time.sleep(0.5) print("play minor chord") chord = ["C4", "Eb4", "G4"] player.play_wave(synthesizer.generate_chord(chord, 3.0)) time.sleep(0.5) print("play sus4 chord") chord = ["C4", "F4", "G4"] player.play_wave(synthesizer.generate_chord(chord, 3.0)) time.sleep(0.5) print("play 7th chord") chord = ["C4", "E4", "G4", "Bb4"] player.play_wave(synthesizer.generate_chord(chord, 3.0)) time.sleep(0.5) print("play add9 chord") chord = ["C4", "E4", "G4", "D5"] player.play_wave(synthesizer.generate_chord(chord, 3.0)) time.sleep(0.5) print("play chord sequence") chord = ["D4", "F4", "A4", "C5"] player.play_wave(synthesizer.generate_chord(chord, 1.0)) chord = ["D4", "G4", "B4"] player.play_wave(synthesizer.generate_chord(chord, 1.0)) chord = ["E4", "G4", "C5"] player.play_wave(synthesizer.generate_chord(chord, 1.0))
from synthesizer import Player, Synthesizer, Waveform p = Player() p.open_stream() s = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False) i = 0 while (i < 3): A = s.generate_constant_wave(88.0, 1.0) p.play_wave(A) i += 1
import pygame import pygame.midi as midi from midi import MidiConnector from synthesizer import Player, Synthesizer, Waveform import math player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.square, osc1_volume=1.0, use_osc2=True, osc2_waveform=Waveform.sawtooth, osc2_volume=0.5) pygame.midi.init() print(pygame.midi.get_device_info(1)) input_id = pygame.midi.get_default_input_id() print ("using input_id {}".format(input_id)) i = pygame.midi.Input( input_id ) val = 0 note_list = [] num_list = [] main_list = [[], []] def update_list(list_in, num_list, midi_dat): note_num = midi_dat[0][1] note = 2**((note_num-69)/12.0)*440 if(midi_dat[0][0] != 144): return list_in, num_list if(midi_dat[0][2] == 0):
import mido import time from synthesizer import Player, Synthesizer, Waveform, Oscillator """ Emergency sound maker for when Helm isn't working""" def midi_to_freq(note): a = 440 #frequency of A (common value is 440Hz) return (a / 32) * (2**((note - 9) / 12)) player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=0.25, use_osc2=False) oscillator = Oscillator(Waveform.sine, volume=0.25) prev_note = 440 with mido.open_input() as port: for message in port: if message.type == 'note_on': current_time = time.time() note = message.note freq = message.note * 10 print(message) player.play_wave(synthesizer.generate_constant_wave(freq, 0.01)) prev_note = message.note * 10
from synthesizer import Player, Synthesizer, Waveform import numpy as np player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.square, osc1_volume=1.0, use_osc2=True) blank = synthesizer.generate_constant_wave(0, 0.5) bass = synthesizer.generate_constant_wave(146.83, 0.5) synthesizer2 = Synthesizer(osc2_waveform=Waveform.square, osc2_volume=1.0, use_osc2=True) melodi = synthesizer.generate_constant_wave(261.63, 0.5) instrumenter = [blank, bass, melodi] grid = [[True, False], [False, True], [True, True], [False, True]] for takt in grid: for instrument in range(0, len(takt)): out = blank if takt[instrument] == True: out = out + instrumenter[instrument] if out.equals(blank): # Find ud af at sammenligne numpy arrays (type?) player.play_wave(out)
def digitalChime(number_of_notes): player = Player() synthesizer = Synthesizer(osc1_waveform=Waveform.sawtooth, osc1_volume=0.1, use_osc2=False) player.open_stream() #find base note base = random.randint(1, 6) time = random.randint(1, 4) * 0.25 octive = 1 sig = 3 #play this many notes for i in range(0, number_of_notes): next = random.randint(1, 6) print('| ', end='') if i % sig == 0: base = random.randint(1, 6) if base == 1: base = Notes['C4'] print('Cv ', end='♪ ') elif base == 2: base = Notes['D4'] print('Dv ', end='♪ ') elif base == 3: base = Notes['F4'] print('Fv ', end='♪ ') elif base == 4: base = Notes['G4'] print('Gv ', end='♪ ') elif base == 5: base = Notes['A4'] print('Av ', end='♪ ') else: base = Notes['C5'] print('C ', end='♪ ') base = (base / 2) * octive else: print('" ', end='♫ ') if next == 1: next = Notes['C4'] print('C ', end='') elif next == 2: next = Notes['D4'] print('D ', end='') elif next == 3: next = Notes['F4'] print('F ', end='') elif next == 4: next = Notes['G4'] print('G ', end='') elif next == 5: next = Notes['A4'] print('A ', end='') else: next = Notes['C5'] print('C^ ', end='') if i % (int)(8 / (time)) == 0: print(' | ', end='♫ ') sig = random.randint(2, 8) time = random.randint(2, 10) * 0.125 octive = random.randint(0, 2) if octive == 0: octive = 0.5 elif octive < 0: octive = 0.25 print(octive * 4, end=' ♪ ') print(time, end=' ♪\n') else: print(' |') next *= octive chord = [next, base] #print(octive) #print(time) player.play_wave(synthesizer.generate_chord(chord, time)) # player.play_wave(synthesizer.generate_constant_wave(next,0.5)) player.play_wave(synthesizer.generate_chord(chord, time * sig - 1))
def test_open_default_stream(): player = Player() player.open_stream() ok_("open_stream() succeeded.")
transcribed_music.append(less_hydrophobic_notes[amino_acids]) if amino_acids in part_hydrophobic_notes: transcribed_music.append(part_hydrophobic_notes[amino_acids]) if amino_acids in not_hydrophobic_chords: transcribed_music.append(not_hydrophobic_chords[amino_acids]) return transcribed_music most = most_hydrophobic_chords(aa_sequence) less = less_hydrophobic_notes(aa_sequence) part = part_hydrophobic_notes(aa_sequence) not_hy = not_hydrophobic_chords(aa_sequence) music_sheet = transcribed_music(aa_sequence) ##Set base values for instrument change, polar/nonpolar, size player = Player() player.open_stream() instrument1 = osc1_waveform = Waveform.square #main instrument instrument2 = osc1_waveform = Waveform.triangle #diff instrument volume1 = osc1_volume = 0.5 #nonpolar volume2 = osc1_volume = 1.0 #polar length = [0.1, 0.2, .3] #based on size from smallest to largest ##For loop plays out each individual chords or notes from transcribed music count = 0 for music in music_sheet: if music in chord_freq and aa_sequence[count] in small and aa_sequence[ count] in nonpolar: #Chords A-G & small print(aa_sequence[count]) synthesizer = Synthesizer(instrument1, \ volume1,use_osc2=False)
# https://pypi.org/project/synthesizer/ from synthesizer import Player, Synthesizer, Waveform import genome if __name__ == '__main__': player = Player() player.open_stream() synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False) w = 0.5 # weight for frequency transposition (0.5 = one octave lower) l = 0.05 # duration of each note nuc_freqs = { 'a': 440.00 * w, 'g': 392.00 * 2 * w, 'c': 523.25 * w, 't': 2793 * w } merge_repeated_nucleotides = True if (merge_repeated_nucleotides): for nuc_seg in genome.segments(): player.play_wave( synthesizer.generate_constant_wave(nuc_freqs[nuc_seg[0]], l * nuc_seg[1])) else:
def main(): player = Player() player.open_stream() print("play sine wave") synthesizer = Synthesizer(osc1_waveform=Waveform.sine, osc1_volume=1.0, use_osc2=False) player.play_wave(synthesizer.generate_constant_wave(440.0, 3.0)) time.sleep(0.5) print("play square wave") synthesizer = Synthesizer(osc1_waveform=Waveform.square, osc1_volume=0.8, use_osc2=False) player.play_wave(synthesizer.generate_constant_wave(440.0, 3.0)) time.sleep(0.5) print("play triangle wave") synthesizer = Synthesizer(osc1_waveform=Waveform.triangle, osc1_volume=0.8, use_osc2=False) player.play_wave(synthesizer.generate_constant_wave(440.0, 3.0)) time.sleep(0.5) print("play synthesized wave 1") synthesizer = Synthesizer( osc1_waveform=Waveform.sawtooth, osc1_volume=1.0, use_osc2=True, osc2_waveform=Waveform.sawtooth, osc2_volume=0.3, osc2_freq_transpose=6.0, ) player.play_wave(synthesizer.generate_constant_wave(440.0, 3.0)) time.sleep(0.5) print("play synthesized wave 2") synthesizer = Synthesizer( osc1_waveform=Waveform.square, osc1_volume=1.0, use_osc2=True, osc2_waveform=Waveform.sine, osc2_volume=0.3, osc2_freq_transpose=3.0, ) player.play_wave(synthesizer.generate_constant_wave(440.0, 3.0))