DEV Community

Cover image for TinEAR, using GA for music inspiration
Paula
Paula

Posted on

TinEAR, using GA for music inspiration

I'm very interested in art experimentation as well as tech and sustainability. I recently participated in a live programming workshop meant for music creation. One of the guys conducting the workshop mentioned the fact of slight imperfections (usually not noticeable by the human regular ear) of human artists against programmed music. Somehow this made me think of how some imperfections lead to more interesting works than the one that was previously attempted. How could I work around a terminal toy that was "imperfect" in its attempts to play music?

I'm very interested in sustainability and de-escalating tech resources, so I refused to work towards AI, but I thought of working with GA. The idea is for the toy to attempt to reach a collection of notes, each attempt more close, but not quite until it reaches the correct ones.

In order to do this I chose python3 and a very simple GA structure, the same that would try to guess a word.

This is an example usage:

python3 tinear.py
TARGET: AABC
MAXIMUN GENERATIONS ALLOWED: 7

Generation: 1   String: AACC    Fitness: 1
Generation: 2   String: AABC    Fitness: 0
Enter fullscreen mode Exit fullscreen mode

In this case it was lucky and guessed the right one the second time (generation 2). In order to play music directly from the terminal, I use os.system defining a command with variable chords (the ones asked to the user at the execution) and play -n synth pl.

The result is that each guess, the terminal plays the attempting tune, making it fun when doing some live coding jams.

I mixed the tinear attempts with some synthesizer tunes using teenage engineering devices and created some imperfect, yet fun music! You can find the script here.

Top comments (4)

Collapse
 
cicirello profile image
Vincent A. Cicirello

Look up Al Biles and GenJam. Al Biles is a retired computer science professor who is also a jazz trumpeter. Before he retired, his research included genetic algorithms. His GenJam (Genetic Jammer) uses genetic algorithms for jazz improvisation. He'd perform playing trumpet, with GenJam accompanying him by improvising other instruments. He actually auditioned for America's Got Talent with GenJam several years ago, the round with producers before the round they show on tv. He has a clip of it though. I forget if it is on his website or youtube, or if it is within one of his talks about GenJam.

Collapse
 
terceranexus6 profile image
Paula

This is amazing and very close to what I experimented around with! I will take a look around, I'm sure I will be able to find his stuff

Collapse
 
michaeltharrington profile image
Michael Tharrington

Awesome post, Paula!

This bit:

One of the guys conducting the workshop mentioned the fact of slight imperfections (usually not noticeable by the human regular ear) of human artists against programmed music. Somehow this made me think of how some imperfections lead to more interesting works than the one that was previously attempted.

Reminds me of a video I watched not too long ago on YouTube that talked about the making Earth, Wind & Fire's "September" (appropriate timing 🙂) and how they made a "mistake" with the bass playing. Earth, Wind & Fire made music in the 70's and it's full of little human mistakes — the groove moves naturally. The song "September" was rerecorded by Justin Timerblake & Anna Kendrick for the movie Trolls in 2016 and because it was recorded with modern techniques, it's more locked into perfection and doesn't ebb and flow as much... which just doesn't feel as human. Check the explanation in the video!

Also, if you like this YouTuber and this video, he talks about the concept of "groove grids" and how the modern, machine-perfected music compares to old-school human-made music. The video is about a musician named J Dilla who used drum machines in an interesting way to get more human-like imperfections... it's pretty dang cool!

Anyway, aside from all these music Youtube suggestions I'm throwing your way, I really dig that you're exploring how to make "imperfect" music with your terminal. Such a cool idea!

Collapse
 
terceranexus6 profile image
Paula

Wow this is so cool I didn't know about this!! Thanks for the tip, I think I can get inspired