Processing math: 100%

Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome, Safari or Firefox browser.

Evolving your own music for fun and no profit

Vik Paruchuri

DataQuest (www.dataquest.io)

vik.paruchuri@gmail.com

What's evolving music?

  • Take existing music
  • Learn patterns from it
  • Use the knowledge to make new music
  • Judge your new music

Why?

  • Because it's cool
  • See above reason

Listen in

  • Sample tracks: 1 2 3

Midi format

[midi.ProgramChangeEvent(tick=0, channel=0, data=[0]),
midi.NoteOffEvent(tick=20, channel=9, data=[42, 64]),
midi.NoteOnEvent(tick=28, channel=9, data=[38, 90]),
midi.NoteOnEvent(tick=0, channel=9, data=[42, 90]),
midi.NoteOffEvent(tick=20, channel=9, data=[38, 64]),
midi.NoteOffEvent(tick=0, channel=9, data=[42, 64]),
midi.NoteOnEvent(tick=28, channel=9, data=[42, 70]),
midi.NoteOffEvent(tick=20, channel=9, data=[35, 64]),
midi.NoteOffEvent(tick=0, channel=9, data=[42, 64]),
midi.NoteOnEvent(tick=28, channel=9, data=[42, 58]),
midi.EndOfTrackEvent(tick=0, data=[])]

MIDI stored as byte code

midi

Python-midi to the rescue!

Step 1: ACQUIRE MUSIC

Step 2: Render tracks

  • MIDI has to be "rendered"
  • Output to .ogg files

Step 45: Markov chain everything!

Markov chain

Construct chains

  • Make matrices for pitch, velocity, tick per-instrument
  • Rows and columns are numbers
  • Cells contain # of transitions from row state to column state

Note "phrases"

  • Music has structure
  • Phrases are basic units of it
  • I have almost no music theory experience
  • Let me know after if I'm wrong
  • Pull out sequences of 8 notes

Making a track

  • Select the instrument
  • Randomly select a starting phrase
  • Use markov chains to pick next phrase
  • Repeat until specified length

Making a song

  • Pick instruments that are good together
  • Put tracks from those instruments together
  • Add a tempo track

Evaluating song

  • Render midi to ogg file
  • Use fluidsynth, oggenc, and sox

Look at the audio

audio

Read audio in

[2.35185598e051.04448336e053.46823663e063.73403673e052.69492170e061.44758296e059.47549870e062.09419904e052.70856035e053.44590421e063.01332675e052.74870854e051.44664727e067.49632018e053.80197125e052.56412422e055.61815832e051.29676855e054.73532873e063.69851950e05]

Feature calculation

  • Calculate a bunch of features
  • Split song into "bins"
  • ZCR, slope, peak count, and many more
  • 154 in all
  • Put into matrix

Scoring songs

  • Compare generated song with existing songs
  • Used random forest at one point to predict
  • Simpler to use cosine distance
  • Lower distance is better

Semi-genetic algorithm

  • Create candidate songs
  • Score them all
  • Pick the best ones
  • Remix songs by swapping tracks
  • Generate some new songs

Generations

  • Evolve multiple generations
  • Try to minimize distance from existing songs
  • Algorithm finds local minimum quickly
  • More than 3 generations gets duplicate "best" song

Ways to make it better

  • Hand-label some songs, and use them for supervised learning
  • Get more training data
  • Generate better features
  • Do more in the genetic algorithm than just remix

Open source