{"id":12305,"date":"2024-12-18T10:13:08","date_gmt":"2024-12-18T15:13:08","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=12305"},"modified":"2024-12-18T10:13:08","modified_gmt":"2024-12-18T15:13:08","slug":"code-for-sonic-and-ten-sonic-movies","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2024\/12\/18\/code-for-sonic-and-ten-sonic-movies\/","title":{"rendered":"Code for Sonic and Ten Sonic Movies"},"content":{"rendered":"<div class=\"content\"><!--introduction-->\r\n<p>Two previous blog posts, <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2024\/12\/08\/sonic-adds-sound-to-logo-recaman-chaos\/\">Dec. 12, 2024<\/a> and <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2024\/11\/16\/lights-camera-action-and-sound\/\">Nov. 16, 2024<\/a>, introduced \"Sonic\", my new tool for incorporating sound in videos. Today's blog post includes a link to the MATLAB source code for Sonic, as well as links to new versions of ten examples.<\/p>\r\n<!--\/introduction-->\r\n<h3>Contents<\/h3>\r\n<div>\r\n<ul>\r\n<li>\r\n<a href=\"#430e1f71-5674-4dd0-9822-ecdf14267246\">Code<\/a>\r\n<\/li>\r\n<li>\r\n<a href=\"#261cb182-c13b-4b1e-9932-f52485ff1334\">Sonic<\/a>\r\n<\/li>\r\n<li>\r\n<a href=\"#c9a4823d-d0b6-48fd-a9f0-388f00ec93b3\">Ten Movies<\/a>\r\n<\/li>\r\n<\/ul>\r\n<\/div>\r\n<h4>Code<a name=\"430e1f71-5674-4dd0-9822-ecdf14267246\"><\/a>\r\n<\/h4>\r\n<p>The MATLAB code for Sonic and all the examples is available in this 11 MB <tt>zip<\/tt> file.<\/p>\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/Sonic.zip\">Sonic.zip<\/a>\r\n<\/p>\r\n<h4>Sonic<a name=\"261cb182-c13b-4b1e-9932-f52485ff1334\"><\/a>\r\n<\/h4>\r\n<p>There are two ways to generate the musical sounds. The three movies Warm-Up, TanSin and Blackjack use recordings of C-major scales played on three different pianos. All the other movies rely on <a href=\"https:\/\/www.mathworks.com\/help\/signal\/ref\/resample.html\">resampling<\/a> a single note from a trumpet, xylophone or piano.<\/p>\r\n<p>The function <tt>sonic_examples(kases,n)<\/tt> is a driver for <tt>sonic<\/tt>. The first parameter, <tt>kases<\/tt>, is an integer vector of desired examples, 0 though 9. The second parameter, <tt>n<\/tt>, is the number of desired samples.<\/p>\r\n<div>\r\n<ul>\r\n<li>n = 25 is very fast<\/li>\r\n<li>n = 100 is reasonable<\/li>\r\n<li>n = 200 is the default<\/li>\r\n<li>n = 300 is overkill<\/li>\r\n<\/ul>\r\n<\/div>\r\n<h4>Ten Movies<a name=\"c9a4823d-d0b6-48fd-a9f0-388f00ec93b3\"><\/a>\r\n<\/h4>\r\n<p>Here are links to new versions of the animated videos, and the final frames.<\/p>\r\n<p>\r\n<b>0. Warm-Up<\/b>\r\n<\/p>\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_0.mp4\">sonic_examples_0.mp4<\/a>\r\n<\/p>\r\n<p>\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_0.png\" alt=\"\"> <\/p>\r\n<p>\r\n<b>1. Lissajous<\/b>\r\n<\/p>\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_1.mp4\">sonic_examples_1.mp4<\/a>\r\n<\/p>\r\n<p>\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_1.png\" alt=\"\"> <\/p>\r\n<p>\r\n<b>2. Mertens<\/b>\r\n<\/p>\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_2.mp4\">sonic_examples_2.mp4<\/a>\r\n<\/p>\r\n<p>\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_2.png\" alt=\"\"> <\/p>\r\n<p>\r\n<b>3. TanSin<\/b>\r\n<\/p>\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_3.mp4\">sonic_examples_3.mp4<\/a>\r\n<\/p>\r\n<p>\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_3.png\" alt=\"\"> <\/p>\r\n<p>\r\n<b>4. Van der Pol<\/b>\r\n<\/p>\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_4.mp4\">sonic_examples_4.mp4<\/a>\r\n<\/p>\r\n<p>\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_4.png\" alt=\"\"> <\/p>\r\n<p>\r\n<b>5. VdP Derivative<\/b>\r\n<\/p>\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_5.mp4\">sonic_examples_5.mp4<\/a>\r\n<\/p>\r\n<p>\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_5.png\" alt=\"\"> <\/p>\r\n<p>\r\n<b>6. Blackjack<\/b>\r\n<\/p>\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_6.mp4\">sonic_examples_6.mp4<\/a>\r\n<\/p>\r\n<p>\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_6.png\" alt=\"\"> <\/p>\r\n<p>\r\n<b>7. Vibrating L-shaped Membrane<\/b>\r\n<\/p>\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_7.mp4\">sonic_examples_7.mp4<\/a>\r\n<\/p>\r\n<p>\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_7.png\" alt=\"\"> <\/p>\r\n<p>\r\n<b>8. Recam&aacute;n Sequence<\/b>\r\n<\/p>\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_8.mp4\">sonic_examples_8.mp4<\/a>\r\n<\/p>\r\n<p>\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_8.png\" alt=\"\"> <\/p>\r\n<p>\r\n<b>9. Swinging Sticks<\/b>\r\n<\/p>\r\n<p>\r\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_9.mp4\">sonic_examples_9.mp4<\/a>\r\n<\/p>\r\n<p>\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_9.png\" alt=\"\"> <\/p>\r\n<script language=\"JavaScript\"> <!-- \r\n    function grabCode_6be05d5d2be34097bc51738847d9f5b6() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='6be05d5d2be34097bc51738847d9f5b6 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 6be05d5d2be34097bc51738847d9f5b6';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2024 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\">\r\n<br>\r\n<a href=\"javascript:grabCode_6be05d5d2be34097bc51738847d9f5b6()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript>\r\n<\/span><\/a>\r\n<br>\r\n<br>\r\n      Published with MATLAB&reg; R2024b<br>\r\n<\/p>\r\n<\/div>\r\n<!--\r\n6be05d5d2be34097bc51738847d9f5b6 ##### SOURCE BEGIN #####\r\n%% Code for Sonic and Ten Sonic Movies\r\n% Two previous blog posts,\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2024\/12\/08\/sonic-adds-sound-to-logo-recaman-chaos\/\r\n% Dec. 12, 2024> and\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2024\/11\/16\/lights-camera-action-and-sound\/\r\n% Nov. 16, 2024>,\r\n% introduced \"Sonic\", my new tool for incorporating sound in videos. \r\n% Today's blog post includes a link to the MATLAB source code for Sonic,\r\n% as well as links to new versions of ten examples.\r\n\r\n%% Code\r\n% The MATLAB code for Sonic and all the examples is available in this\r\n% 11 MB |zip| file.\r\n%\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/Sonic.zip Sonic.zip>\r\n% \r\n%% Sonic\r\n% There are two ways to generate the musical sounds.\r\n% The three movies Warm-Up, TanSin and Blackjack use recordings\r\n% of C-major scales played on three different pianos. \r\n% All the other movies rely on \r\n% <https:\/\/www.mathworks.com\/help\/signal\/ref\/resample.html resampling>\r\n% a single note from a trumpet, xylophone or piano.\r\n%\r\n% The function |sonic_examples(kases,n)| is a driver for |sonic|.\r\n% The first parameter, |kases|, is an integer vector of desired examples,\r\n% 0 though 9.  The second parameter, |n|, is the number of desired samples.\r\n%\r\n% * n = 25 is very fast\r\n% * n = 100 is reasonable \r\n% * n = 200 is the default\r\n% * n = 300 is overkill\r\n\r\n%% Ten Movies\r\n% Here are links to new versions of the animated videos, and the final\r\n% frames.\r\n%\r\n% *0. Warm-Up*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_0.mp4 sonic_examples_0.mp4>\r\n%\r\n% <<sonic_examples_0.png>>\r\n%\r\n\r\n%%\r\n% *1. Lissajous*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_1.mp4 sonic_examples_1.mp4>\r\n%\r\n% <<sonic_examples_1.png>>\r\n\r\n%%\r\n% *2. Mertens*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_2.mp4 sonic_examples_2.mp4>\r\n%\r\n% <<sonic_examples_2.png>>\r\n\r\n%%\r\n% *3. TanSin*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_3.mp4 sonic_examples_3.mp4>\r\n%\r\n% <<sonic_examples_3.png>>\r\n\r\n%% \r\n% *4. Van der Pol*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_4.mp4 sonic_examples_4.mp4>\r\n%\r\n% <<sonic_examples_4.png>>\r\n\r\n%% \r\n% *5. VdP Derivative*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_5.mp4 sonic_examples_5.mp4>\r\n%\r\n% <<sonic_examples_5.png>>\r\n\r\n%%\r\n% *6. Blackjack*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_6.mp4 sonic_examples_6.mp4>\r\n%\r\n% <<sonic_examples_6.png>>\r\n\r\n%%\r\n% *7. Vibrating L-shaped Membrane*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_7.mp4 sonic_examples_7.mp4>\r\n%\r\n% <<sonic_examples_7.png>>\r\n\r\n%%\r\n% *8. Recam\u00e1n Sequence*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_8.mp4 sonic_examples_8.mp4>\r\n%\r\n% <<sonic_examples_8.png>>\r\n\r\n%%\r\n% *9. Swinging Sticks*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_9.mp4 sonic_examples_9.mp4>\r\n%\r\n% <<sonic_examples_9.png>>\r\n   \r\n%%\r\n   \r\n\r\n##### SOURCE END ##### 6be05d5d2be34097bc51738847d9f5b6\r\n-->\r\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/sonic_examples_7.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><!--introduction-->\r\n<p>Two previous blog posts, <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2024\/12\/08\/sonic-adds-sound-to-logo-recaman-chaos\/\">Dec. 12, 2024<\/a> and <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2024\/11\/16\/lights-camera-action-and-sound\/\">Nov. 16, 2024<\/a>, introduced \"Sonic\", my new tool for incorporating sound in videos. Today's blog post includes a link to the MATLAB source code for Sonic, as well as links to new versions of ten examples.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2024\/12\/18\/code-for-sonic-and-ten-sonic-movies\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":12201,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,23,22,39,51,1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/12305"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/comments?post=12305"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/12305\/revisions"}],"predecessor-version":[{"id":12308,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/12305\/revisions\/12308"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media\/12201"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=12305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=12305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=12305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}