├── Piano.mid ├── Woodblock.mid ├── README.md └── shepard_tone.py /Piano.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evpu/Shepard-tone-music21/HEAD/Piano.mid -------------------------------------------------------------------------------- /Woodblock.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evpu/Shepard-tone-music21/HEAD/Woodblock.mid -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Shepard tone with music21 (Python) 2 | 3 | "A Shepard tone is an auditory illusion of a tone that continually ascends or descends in pitch, yet which ultimately seems to get no higher or lower." [(wiki)](https://en.wikipedia.org/wiki/Shepard_tone) 4 | 5 | A great explanation is available in [this youtube video](https://www.youtube.com/watch?v=LVWTQcZbLgY). 6 | 7 | The code creates three tracks with notes moving up the scale in C major. Each track is separated by two octaves. In the higher track, the volume gradually decreases. In the middle track, the volume stays constant. In the lower track, the volume gradually increases. The final result is created by overlapping and looping over these three tracks. 8 | 9 | MIDI files: 10 | 11 | [(Piano)](https://raw.githubusercontent.com/evpu/Shepard-tone-music21/master/Piano.mid) 12 | [(Woodblock)](https://raw.githubusercontent.com/evpu/Shepard-tone-music21/master/Woodblock.mid) 13 | -------------------------------------------------------------------------------- /shepard_tone.py: -------------------------------------------------------------------------------- 1 | # ************************************************************************ 2 | # Shepard tone with music21 3 | # https://github.com/evpu 4 | # ************************************************************************ 5 | 6 | import os 7 | from music21 import stream, instrument 8 | from music21.note import Note 9 | 10 | print(os.getcwd()) 11 | os.chdir('.') # set working directory 12 | 13 | loop = 10 14 | length = 0.5 15 | 16 | # Highest octave, volume gets lower 17 | shepard_tone_u = stream.Part() 18 | shepard_tone_u.insert(0, instrument.Piano()) 19 | c_major = ['C#5', 'D#5', 'E#5', 'F#5', 'G#5', 'A#5', 'B#5', 'C#6', 'D#6', 'E#6', 'F#6', 'G#6', 'A#6', 'B#6'] 20 | for l in range(loop): 21 | volume_increment = 0 22 | for i in c_major: 23 | n = Note(i, quarterLength=length) 24 | n.volume.velocityScalar = 0.7 - volume_increment 25 | shepard_tone_u.append(n) 26 | volume_increment = volume_increment + 0.05 27 | 28 | # Middle octave, volume constant 29 | shepard_tone_m = stream.Part() 30 | shepard_tone_m.insert(0, instrument.Piano()) 31 | c_major = ['C#3', 'D#3', 'E#3', 'F#3', 'G#3', 'A#3', 'B#3', 'C#4', 'D#4', 'E#4', 'F#4', 'G#4', 'A#4', 'B#4'] 32 | for l in range(loop): 33 | for i in c_major: 34 | n = Note(i, quarterLength=length) 35 | shepard_tone_m.append(n) 36 | 37 | # Lowest octave, volume gets higher 38 | shepard_tone_l = stream.Part() 39 | shepard_tone_l.insert(0, instrument.Piano()) 40 | c_major = ['C#1', 'D#1', 'E#1', 'F#1', 'G#1', 'A#1', 'B#1', 'C#2', 'D#2', 'E#2', 'F#2', 'G#2', 'A#2', 'B#2'] 41 | for l in range(loop): 42 | volume_increment = 0 43 | for i in c_major: 44 | n = Note(i, quarterLength=length) 45 | n.volume.velocityScalar = 0.05 + volume_increment 46 | shepard_tone_l.append(n) 47 | volume_increment = volume_increment + 0.05 48 | 49 | 50 | shepard_tone = stream.Stream([shepard_tone_u, shepard_tone_m, shepard_tone_l]) 51 | 52 | shepard_tone.write('midi', 'Piano.mid') 53 | --------------------------------------------------------------------------------