Music is the rhythm of the life
Music is a universal language. It has the ability to effortlessly transcend the opaque body, subtle mind, and invisible soul. At the end of a long hard-working day, listening to your favorite music composition can give a much-needed solace and fresh energy to look forward to dealing with life with a smile.
In this article, I focused on the following topics:
- Play and visualize Carnatic Music Ragas using Google Magenta library
- Generate Carnatic Music Raga notes using machine learning techniques
- Generate random Carnatic Music Raga notes with simple python scripts
Having learned the basics of Carnatic Music in my childhood, I always had the fascination to automate generating this ancient form of South Indian classical music. Hindustani Music is popular in North India. Indian film music is more popular nowadays, which often takes inspiration from both these classical forms of music.
In the pursuit of a good tool to generate music, I came across the Google Magenta project. It has a simple yet powerful way to generate Note sequence music. My attempt to generate Carnatic music with this tool is presented here.
Basics of Carnatic Music vis–à–vis Western Music
Western music has scales and notes generated by the keys with Major and Minor scales, whereas Indian Classical music has Ragam or Raga which is more than a set of notes or swaras.
Western music generated with notes is discrete by design. Raga is continuous and captures human emotion along with mood, expression, and energy.
Despite many differences, fortunately, both are based on 12 keynotes or swaras which can help in generating Indian classical music from a broader perspective, ignoring the microtonal perfections.
Let’s see how Indian Classical music (Carnatic Music) notes map to Electronic Piano notes to understand the similarities and possibilities for Carnatic Music generation.
Unlike the western music system where swaras/notes frequencies are fixed; in the Indian classical music system variations in few notes are allowed. This scheme envisages ‘Sa’ and ‘Pa’ as fixed notes, with ‘Ma’ having 2 variants and the remaining swaras having 3 variants each. Swaras/Notes and their variations are given in above table.
In total, Carnatic Music considers 16 Swaras/Notes for classifying and accommodating a rich variety of Ragas.
”Ma” is the median among 7 major swaras. Since ‘Ma’ has 2 variants, it divides the Root Ragams also called “Melakarta” Ragams or Parent Ragams into two equal parts. This picture below depicts the division of these 72 major Ragams which have all 7 major swaras. Thousands of Child Ragas are derived by adding, omitting, or transposing the notes from these 72 main Ragas.
1.Carnatic Music with Magenta
Enough of theory, now let’s jump into Carnatic Music generation using Google Magenta.
Click this link to run the below examples yourself. This is the easiest way to get started with Magenta. Here, you can generate music, download it as MIDI and also see the graphical music patterns with Bokeh library.
Everything in Magenta is centered around NoteSequences. This is a fantastic abstract representation of a series of notes, each with different pitches or srutis, instruments and strike velocities, much like MIDI.
The beginners of Carnatic Music are first taught with Mayamalavagowla Ragam, the 15th Melakarta (see the chart above). It has the following notes/swaras.
sa, ri1, ga2, ma1, pa, da1, ni2
The ascending order (Aarohana) and descending order (Avarohana) have all the same 7 swaras, which is a common property for all Melakarta Ragams. The following python script plays this ragam notes. Run this code in Step 1 of the Hello Magenta Colab window given above.
Visualizing the Ragas
The above code generates the graph and note sequence as MIDI file for 3 ragas.
You can observe the symmetry of notes in the graph, which may be the reason, new students are started with this Mayamalavagowla Ragam.
Punching the main keynotes on piano will generate Sankarabharam Ragam, which appears to be a platykurtic gaussian normal distribution.
Music is all about melodious patterns
A new student is taught to sing/play some notes/swaras patterns. Here is a code snippet for one such beautiful pattern called sarali swaram.
Any ragam with the same ascending order and descending order notes can be played with the above pattern
Generating variable-length note sequences
Many times, notes/swaras need to played at variable lengths. NoteSequence has provided this feature with start_time and end_time parameters. This this code generates notes for one such basic composition called Pillari Geetam.
2. Generate Raga notes using Melody_RNN
Till now, we just used NoteSequence to generate Carnatic Raga Notes. Now, let’s try to generate music with the Recurrent Neural Network model developed by the Google Magenta team.
A MelodyRNN is an LSTM-based language model for musical notes — it is best at continuing a NoteSequence that you give it. Try running this this code in Step-2 of the Hello Magenta Colab file to see the result of generating Carnatic Raga Notes using Melody_RNN.
I saw that the output sequence generated by Melody_RNN does go beyond the given Raga Notes. A single note change can result in deviation from Raga’s pattern. This is not as desirable as per the rigid properties of Raga.
3. Generate random Raga notes with simple Python Scripts
When complex things are not working, try simple options
This is a simple this code to generate random Raga Notes with variable lengths. This script generates only the notes present in the Raga. This is a very simple one and serves the basic purpose of random notes generation.
In this article, I attempted to explore the possibilities of generating Carnatic Music Raga notes with Magenta NoteSequence. Automatic Note sequence can be generated with Melody_RNN, but it produced notes beyond Raga pattern notes. So, I provided a simple random notes generator, that may serve basic needs while confining to Raga note sequence limits.
You can also read this article on our Mobile APP