{"id":5304,"date":"2024-04-19T17:52:27","date_gmt":"2024-04-19T16:52:27","guid":{"rendered":"https:\/\/www.celesteh.com\/blog\/?p=5304"},"modified":"2024-04-19T18:46:10","modified_gmt":"2024-04-19T17:46:10","slug":"try-out-different-equal-temperaments","status":"publish","type":"post","link":"https:\/\/www.celesteh.com\/blog\/2024\/04\/19\/try-out-different-equal-temperaments\/","title":{"rendered":"Try out different Equal Temperaments"},"content":{"rendered":"\n<p><em>Note: Code for this post is <a href=\"https:\/\/gist.github.com\/celesteh\/77ee808b2d1a92c95684c1fa08e760e8\">available on github here<\/a>.<\/em><\/p>\n\n\n\n<p>Tuning scales is about ratios. We multiply the root frequency by a given ratio to get a note in the scale. In Equal Temperament, all ratios are equal, the 12th root of 2.  Which is 2<sup>1&frasl;12<\/sup>. We multiply a frequency by that to get the next frequency in the scale. When we&#8217;ve gone through all 12, we get the octave. (2<sup>1&frasl;12<\/sup>)<sup>12<\/sup> = 2.<\/p>\n      <p>Let&#8217;s say we want the 3rd note in the chromatic scale. We have the root and multiply by the ratio for the second and then for the third. For the fourth, we do it three times. For the fifth, four times. Therefore, for any chromatic scale step \ud835\ude2f, we multiply the root by 2<sup>(\ud835\ude2f-1)&frasl;12<\/sup>\n      <p>But, especially when we&#8217;re using computers, we can try out putting the notes in different places!  What if we have 10 steps per octave?  Then our ratio is  Which is 2<sup>1&frasl;10<\/sup>.  The composer William Sethares has written music using 10 tone equal temperament and in other unusual tunings, which you can listen to on <a href=\"https:\/\/sethares.engr.wisc.edu\/otherperson\/all_mp3s.html\">his web page<\/a>.<\/p>\n      <p>We can even forego octaves entirely. The Bohlen-Pierce scale is based on divisions of 3, rather than 2. When people use equal temperament with that scale, they typically have 13 steps in the octave, which makes their ratio 3<sup>1&frasl;13<\/sup>. The composer Elaine Walker is one of many who has written music using Bolhen Pierce and you can find examples on <a href=\"http:\/\/ziaspace.com\/_academic\/BP\/\">her website.<\/a><\/p>\n      <p>We can also try out different tunings ourselves! Below, you can try out different Equally Tempered scales. Change the steps value for the number of divisions you want. If you want to try out Bohlen-Pierce, change the octave ratio to 3. Or try whatever tickles your fancy.<\/p>\n      <form id=\"tuner\">\n        <label for=\"freq\">Base Frequency:<\/label>\n        <input type=\"number\" id=\"freq\" name=\"freq\" value=\"440\"><br\/>\n        <label for=\"octave\">Octave ratio:<\/label>\n        <input type=\"number\" id=\"octave\" name=\"octave\" value=\"2\"><br\/>\n        <label for=\"steps\">Number of chromatic steps:<\/label>\n        <input type=\"number\" id=\"steps\" name=\"steps\" value=\"12\"><br\/>\n        <button type=\"button\" onclick=\"calculate_ratio()\">Calculate ratio<\/button>\n        <button type=\"button\" onclick=\"play_chromatic()\">Listen to your tuning<\/button>\n        <button type=\"button\" onclick=\"play_12tet()\">Compare to 12tet<\/button><br \/>\n      <\/form>\n<p> <\/p>\n      <p>Your tuning ratio is <span id=\"pretty_ratio\"> 2<sup>1&frasl;12<\/sup><\/span>, which is equal to <span id=\"decimal\">1.0594630943592953<\/span><p>\n      <p>12tet&#8217;s ratio of 2<sup>1&frasl;12<\/sup> is equal to 1.0594630943592953<\/p>\n                                                                                                                                                      \n      <script>\n        const audioCtx = new (window.AudioContext || window.webkitAudioContext)();\n\n        var ttet_ratio = Math.pow(2, 1\/12);\n        var octave = 2, steps = 12;\n        var user_ratio = ttet_ratio;\n        var ttet_arr, user_arr, notes, ttet_oct, user_oct;\n        ttet_arr = calculate_scale(ttet_ratio, 12);\n        user_arr = ttet_arr;\n        ttet_oct = calculate_octatonic(ttet_ratio, 12, 2);\n        user_oct = ttet_oct;\n        \n        function calculate_ratio() {\n          octave = Number(document.getElementById(\"octave\").value);\n          steps =  Number(document.getElementById(\"steps\").value);\n          document.getElementById(\"pretty_ratio\").innerHTML = \n            \" \".concat(octave).concat(\"<sup>1&frasl;\").concat(steps).concat(\"<\/sup>\");\n    \n          var old_user_ratio = user_ratio;\n          user_ratio = Math.pow(octave, 1\/steps);\n          document.getElementById(\"decimal\").innerHTML = user_ratio;\n\n          if ( old_user_ratio != user_ratio) {\n            user_arr = calculate_scale(user_ratio, steps);\n            user_oct = calculate_octatonic(user_ratio, steps, octave);\n          }\n        }\n        \n        function calculate_scale(ratio, steps) {\n          steps = steps+1;\n          console.log(steps, ratio);\n          var arr = new Array(steps);\n          for (let i = 0; i < steps; i++) {\n            \/\/console.log(i);\n            arr[i] = Math.pow(ratio, i);\n          }\n          console.log(arr);                 \n          return arr;\n        }\n                              \n        function calculate_octatonic(ratio, steps, octave){\n          steps = steps+1;\n          var arr = new Array(1);\n          arr[0] = 1;\n          var index = 0;\n          var keep_looping = true;\n          while (index < steps) {\n              index += 2;\n              if (index < steps){\n                  arr.push(Math.pow(ratio, index));\n                  index++;\n                  if (index < steps) {\n                    arr.push(Math.pow(ratio, index));\n                  }\n              }\n          }\n          if (arr[arr.length-1] != octave){\n            arr.push(octave);\n          }\n          return arr;\n        }\n        \n        \n        function playNote(frequency, duration) {\n          \/\/ create Oscillator node\n          var oscillator = audioCtx.createOscillator();\n\n          oscillator.type = 'square';\n          oscillator.frequency.value = frequency; \/\/ value in hertz\n          oscillator.connect(audioCtx.destination);\n          oscillator.start();\n\n          setTimeout(\n            function() {\n              oscillator.stop();\n              playList();\n          }, duration);\n        }\n\n        function playList() {\n          if (notes.length > 0) {\n            note = notes.pop();\n            console.log(note);\n            console.log(notes.length);\n            if (Array.isArray(note)) {\n              playNote(note[0],note[1]);\n            } else {\n              playNote(note, 500);\n            }\n          }\n        }\n        \n        function playScale(arr) {\n        \n          var freq = Number(document.getElementById(\"freq\").value);\n          var steps = arr.length;\n          \/\/var i = steps;\n          notes = new Array((steps*2)-2);\n          \/\/console.log((steps*2)+1);\n\n          for(let i=0; i < (steps); i++){\n            notes[i] = arr[i] * freq;\n            notes[steps+i] = arr[steps-i-1] * freq;\n            \/\/console.log(i, arr[i], steps+i, arr[steps-i-1]);\n          }\n                               \n          \/\/console.log(notes);\n          playList();\n        }\n        \n        function play_chromatic() {\n          calculate_ratio();\n          playScale(user_arr);\n        }\n        \n        function play_12tet(){\n          playScale(ttet_arr);\n        }\n          \n        function debussy(scale){\n          var freq = Number(document.getElementById(\"freq\").value);\n                           \n          var crotchet = 700;\n          var quaver = crotchet\/2;\n          var semiquaver_triplet = quaver \/ 3;\n                           \n          notes = [\n            [scale[1] * freq, semiquaver_triplet],\n            [scale[2] * freq, semiquaver_triplet],\n            [scale[3] * freq, semiquaver_triplet],\n            [scale[4] * freq, crotchet * 3],\n            [scale[3] * freq, crotchet * 2],\n            [scale[2] * freq, crotchet],\n            [scale[1] * freq, crotchet],\n            [scale[0] * freq, crotchet],\n            [scale[0] * freq, crotchet * 2]\n          ];\n          notes.reverse();\n          playList();\n        }             \n       \n        \n      <\/script>\n                              \n      <p>It can sometimes be difficult to hear the differences in pitches just going up and down a chromatic scale. Modes like major and minor are very strongly tied to a 12 note chromatic scale and it doesn't make sense to try to, say, play a 10 note major scale. However, the octatonic scale is a mode that can potentially work for any tuning. It alternates whole and half steps. Perhaps listening to the octatonic versions of your scale and 12tet will demonstrate the differences more clearly.<\/p>\n      <form id=\"octatonic\">\n         <button type=\"button\" onclick=\"calculate_ratio();playScale(user_oct);\">Listen to your tuning in octatonic<\/button>\n         <button type=\"button\" onclick=\"playScale(ttet_oct);\">Compare to 12tet octatonic<\/button><br \/>\n      <\/form>\n<p> <\/p>\n      <p>Or we can try a phrase by Debussy:<\/p>\n      <form id=\"octatonic\">\n         <button type=\"button\" onclick=\"calculate_ratio();debussy(user_oct);\">Debussy in your tuning<\/button>\n         <button type=\"button\" onclick=\"debussy(ttet_oct);\">Debussy in 12tet<\/button><br \/>\n      <\/form>\n","protected":false},"excerpt":{"rendered":"<p>Note: Code for this post is available on github here. Tuning scales is about ratios. We multiply the root frequency by a given ratio to get a note in the scale. In Equal Temperament, all ratios are equal, the 12th root of 2. Which is 21&frasl;12. We multiply a frequency by that to get the &hellip; <a href=\"https:\/\/www.celesteh.com\/blog\/2024\/04\/19\/try-out-different-equal-temperaments\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Try out different Equal Temperaments<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"federated","footnotes":""},"categories":[1],"tags":[424,436,425,166],"class_list":["post-5304","post","type-post","status-publish","format-standard","hentry","category-uncategorised","tag-lecture-notes","tag-octatonic","tag-science-of-sound","tag-tuning"],"_links":{"self":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts\/5304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/comments?post=5304"}],"version-history":[{"count":6,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts\/5304\/revisions"}],"predecessor-version":[{"id":5311,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts\/5304\/revisions\/5311"}],"wp:attachment":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/media?parent=5304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/categories?post=5304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/tags?post=5304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}