{"id":2441,"date":"2024-09-09T23:29:35","date_gmt":"2024-09-09T23:29:35","guid":{"rendered":"https:\/\/writingagame.com\/?p=2441"},"modified":"2025-02-12T01:45:41","modified_gmt":"2025-02-12T01:45:41","slug":"chapter-12-sound-miniaudio-h","status":"publish","type":"post","link":"https:\/\/writingagame.com\/index.php\/2024\/09\/09\/chapter-12-sound-miniaudio-h\/","title":{"rendered":"Chapter 12. Sound and smoke"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>Contrary to my expectations, these 2 topics were not that complicated. So I decided that one article on them would be enough. Here&#8217;s how it looks and sounds like:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<iframe loading=\"lazy\" width=\"100%\" height=\"400\" src=\"https:\/\/www.youtube.com\/embed\/Uw8nAMZY-40?controls=0&amp;autoplay=1&amp;loop=1&amp;playlist=Uw8nAMZY-40\" title=\"Sound and smoke demo\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\"><\/iframe>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Sound<\/h2>\n\n\n\n<p>Essentially, the topic came down to finding a suitable audio library\/API.<\/p>\n\n\n\n<p>I&#8217;ve checked a few, including OpenSL, OpenAL, irrKlang, SFML, FMOD, PortAudio, SDL2, etc. Many of them, despite their own claims, are not truly cross-platform (or I couldn&#8217;t get them to run), some are not even &#8220;audio APIs&#8221; but multimedia device interfaces . And most of them are huge and heavy.<\/p>\n\n\n\n<p>I continued searching and finally came across <a href=\"https:\/\/miniaud.io\/index.html\" target=\"_blank\" rel=\"noreferrer noopener\">miniaudio.h<\/a> by <em>David Reid<\/em>, which well deserves to be #1 in relevant Google searches (I lost too much time checking other less suitable options). A single h-file 2-level API. Nice, compact and convenient. Only the samples list confused me a bit. The correct sample to start with is <em>&#8220;Engine Hello World&#8221;<\/em>, <strong>NOT <\/strong>a &#8220;Simple Playback&#8221;.<\/p>\n\n\n\n<p>On my side it&#8217;s implemented in <em>MySound <\/em>class. Extra parameters in my calls allow to regulate volume and pitch of the sound. <\/p>\n\n\n\n<p>Most sounds are from <a href=\"https:\/\/freesound.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">freesound.org<\/a>. <\/p>\n\n\n\n<p>The sound editor I used is <a href=\"https:\/\/www.audacityteam.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Audacity<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Smoke<\/h2>\n\n\n\n<p>The standard approach is &#8220;particle system&#8221;. Here it&#8217;s basically the same, only the particles are bigger and animated. The classes involved are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>subjs\/Smoke<\/li>\n\n\n\n<li>subjs\/Exhaust<\/li>\n\n\n\n<li>rr\/ExhaustLoco<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Source code<\/h2>\n\n\n\n<p>As usual, on GitHub:<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/bkantemir\/_wg_412\" target=\"_blank\" rel=\"noreferrer noopener\">github.com\/bkantemir\/_wg_412<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"mb-2\">Contrary to my expectations, these 2 topics were not that complicated. So I decided that one article on them would be enough. Here&#8217;s how it looks and sounds like: Sound Essentially, the topic came down to finding a suitable audio library\/API. I&#8217;ve checked a few, including OpenSL, OpenAL, irrKlang, SFML, FMOD, PortAudio, SDL2, etc. Many [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2480,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2441","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cross-platform-3d"],"_links":{"self":[{"href":"https:\/\/writingagame.com\/index.php\/wp-json\/wp\/v2\/posts\/2441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/writingagame.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/writingagame.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/writingagame.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/writingagame.com\/index.php\/wp-json\/wp\/v2\/comments?post=2441"}],"version-history":[{"count":32,"href":"https:\/\/writingagame.com\/index.php\/wp-json\/wp\/v2\/posts\/2441\/revisions"}],"predecessor-version":[{"id":3065,"href":"https:\/\/writingagame.com\/index.php\/wp-json\/wp\/v2\/posts\/2441\/revisions\/3065"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/writingagame.com\/index.php\/wp-json\/wp\/v2\/media\/2480"}],"wp:attachment":[{"href":"https:\/\/writingagame.com\/index.php\/wp-json\/wp\/v2\/media?parent=2441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/writingagame.com\/index.php\/wp-json\/wp\/v2\/categories?post=2441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/writingagame.com\/index.php\/wp-json\/wp\/v2\/tags?post=2441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}