<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] Getting a SAMPLE_INSTANCE* from a SAMPLE_ID</title>
		<link>http://www.allegro.cc/forums/view/605885</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 22 Dec 2010 17:25:42 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Simple question: Given an ALLEGRO_SAMPLE_ID from al_play_sample, how do I get its corresponding ALLEGRO_SAMPLE_INSTANCE* so I can adjust its volume, etc.?</p><p>EDIT: Also, what is the difference between al_sample_stop_sample_instance and al_set_sample_instance_playing(false) ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Wed, 22 Dec 2010 15:00:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s been a while since I used A5&#39;s sound routines. 
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605885/895922#target">X-G</a> said:</div><div class="quote"><p> Given an ALLEGRO_SAMPLE_ID from al_play_sample, how do I get its corresponding ALLEGRO_SAMPLE_INSTANCE* so I can adjust its volume, etc.?
</p></div></div><p>I&#39;m not sure that you can. (That&#39;s not to say it wouldn&#39;t be nice to be able to get the sample instance from an ID.) </p><p>I think in that case you have to use the more &quot;advanced&quot; API:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE_INSTANCE"><span class="a">ALLEGRO_SAMPLE_INSTANCE</span></a><span class="k3">*</span> sample_inst <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_play_sample_instance"><span class="a">al_play_sample_instance</span></a><span class="k2">(</span>sample_inst<span class="k2">)</span><span class="k2">;</span>
<span class="c">/* make changes to that sample_inst ... */</span>
</pre></div></div><p>
You can create multiple instances of the same sample. </p><p>Note that the API you&#39;re currently using via <span class="source-code"><a href="http://www.allegro.cc/manual/al_reserve_samples"><span class="a">al_reserve_samples</span></a><span class="k2">(</span><span class="k2">)</span></span> is basically just a shortcut for the above. </p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Also, what is the difference between al_sample_stop_sample_instance and al_set_sample_instance_playing(false) ?
</p></div></div><p>Nothing, as far as I know. Could be wrong. But I think a long, long time ago there was some internal back-and-forth between having one or two abstract property getter and setters vs having unique functions, and perhaps there&#39;s still some (unintended?) multiple ways of doing things.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 22 Dec 2010 15:46:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, looks like it. I&#39;ll do it the &quot;manually created sample instance&quot; way, but it seems such a shame to have convenience functions in the library and then not allow you to use any of the functions you actually want to use on the result (aside from stop). Personally I kinda feel that al_play_sample should return an ALLEGRO_SAMPLE_INSTANCE* rather than that ID thing. Maybe. Could be some internal reason why it shouldn&#39;t. Either way...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Wed, 22 Dec 2010 15:56:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605885/895926#target">X-G</a> said:</div><div class="quote"><p>Personally I kinda feel that al_play_sample should return an ALLEGRO_SAMPLE_INSTANCE* rather than that ID thing. Maybe. Could be some internal reason why it shouldn&#39;t.</p></div></div><p>
I think that it may have done that at one point in the past. I don&#39;t remember the reasons for changing that though, but it could have something to do with the persistance of the ALLEGRO_SAMPLE_INSTANCE pointer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 22 Dec 2010 16:07:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Could be, but then at least there needs to be an al_get_sample_instance_from_id(). Basically what I&#39;m trying to do is the equivalent of adjust_sample from A4... which does exist in the form of sample_instance_set*, but if I can&#39;t get an instance...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Wed, 22 Dec 2010 16:12:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605885/895928#target">Evert</a> said:</div><div class="quote"><p> I think that it may have done that at one point in the past. I don&#39;t remember the reasons for changing that though, but it could have something to do with the persistance of the ALLEGRO_SAMPLE_INSTANCE pointer.
</p></div></div><p>Originally <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a></span> was <span class="source-code">ALLEGRO_SAMPLE_DATA</span> and <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE_INSTANCE"><span class="a">ALLEGRO_SAMPLE_INSTANCE</span></a></span> was <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a></span>. I switched it around to the way it was now in order to make the &quot;simple&quot; mode the default. (i.e., To work more like Allegro 4.)</p><p>I&#39;d have to look at the source to refresh myself, but I&#39;m thinking that if the actual instance were returned, you could completely mess up future <span class="source-code"><a href="http://www.allegro.cc/manual/al_play_sample"><span class="a">al_play_sample</span></a></span> calls if you did things like destroyed that sample instance.</p><p><b>Edit:</b> It seems like the advantage of the current setup is that you never have to <span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_sample_instance"><span class="a">al_destroy_sample_instance</span></a><span class="k2">(</span><span class="k2">)</span></span> when doing an <span class="source-code"><a href="http://www.allegro.cc/manual/al_play_sample"><span class="a">al_play_sample</span></a><span class="k2">(</span><span class="k2">)</span></span>. When it&#39;s done playing, it&#39;s lost, and it can be reused.</p><p>I think we could introduce an <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE_ID"><span class="a">ALLEGRO_SAMPLE_ID</span></a></span> to <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE_INSTANCE"><span class="a">ALLEGRO_SAMPLE_INSTANCE</span></a></span> function if:
</p><ul><li><p>it returned <span class="source-code">NULL</span> if the sample has expired (finished playing)
</p></li><li><p>the call to <span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_sample_instance"><span class="a">al_destroy_sample_instance</span></a><span class="k2">(</span><span class="k2">)</span></span> returned <span class="source-code"><span class="k1">false</span></span> if you tried to destroy a reserved sample</p></li></ul><p>While <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE_ID"><span class="a">ALLEGRO_SAMPLE_ID</span></a></span> would not be strictly necessary if it were impossible to destroy the reserved instances, I think it would still be useful so you know whether or not you&#39;re dealing with the same instance as you think you are.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 22 Dec 2010 17:09:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605885/895935#target">Matthew Leverton</a> said:</div><div class="quote"><p>I think we could introduce an ALLEGRO_SAMPLE_ID to ALLEGRO_SAMPLE_INSTANCE function if:</p><p>    *</p><p>      it returned NULL if the sample has expired (finished playing)<br />    *</p><p>      the call to al_destroy_sample_instance() returned false if you tried to destroy a reserved sample</p></div></div><p>
Agreed. The documentation should also come with a big fat warning to use the returned sample immediately and not store it. Even then there is a chance that by the time you use it the sample has expired.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 22 Dec 2010 17:25:42 +0000</pubDate>
	</item>
</rss>
