def TEST1(): """ Returns a 16-bit string audio waveform to test Mary Had a Little Lamb""" note_names = ["E4", "D4", "C4", "D4", "E4", "E4", "E4", "E4", "D4", "D4", "D4", "D4", "E4", "G4", "G4", "G4"] chords = [songsmith.Chord(notes=[songsmith.Note(songsmith.nametofreq(name),0.5,16000)]) for name in note_names] song = songsmith.Phrase(chords) song.addovertones(5) return str(song)
def TEST2(): """ Returns a 16-bit string audio waveform to test musical chords""" song = songsmith.Phrase(chords=[ songsmith.Chord(notes=[ songsmith.Note(songsmith.nametofreq("C4"), 0.5, 8000) ]), songsmith.Chord(notes=[ songsmith.Note(songsmith.nametofreq("C4"), 0.5, 8000), songsmith.Note(songsmith.nametofreq("E4"), 0.5, 8000) ]), songsmith.Chord(notes=[ songsmith.Note(songsmith.nametofreq("C4"), 0.5, 8000), songsmith.Note(songsmith.nametofreq("E4"), 0.5, 8000), songsmith.Note(songsmith.nametofreq("G4"), 0.5, 8000) ]), songsmith.Chord(notes=[ songsmith.Note(songsmith.nametofreq("C4"), 1.5, 8000), songsmith.Note(songsmith.nametofreq("E4"), 1.5, 8000), songsmith.Note(songsmith.nametofreq("G4"), 1.5, 8000), songsmith.Note(songsmith.nametofreq("C5"), 1.5, 8000) ]) ]) song.addovertones(5) return str(song)
def generate(self, length=100): song = songsmith.Phrase() lastindices = [[0] for i in range(self.search_depth)] for i in range(length): currentindices = [] # Pick the next note choices = [] for depth, indices in enumerate(lastindices): for index in indices: choices.extend(self.patterns[index]["next"][depth]) currentindices.append(random.choice(choices)) # Generate the next chord c = songsmith.Chord(notes=[]) duration = random.choice(self.patterns[currentindices[0]]["durations"]) for index in currentindices: freq = 0 if self.patterns[index]["name"] == "" else songsmith.nametofreq(self.patterns[index]["name"] + "4") amplitude = 0 if self.patterns[index]["name"] == "" else 16000 c.notes.append(songsmith.Note(freq,duration,amplitude)) c.addovertones(5) # Update the lastindices for the next loop lastindices.pop() lastindices.insert(0, currentindices) song.chords.append(c) return song