<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Audio addon: pause sample</title>
		<link>http://www.allegro.cc/forums/view/615910</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 07 Dec 2015 22:11:52 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There&#39;s al_play_sample and al_stop_sample... which is good but what to do if you want to pause a sample and then resume it?</p><p>al_stop_sample complete wipes the sound which means that repeated playback will start from very beginning.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neuton Mouse)</author>
		<pubDate>Mon, 07 Dec 2015 02:57:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The typical solution to these kinds of questions is to switch to the more advanced API. Instead of <span class="source-code"><a href="http://www.allegro.cc/manual/al_play_sample"><span class="a">al_play_sample</span></a></span>, you can do this:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_reserve_samples"><span class="a">al_reserve_samples</span></a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a><span class="k3">*</span> sample <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_sample"><span class="a">al_load_sample</span></a><span class="k2">(</span>...<span class="k2">)</span><span class="k2">;</span>

<span class="c">// Start a new sample playback.</span>

<a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE_INSTANCE"><span class="a">ALLEGRO_SAMPLE_INSTANCE</span></a><span class="k3">*</span> instance <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_sample_instance"><span class="a">al_create_sample_instance</span></a><span class="k2">(</span>sample<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_attach_sample_instance_to_mixer"><span class="a">al_attach_sample_instance_to_mixer</span></a><span class="k2">(</span>instance, <a href="http://www.allegro.cc/manual/al_get_default_mixer"><span class="a">al_get_default_mixer</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="c">// Optionally set playmode, gain, pan etc.</span>
<a href="http://www.allegro.cc/manual/al_set_sample_instance_playing"><span class="a">al_set_sample_instance_playing</span></a><span class="k2">(</span>instance, <span class="k1">true</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Then you can pause it using <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_sample_instance_playing"><span class="a">al_set_sample_instance_playing</span></a></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 07 Dec 2015 07:01:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks a lot SiegeLord. That actually works. </p><p>------</p><p>Somewhat strange audio API. What&#39;s the difference between all these audio structs? ALLEGRO_SAMPLE holds the data, al_play_sample is just a shortcut wrapper (i think), what&#39;s up with audio instances and id? </p><p>I&#39;m having over 100 sounds at the moment in the project, would that method be appropriate as initialization: load sample, create instance, attach to mixer like 100 times?</p><p>UPD: Ok, i&#39;ve done some forum searches. Everything&#39;s clear now.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neuton Mouse)</author>
		<pubDate>Mon, 07 Dec 2015 17:05:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just to have this in sort of one place, <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a></span> contains the actual data, <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE_INSTANCE"><span class="a">ALLEGRO_SAMPLE_INSTANCE</span></a></span> contains the current play position, pan, speed and things like that (importantly, it allows you to have several of those for each <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a></span>). <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE_ID"><span class="a">ALLEGRO_SAMPLE_ID</span></a></span> is essentially an index to an internal array of <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE_INSTANCE"><span class="a">ALLEGRO_SAMPLE_INSTANCE</span></a></span>.</p><p>In my games I typically make a vector of <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE_INSTANCE"><span class="a">ALLEGRO_SAMPLE_INSTANCE</span></a></span> and perhaps cap it at some number (only for the purposes of not washing out the sound, there shouldn&#39;t be much performance issues). Sometimes I add a priority to these sounds, so that if a new sound is played at a low priority, it won&#39;t kick out something at a higher priority. This also allows me to do positional audio (I store the physical location for each instance, and then adjust the pan and volume in relation to where the camera is).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 07 Dec 2015 22:11:52 +0000</pubDate>
	</item>
</rss>
