Sunday, October 30, 2011

Music and Mathematics 

There are deep connections between music and mathematics. For years, I have consciously stayed away from exploring this link, as I have had one worry -  that I might start intellectualizing  music. Of course, that might well be an unfounded concern, and it might be that I develop greater sense of appreciation for music once I understand the mathematics behind it. I now think it is just a mental block :-) But I did learn a little about the mysterious links these two share in indirect ways. I will share my thoughts on this over a few posts.

When I was about 17, I suddenly developed a craze for programming, and spent hours and hours writing C code in the DOS environment. (I didn't have Visual C++ then !) Besides other things, I discovered that you could have the PC play back a note at a specified frequency in an old-fashioned beepy way, that the DOS games of early years (like Dave, and Alladin, for instance) would. This got me thrilled !  I assumed an arbitrary frequency for the base note Sa, say 400 Hz, and found the frequencies of others relative to this by trial and error. Building on this , I wrote C codes to reproduce many popular tunes, for my amusement :-)  This , as it turns out, was utterly naive, for mathematically, two adjacent half notes in music are related by a constant multiplicative factor that equals the twelfth root of 2 ! There was no need for any trial and error ! This also explains why a 'higher' Sa is twice the frequency of the lower one- There are 12 half note spacings in between .

This also means that all major chords have a fixed frequency relationship between their constituent notes. Some have taken all this further, by attempting to determine patterns of mathematical relationships between note frequencies that result in pleasant sounding music, leading to the world of 'computer-generated' music. I personally don't believe in computer generated music, as I believe it lacks the most important component of music - soul...

As an aside, to share my thoughts on using computers to make music, let me use an analogy. Microsoft Word ( or Openoffice if you're a Linux fan :-) is a useful tool for a writer. It helps one easily edit and rephrase sentences without having to 'scratch' them off a page, allows you to choose colours and sizes for the text, helps you to organize and indent the lines, and in general can make your words look pretty. But it can only do so much. You still have to type in the words :-) Music production software tools play the same role for a musician that Word does for a writer. They are very useful, when used as tools..By computer generated music, I refer to the scenario where the tool picks the 'words' (or, in this case the notes) too !

I have also felt that some pieces of music that sound pleasant to the ear have combinations of notes that conventional music theory would declare as discordant ! There truly are many mysteries in music that defy logical explanation, and that, perhaps is nice :-) What is it, that makes certain patterns sound 'Indian',and others sound 'Western', when both are being played in the same scale ?... What is it that makes a sequence of notes sound more 'Indian' when they aren't played perfectly in meter, and are instead spread out at irregular time intervals?....

Some notes have been going around in my head for the last few days, and I recorded my doodles on the synth .. I got the embedded MP3 player working! Thanks Jayesh :-) Please set the volume to 20% or so before you hit play, and then adjust it accordingly.. I'm still figuring out how to set the default volume to a different value!


11 comments:

Jayesh said...

Nice post. I am no math geek, but I always wanted to tinker with sounds on a computer too.
For embedding audio, I use google's flash-based audio player but it requires that your audio file is already in the cloud on a server somewhere (but blogger.com doesn't allow file uploads if I remember correctly)
But if you don't mind uploading it to a server like archive.org or similar, then you should be able to use it like this -
<embed type="application/x-shockwave-flash" flashvars="audioUrl=url_to_your_file_on_archive_dot_org" src="http://www.google.com/reader/ui/3523697345-audio-player.swf" width="400" height="27" quality="best">

Lalit Patnaik said...

"I personally don't believe in computer generated music, as I believe it lacks the most important component of music - soul...". Computer generated music is probably for those who do not have the skill to play any musical instrument (like your's truly) :-|

Karthik said...

Jayesh, Thanks a lot for sharing the code fragment !:) I've uploaded the file on a google sites page. I tried creating a new post with this code fragment, and with URL changed to point to the correct file location. When I view it in the preview mode, the player appears, but when I click on the play button, nothing seems to happen ! :-) Something else I might be missing ?... :-)

Lalit, I meant something entirely different when I said 'computer generated music'! I myself am exploring using computer software as a tool to help make music ! By computer-generated music, I am referring to a scenario where the program itself decides which notes to play too, taking over the creative part; say some kind of an algorithm which chooses the next note automatically based on some 'heuristics'. I think using computers to make music is very good , as long as it is used a tool, and not as a replacement for creativity :-)

Karthik said...

Lalit, I edited this post to try and clarify this point better :-)

Neeraja said...

Anand is a fanatic when it comes to analyzing the mathematics of music. It drives me crazy for as you say, analyzing and intellectualizing music seems to take most of the pleasure away :). Some forms of "complex rhythmic syncopation" sound totally random and discordant to me, but apparently there is a beautiful mathematical aspect to it, which when represented as frequency distributions shows a "harmonious" or symmetric pattern :). But I feel such kinds of music don't serve their true purpose of reaching/touching us through our ears if I have to break it down to frequencies and visualize it and appreciate it with my brain than with my ears :). But then that is just the frustration of a mathematically-challenged person!

You must have heard/read lots about Bach's music - its geometric progressions, recursive loops, and rhythmic syncopation. I can appreciate some of his music, but this little computer-generated video helped me appreciate it better :)
http://www.youtube.com/watch?v=pVadl4ocX0M&feature=fvst

Karthik said...

Neeraja, Really ?! Very interesting ! If Anand decides to start a blog on this, I would love to read his thoughts :-) I enjoy rhythmic syncopation too, but when taken to extremes, I feel that it leaves the terrain of music, and enters one of showmanship :-)

Thanks a lot for sharing the link !The visual depiction of the flow of the notes is very fascinating to watch !:-) There is a software called Synthesia which shows the notes dropping vertically; but I think the horizontal movement, like in this video, is much more interesting when there are multiple tracks :-)

Jayesh said...

Hey Karthik, I haven't tried using Google Sites for hosting files so not sure how file uploads work there. Is the URL pointing directly to the file and not to an html page containing the file? I mean, if you access that URL in the browser, it should start downloading the file and not show any html page.
I know one way of doing this which definitely works - archive.org. Its meant to do this kinda thing - host media and other files. Though you might have to check the copyright-related options.
Once you've uploaded it, you can use their embeddable mp3 player as well (instead of Google's). See this example.

Karthik said...

Jayesh , A big thanks for writing back!! :-) You were right , I goofed up while specifying the URL; I was pointing to the HTML page for download instead of the actual file location .. Thanks for pointing it out!:-) For now, I've let the file be at google sites; I'll experiment with archive.org next time round !

Jayesh said...

No problem. Good to see it working!

Lalit Patnaik said...

Point taken :)

Hey, just a small suggestion about your blogs in general. I think when you create a new post, you normally leave the designated 'post title' field blank and then type in the title in the main body of the post in bold font. I'd suggest typing the title in the designated field itself as it will help readers open a separate page for the particular post and link to it as well if they please. Correct me if I'm wrong.

Karthik said...

Lalit, that's a good suggestion; thanks :-) Ya, I tend to include the title as a part of the post..I've been aware of it, but had stuck to it due to force of habit :)