Sunday, February 21, 2016

5. Intervals

Note "C3", midi 60, is the base note.


13 intervals, from 0 semitones to 12 semitones are created. A difference of 12 semitones is an octave, and a difference of 7 semitones yields the perfect fifth.


The interval function creates the different spaced notes. Note they have identical start time, duration time, and volume. We could randomize it slightly to humanize the notes.


The printouts will show which semitone is being created. The perfect fifth should give the most consonant note.


# mus5.py
# Intervals

from writeMIDI import writeMIDI

# beats per minute
bpm = 130

notes = []

def interval(start,val):
    notes.append((60,start,1,112))
    notes.append((60+val,start,1,112))

for i in range(13):
    print("Creating interval of {} semitones".format(i))
    diff = 2**(i/12)
    print("Frequency ratio difference of {:.2f}".format(diff))
    print()
    interval(2*i,i)

key = 'C'
writeMIDI(key,"piano",bpm,notes,'mus5')

PrintOut:


Creating interval of 0 semitones
Frequency ratio difference of 1.00

Creating interval of 1 semitones
Frequency ratio difference of 1.06

Creating interval of 2 semitones
Frequency ratio difference of 1.12

Creating interval of 3 semitones
Frequency ratio difference of 1.19

Creating interval of 4 semitones
Frequency ratio difference of 1.26

Creating interval of 5 semitones
Frequency ratio difference of 1.33

Creating interval of 6 semitones
Frequency ratio difference of 1.41

Creating interval of 7 semitones
Frequency ratio difference of 1.50

Creating interval of 8 semitones
Frequency ratio difference of 1.59

Creating interval of 9 semitones
Frequency ratio difference of 1.68

Creating interval of 10 semitones
Frequency ratio difference of 1.78

Creating interval of 11 semitones
Frequency ratio difference of 1.89

Creating interval of 12 semitones
Frequency ratio difference of 2.00

This will generate this for piano roll for mus5.mid:


No comments:

Post a Comment