{"id":4926,"date":"2024-02-10T15:12:07","date_gmt":"2024-02-10T06:12:07","guid":{"rendered":"https:\/\/blog.criware.com\/?p=4926"},"modified":"2024-02-10T15:12:07","modified_gmt":"2024-02-10T06:12:07","slug":"mapping-pitch-to-a-musical-scale","status":"publish","type":"post","link":"https:\/\/blog.criware.com\/index.php\/2024\/02\/10\/mapping-pitch-to-a-musical-scale\/","title":{"rendered":"Mapping Pitch to a Musical Scale"},"content":{"rendered":"<p>When playing game music, you may sometimes want to generate some of the notes in real-time, either to add variation to a looping song, or for the music to better reflect what is happening in the game.<\/p>\n<p>To achieve this, instruments must be sampled and implemented in Atom Craft. Many files may be required to cover all the notes and articulations necessary. Such a large memory footprint may not be available, especially on mobile games.<\/p>\n<p>In this post, we will see how to create lightweight instruments from a single sample by mapping its pitch to a musical scale.<\/p>\n<div style=\"max-width: 700px; margin: 0 auto; margin-bottom: 20px; border: 1px solid #aaa;\">\n<div style=\"width: 800px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-4926-1\" width=\"800\" height=\"423\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/Video-01-Pitch-Map.mp4?_=1\" \/><a href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/Video-01-Pitch-Map.mp4\">https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/Video-01-Pitch-Map.mp4<\/a><\/video><\/div>\n<\/div>\n<h1 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Creating a Pitch Map<\/h1>\n<p>We will start by recording the instrument.<\/p>\n<ul>\n<li>Record any tonal instrument you have access to: piano, guitar, glockenspiel, synthesizer, etc.<\/li>\n<li>Keep only the note that will be your root key. In our example, we recorded two instruments: one at C4 and the other at C6.<\/li>\n<\/ul>\n<p>Import these recordings in Atom Craft.<\/p>\n<ul>\n<li>Create a <strong>Polyphonic Cue.<\/strong><\/li>\n<li>Drag and drop one of the notes on the Cue to create a Track and a Waveform Region.<\/li>\n<\/ul>\n<p>If you play the Cue at that point, it will obviously always play the same note. Adjusting the <em>Pitch Random Range<\/em> property of the Cue would not help, as it would produce out-of-tune sounds, the pitch values being truly random.<\/p>\n<p>So we need another method in order to play notes tuned to a certain scale. For this, we will use an AISAC:<\/p>\n<ul>\n<li>Create an <strong>AISAC-Control<\/strong> called \u201cPitchScale\u201d.<\/li>\n<li>Select your Cue and create a new <strong>AISAC<\/strong>.<\/li>\n<li>Add a <strong>Pitch<\/strong> <strong>graph<\/strong> to the AISAC.<\/li>\n<\/ul>\n<p>Next, we need to map the pitch so that it corresponds to a musical scale.<\/p>\n<p>We have to create a step graph, where each step corresponds to a note in the target scale above and below the root key. The destination values for a pitch graph are expressed in cents. Since 1 semitone is equal to 100 cents, we must add steps in multiples of 100 to create the desired scale. To minimize pitch-shift artifacts, it is recommended to stay within +\/- 1 octave or +\/- 1200 cents of the root key.<\/p>\n<p>For example, if you want to create a pentatonic major scale over two octaves, you will need to create eleven steps with the following values -1200, -1000, -800, -500, -300, 0, 200, 400, 700, 900, 1200. Here is how it should look:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/01-Pitch-graph-scale.png\" alt=\"01 Pitch graph scale\" width=\"1175\" height=\"488\" class=\"alignnone size-full wp-image-4936\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/01-Pitch-graph-scale.png 1175w, https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/01-Pitch-graph-scale-300x125.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/01-Pitch-graph-scale-768x319.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/01-Pitch-graph-scale-1024x425.png 1024w\" sizes=\"auto, (max-width: 1175px) 100vw, 1175px\" \/><\/p>\n<h1 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Randomizing<\/h1>\n<p>Moving the AISAC will allow to play notes in the desired scale. In case a more generative approach is needed, it is also possible to use the AISAC&#8217;s random function to pick up each note.<\/p>\n<ul>\n<li>Select the AISAC.<\/li>\n<li>Change the <em>Control Type<\/em> to <em>Random<\/em>.<\/li>\n<li>New properties will appear: set the <em>Random Range<\/em> to 2 and <em>Default Control Value<\/em> to 0.5.<\/li>\n<\/ul>\n<p>The bar above the AISAC Control Values should turn green, showing the random range.<\/p>\n<p>From now on, each time we play the Cue the pitch will be randomized but will stay in tune.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/02-Random-AISAC.png\" alt=\"02 Random AISAC\" width=\"1645\" height=\"700\" class=\"alignnone size-full wp-image-4927\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/02-Random-AISAC.png 1645w, https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/02-Random-AISAC-300x128.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/02-Random-AISAC-768x327.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/02-Random-AISAC-1024x436.png 1024w\" sizes=\"auto, (max-width: 1645px) 100vw, 1645px\" \/><\/p>\n<h1 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Automating pitch mapping with CRI Robot<\/h1>\n<p>As you have probably noticed, these graphs can have a lot of points. It can be extremely cumbersome and error-prone to adjust them manually, especially for more complex scales.<\/p>\n<p>Thankfully, using the Robot API, we can write a script that will automatically generate the desired graph. In a <a href=\"https:\/\/blog.criware.com\/index.php\/2023\/12\/08\/aisac-crossfades-script-with-robot-api\/\">previous post<\/a>, we saw how to manipulate AISAC graphs, and we will use the same API function in this case too.<\/p>\n<p>Here is a summary of how the script works:<\/p>\n<ul>\n<li>We start by providing a list of different scales and their intervals.<\/li>\n<li>Once the user has selected a scale, we generate the pitch values for each step (in cents).<\/li>\n<li>Finally, we generate the Control Values required to create our step graph, based on how many intervals the scale has.<\/li>\n<\/ul>\n<p>This script can generate pitch graphs for 8 popular scales, but it is easy to edit the list to add your favorite.<\/p>\n<div style=\"max-width: 700px; margin: 0 auto; margin-bottom: 20px; border: 1px solid #aaa;\">\n<div style=\"width: 800px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-4926-2\" width=\"800\" height=\"423\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/Video-02-Script.mp4?_=2\" \/><a href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/Video-02-Script.mp4\">https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/Video-02-Script.mp4<\/a><\/video><\/div>\n<\/div>\n<p>You will find both the demo project and the script below, so you can try with your own sounds and scales!<\/p>\n<div style=\"max-width: 800px; margin: 0 auto; margin-bottom: 20px; text-align: center;\">\n<a style=\"display: block; border: 1px solid #ccc; padding: 20px; max-width: 100%; margin: 0 auto;\" href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/AtomCraft_Project_RandomMusicalScale.zip\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1813\" style=\"display: block; margin: 0 auto;\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2018\/06\/zip.png\" alt=\"zip\" width=\"80\" height=\"78\">AtomCraft_Project_RandomMusicalScale.zip<\/a><\/p>\n<p><a style=\"display: block; border: 1px solid #ccc; padding: 20px; max-width: 100%; margin: 0 auto;\" href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2024\/02\/Scripts_RobotAPI_AISACPitchMap.zip\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1813\" style=\"display: block; margin: 0 auto;\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2018\/06\/zip.png\" alt=\"zip\" width=\"80\" height=\"78\">Scripts_RobotAPI_AISACPitchMap.zip<\/a>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>When playing game music, you may sometimes want to generate some of the notes in real-time, either to add variation<\/p>\n","protected":false},"author":2,"featured_media":4939,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[5,7],"tags":[],"class_list":["post-4926","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-adx","category-tutorials"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/4926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/comments?post=4926"}],"version-history":[{"count":8,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/4926\/revisions"}],"predecessor-version":[{"id":4942,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/4926\/revisions\/4942"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media\/4939"}],"wp:attachment":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media?parent=4926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/categories?post=4926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/tags?post=4926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}