{"id":159,"date":"2016-02-28T11:11:41","date_gmt":"2016-02-28T11:11:41","guid":{"rendered":"http:\/\/www.rangakrish.com\/?p=159"},"modified":"2016-02-29T02:17:44","modified_gmt":"2016-02-29T02:17:44","slug":"using-cellular-automata-to-generate-music","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2016\/02\/28\/using-cellular-automata-to-generate-music\/","title":{"rendered":"Using Cellular Automata to Generate Music"},"content":{"rendered":"<p>Cellular automata are a powerful computational formalism. Stephen Wolfram\u2019s book <em><strong>A New Kind of Science<\/strong><\/em>\u00a0provides a thorough study of these devices. Not surprisingly,\u00a0<a href=\"https:\/\/www.wolfram.com\/mathematica\/\" target=\"_blank\">Wolfram Mathematica<\/a> has great support for working with them.<\/p>\n<p>For example, the following figure shows the evolution of Rule 30 over 50 steps, plotted using <strong>ArrayPlot<\/strong> function (in Mathematica):<\/p>\n<figure id=\"attachment_160\" aria-describedby=\"caption-attachment-160\" style=\"width: 89px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/Cellular-Automata.png\" rel=\"attachment wp-att-160\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"160\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2016\/02\/28\/using-cellular-automata-to-generate-music\/cellular-automata\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/Cellular-Automata.png\" data-orig-size=\"89,432\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Cellular Automata\" data-image-description=\"&lt;p&gt;Cellular Automata&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Cellular Automata&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/Cellular-Automata.png\" class=\"size-full wp-image-160\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/Cellular-Automata.png?resize=89%2C432\" alt=\"Cellular Automata\" width=\"89\" height=\"432\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/Cellular-Automata.png?w=89&amp;ssl=1 89w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/Cellular-Automata.png?resize=62%2C300&amp;ssl=1 62w\" sizes=\"(max-width: 89px) 100vw, 89px\" \/><\/a><figcaption id=\"caption-attachment-160\" class=\"wp-caption-text\">Cellular Automata<\/figcaption><\/figure>\n<p>Using cellular automata for generating music is not new. A google search throws\u00a0up many papers and articles on this topic. <a href=\"http:\/\/tones.wolfram.com\/about\/how.html\" target=\"_blank\">Wolfram Tones<\/a>\u00a0 gives a nice example of the idea.<\/p>\n<p>The latest version of <a href=\"http:\/\/opusmodus.com\" target=\"_blank\">Opusmodus<\/a> has introduced a function<strong> cellular-automaton<\/strong> for tracing the evolution of a primitive automaton over a given number of steps, starting from an initial condition. For today\u2019s post, I wanted to generate music in Opusmodus using this new function.<\/p>\n<p>Here is what I have done\u00a0in a nutshell. I generate a 50-step evolution of rules 26 and 30 each, starting from the initial bit vector (<strong>0, 0, 0, 1, 0, 1, 0, 0, 0, 0)<\/strong>. One of the two is randomly chosen to serve as the basis for our score. Additionally, I randomly choose 10 consecutive rows of the active element (each row maps to a bar of synthesised music). Both these tricks guarantee that different music is generated each time you run the program.<\/p>\n<p>The bit vector corresponding to a row is converted into a sequence of note lengths, <strong>1<\/strong>\u00a0becoming a <strong>1\/16<\/strong>th unit and <strong>0<\/strong>\u00a0becoming a rest for the same duration. Just to make this a bit interesting, I use three tracks, comprising <strong>Bass Drum<\/strong>, <strong>Glockenspiel<\/strong> and <strong>English Horn<\/strong>. The rhythm for all instruments is derived from the same evolution vector. For the non-percussion instruments, I select random pitches from <strong>mela-kokilapriya<\/strong> (an Indian scale) and <strong>pentatonic-blues<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_165\" aria-describedby=\"caption-attachment-165\" style=\"width: 272px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/CA-in-Opusmodus.png\" rel=\"attachment wp-att-165\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"165\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2016\/02\/28\/using-cellular-automata-to-generate-music\/ca-in-opusmodus\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/CA-in-Opusmodus.png\" data-orig-size=\"790,872\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"CA in Opusmodus\" data-image-description=\"&lt;p&gt;Cellular Automata in Opusmodus&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;CA in Opusmodus&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/CA-in-Opusmodus.png\" class=\"size-medium wp-image-165\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/CA-in-Opusmodus-272x300.png?resize=272%2C300\" alt=\"CA in Opusmodus\" width=\"272\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/CA-in-Opusmodus.png?resize=272%2C300&amp;ssl=1 272w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/CA-in-Opusmodus.png?resize=768%2C848&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/02\/CA-in-Opusmodus.png?w=790&amp;ssl=1 790w\" sizes=\"(max-width: 272px) 100vw, 272px\" \/><\/a><figcaption id=\"caption-attachment-165\" class=\"wp-caption-text\">CA in Opusmodus<\/figcaption><\/figure>\n<p>What I have done is just one of the innumerable possibilities of using CA for music.\u00a0Nothing out of the world here, but an interesting idea that can be used in a larger (more realistic) project!<\/p>\n<p><a href=\"http:\/\/www.rangakrish.com\/downloads\/Cellular automata.opmo\" target=\"_blank\">Here<\/a> is the source code and <a href=\"http:\/\/www.rangakrish.com\/downloads\/cellular automata.mid\" target=\"_blank\">here<\/a> is a sample midi file generated from a single run of the program.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cellular automata are a powerful computational formalism. Stephen Wolfram\u2019s book A New Kind of Science\u00a0provides a thorough study of these devices. Not surprisingly,\u00a0Wolfram Mathematica has great support for working with them. For example, the following figure shows the evolution of Rule 30 over 50 steps, plotted using ArrayPlot function (in Mathematica): Using cellular automata for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18,5,17],"tags":[42,43,37],"class_list":["post-159","post","type-post","status-publish","format-standard","hentry","category-lisp","category-music","category-programming","tag-cellular-automata","tag-mathematica","tag-opusmodus"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-2z","jetpack-related-posts":[{"id":169,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/03\/04\/a-gui-front-end-for-cellular-automata-generator\/","url_meta":{"origin":159,"position":0},"title":"A GUI Front-end for Cellular Automata Generator","author":"admin","date":"March 4, 2016","format":false,"excerpt":"In my last post, I explained how we can use Cellular Automata (CA) in Opusmodus\u00a0to create music. For today\u2019s post, I wanted to build a simple UI to control the parameters used in the CA example. This posed a practical difficulty. Opusmodus does not yet provide a GUI library. Even\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Opusmodus GUI Driver","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Opusmodus-Driver.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Opusmodus-Driver.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Opusmodus-Driver.png?resize=525%2C300 1.5x"},"classes":[]},{"id":3545,"url":"https:\/\/www.rangakrish.com\/index.php\/2024\/11\/09\/semantic-search-in-wolfram-mathematica\/","url_meta":{"origin":159,"position":1},"title":"Semantic Search in Wolfram Mathematica","author":"admin","date":"November 9, 2024","format":false,"excerpt":"In an earlier article, I explained how to use OpenAI from Wolfram Mathematica ver 14.1. This latest release of Wolfram supports Semantic Search as well. In today\u2019s article, let me discuss this feature. As in the case of using LLMs, using Semantic Search requires an account with one of the\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Remedy Description","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/11\/image1-300x225.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/11\/image1-300x225.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/11\/image1-300x225.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3794,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/08\/19\/stock-analysis-with-wolfram-mathematica-part-2\/","url_meta":{"origin":159,"position":2},"title":"Stock Analysis with Wolfram Mathematica &#8211; Part 2","author":"admin","date":"August 19, 2025","format":false,"excerpt":"In the previous article, I had explained how to get started using Wolfram Mathematica\u2019s stock analysis features. The focus was on working with the exchanges supported by Mathematica, for example BSE India. What if we have stock data from a different source and want to analyze it in Mathematica? In\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Loading the CSV Data","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/08\/processdata-fn-300x149.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/08\/processdata-fn-300x149.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/08\/processdata-fn-300x149.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3774,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/08\/04\/stock-analysis-using-wolfram-mathematica\/","url_meta":{"origin":159,"position":3},"title":"Stock Analysis Using Wolfram Mathematica","author":"admin","date":"August 4, 2025","format":false,"excerpt":"I have my own toolkit for analyzing stocks, but occasionally I use Mathematica as well. Given Mathematica\u2019s extensive support for numerical computation including Machine Learning, it can be a valuable resource for deep analysis of the stock market. In today\u2019s article, let me give an overview of some of the\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Supported Exchanges","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/08\/exchanges-300x28.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/08\/exchanges-300x28.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/08\/exchanges-300x28.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3830,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/10\/31\/analysing-weather-data-using-wolfram-mathematica\/","url_meta":{"origin":159,"position":4},"title":"Analysing Weather Data Using Wolfram Mathematica","author":"admin","date":"October 31, 2025","format":false,"excerpt":"If you are interested in analysing weather data and making predictions such as rainfall, storm, etc., then Mathematica has nice functionality that you can use. In this article, let me cover a few basic functions in this category. Let us start by getting the coordinates of the place for which\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"Getting Location Coordinates","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/10\/coord-300x50.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3381,"url":"https:\/\/www.rangakrish.com\/index.php\/2024\/05\/20\/using-openai-from-mathematica\/","url_meta":{"origin":159,"position":5},"title":"Using OpenAI from Mathematica","author":"admin","date":"May 20, 2024","format":false,"excerpt":"Mathematica was among the first to integrate with OpenAI. The functionality is nicely exposed in terms of a few pre-defined functions. Let us explore some of the functionality in today\u2019s article. The simplest way to get started is to use LLMSynthesize\u00a0function: It can take a few seconds before you get\u2026","rel":"","context":"In &quot;Mathematica&quot;","block_context":{"text":"Mathematica","link":"https:\/\/www.rangakrish.com\/index.php\/category\/mathematica\/"},"img":{"alt_text":"LLMSynthesize Function","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/05\/Example1-300x27.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/05\/Example1-300x27.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2024\/05\/Example1-300x27.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}