<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript" language="JavaScript">
//<![CDATA[
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();
}
if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
origWidth = innerWidth;
origHeight = innerHeight;
onresize = reDo;
}
onerror = null;
//]]>
</script>
<style type="text/css">/*<![CDATA[*/
< !-- div.WebHelpPopupMenu {
position: absolute;
left: 0px;
top: 0px;
z-index: 4;
visibility: hidden;
}
p.WebHelpNavBar {
text-align: right;
}
-->
/*]]>*/</style>
<script type="text/javascript">//<![CDATA[
gRootRelPath = "../../../..";
gCommonRootRelPath = "../../../..";
gTopicId = "9.2.2.5";
//]]></script>
<script type="text/javascript" src="../../../../template/scripts/rh.min.js"></script>
<script type="text/javascript" src="../../../../template/scripts/common.min.js"></script>
<script type="text/javascript" src="../../../../template/scripts/topic.min.js"></script>
<script type="text/javascript" src="../../../../template/scripts/topicwidgets.min.js"></script>
<script type="text/javascript" src="../../../../whxdata/projectsettings.js"></script>
<link rel="stylesheet" type="text/css" href="../../../../template/styles/topic.min.css"/>
<link rel="stylesheet" type="text/css" href="../../../../template/Charcoal_Grey/topicheader.css"/>
<meta name="topic-status" content="Draft"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Audio</title>
<meta name="generator" content="Adobe RoboHelp 2019"/>
<link rel="stylesheet" href="../../../../assets/css/default.css" type="text/css"/>
<meta name="rh-authors" content="Mark Alexander"/>
<meta name="topic-comment" content="Page outlining the different functions and variables associated with Audio"/>
<meta name="rh-index-keywords" content=""/>
<meta name="search-keywords" content="Audio"/>
</head>
<body>
<div class="topic-header rh-hide" id="rh-topic-header" onclick="rh._.goToFullLayout()">
<div class="logo">
</div>
<div class="nav">
<div class="title" title="Audio">
<span>Audio</span>
</div>
<div class="gotohome" title="Click here to see this page in full context">
<span>Click here to see this page in full context</span>
</div>
</div>
</div>
<div class="topic-header-shadow rh-hide" id="rh-topic-header-shadow"></div>
<!--<div class="body-scroll" style="top: 150px;">-->
<h1>Audio</h1>
<p>GameMaker Studio 2 has a complete audio engine that is based on the <tt>*.ogg</tt>, <tt>*.mp3</tt> and <tt>*.wav</tt> sound formats. Sounds of these types added to the IDE can then be used in your game using the basic audio functions shown below. For
things more complex than basic sound effects or playing a single piece of music you can refer to the advanced audio functions which let you modify how a sound is played. There are also a selection of more specialised functions dedicated to streaming
audio, positioning audio - to give 3D sound - and grouping audio.</p>
<p class="note"><b>IMPORTANT!</b> When using audio on the HTML5 target, you should be aware that not all browsers support Web Audio and so may not play any sound for your project when run. You can get a general idea of Web Audio support from the following link:
<a href="https://caniuse.com/#search=WebAudio" target="_blank">Can I Use Web Audio?</a>.</p>
<p>The following functions are for dealing with audio in the most straightforward and simple way possible, avoiding the use of emitters and permitting the user to generate sounds and play music easily as these sounds are always generated at the <i>listener position</i> (see the section linked below for more details on the <i>listener</i>) and so are generally not affected by any changes to the <i>listener</i>:</p>
<p> </p>
<ul class="colour">
<li><a href="audio_exists.htm">audio_exists</a></li>
<li><a href="audio_get_name.htm">audio_get_name</a></li>
<li><a href="audio_get_type.htm">audio_get_type</a></li>
<li><a href="audio_play_sound.htm">audio_play_sound</a></li>
<li><a href="audio_play_sound_at.htm">audio_play_sound_at</a></li>
<li><a href="audio_pause_sound.htm">audio_pause_sound</a></li>
<li><a href="audio_pause_all.htm">audio_pause_all</a></li>
<li><a href="audio_resume_sound.htm">audio_resume_sound</a></li>
<li><a href="audio_resume_all.htm">audio_resume_all</a></li>
<li><a href="audio_stop_sound.htm">audio_stop_sound</a></li>
<li><a href="audio_stop_all.htm">audio_stop_all</a></li>
<li><a href="audio_is_playing.htm">audio_is_playing</a></li>
<li><a href="audio_is_paused.htm">audio_is_paused</a></li>
<li><a href="audio_create_stream.htm">audio_create_stream</a></li>
<li><a href="audio_destroy_stream.htm">audio_destroy_stream</a></li>
</ul>
<p> </p>
<p>The following functions are designed to give more control over how the audio engine works, and how the sounds played through it will be "heard" by the listener. As such it is recommended that you have a good working knowledge of how the rest
of the GameMaker Studio 2 audio engine works before using any of the following functions:</p>
<p> </p>
<ul class="colour">
<li><a href="audio_sound_set_track_position.htm">audio_sound_set_track_position</a></li>
<li><a href="audio_sound_get_track_position.htm">audio_sound_get_track_position</a></li>
<li><a href="audio_sound_set_listener_mask.htm">audio_sound_set_listener_mask</a></li>
<li><a href="audio_sound_get_listener_mask.htm">audio_sound_get_listener_mask</a></li>
<li><a href="audio_sound_length.htm">audio_sound_length</a></li>
<li><a href="audio_sound_pitch.htm">audio_sound_pitch</a></li>
<li><a href="audio_sound_get_pitch.htm">audio_sound_get_pitch</a></li>
<li><a href="audio_sound_is_playable.htm">audio_sound_is_playable</a></li>
<li><a href="audio_falloff_set_model.htm">audio_falloff_set_model</a></li>
<li><a href="audio_sound_gain.htm">audio_sound_gain</a></li>
<li><a href="audio_sound_get_gain.htm">audio_sound_get_gain</a></li>
<li><a href="audio_master_gain.htm">audio_master_gain</a></li>
<li><a href="audio_set_master_gain.htm">audio_set_master_gain</a></li>
<li><a href="audio_get_master_gain.htm">audio_get_master_gain</a></li>
<li><a href="audio_channel_num.htm">audio_channel_num</a></li>
<li><a href="audio_debug.htm">audio_debug</a></li>
</ul>
<p> </p>
<p>Further advanced functionality, like setting listeners, recording audio, or synchronising multiple audio tracks over time can all be found from the sub-sections listed below:</p>
<ul class="colour">
<li><a href="Audio_Emitters/Audio_Emitters.htm">Audio Emitters</a></li>
<li><a href="Audio_Listeners/Audio_Listeners.htm">Audio Listeners</a></li>
<li><a href="Audio_Groups/Audio_Groups.htm">Audio Groups</a></li>
<li><a href="Audio_Buffers/Audio_Buffers.htm">Audio Buffers</a></li>
<li><a href="Audio_Synchronisation/Audio_Synchronisation.htm">Audio Synchronisation</a></li>
</ul>
<p> </p>
<p> </p>
<h2>Web Audio</h2>
<p>When creating games for the HTML5 target platform, the audio engine requires <b>Web Audio</b> support, and this in turn mans that sometimes your audio won't play when or how you expect it. This is because the Web Audio context may not be running
or may stop running when your game is being played. What causes this varies greatly between browsers, and even between different versions of the same browser, and so detecting when the web audio context status changes is very important, eg: to detect
when the context changes and pause/start looping audio like background music.</p>
<p>To help with this issue, GameMaker Studio 2 has two separate ways to detect the change in Web Audio context status, either using the following function:</p>
<ul class="colour">
<li><a href="audio_system_is_available.htm">audio_system_is_available</a></li>
</ul>
<p> </p>
<p>You may also use the <b>Asynchronous System Event</b>, which will be triggered whenever the Web Audio status changes. In this event you will get the built in <a href="../../../GML_Overview/Variables/Builtin_Global_Variables/async_load.htm"><tt>async_load</tt></a><span> DS map</span> populated with the key "<tt>event_type</tt>" which in turn will hold the string "<tt>audio_system_status</tt>" if it is an audio event. When this key exists, there will also be a further "<tt>status</tt>" key which will
be either "<tt>available</tt>" or "<tt>unavailable</tt>". Note that this event will be triggered on <i>all</i> platforms, but on everything except HTML5 it will only be triggered once on Game Start when the audio engine is first
initialised. For more information please see the section:</p>
<ul class="colour">
<li><a href="../../../../The_Asset_Editors/Object_Properties/Async_Events/System.htm">The Asynchronous System Event</a></li>
</ul>
<p> </p>
<p> </p>
<p> </p>
<div class="footer">
<div class="buttons">
<div class="clear">
<div style="float:left">Back: <a href="../Asset_Management.htm">Asset Management</a></div>
<div style="float:right">Next: Paths</div>
</div>
</div>
<h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
</div>
<!-- KEYWORDS
Audio
-->
<!-- TAGS
audio_functions
-->
</body></html>