<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>How to find the last possible position of a sample instance</title>
		<link>http://www.allegro.cc/forums/view/616720</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 10 Feb 2017 08:08:13 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is it possible to find the last possible position of a sample instance?</p><p>My brute force method is to have the program output <tt>al_get_sample_instance_position(instance)</tt>  every tick and then listen to the instance to completion, however I can&#39;t help but feel like there is a more elegant way to get this in the code. Is there?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AgentBaron)</author>
		<pubDate>Thu, 02 Feb 2017 06:34:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_get_sample_length"><span class="a">al_get_sample_length</span></a></span> should do what you want if you want the number of samples. If you want the duration of a sample in seconds, you&#39;ll need to divide by <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_sample_frequency"><span class="a">al_get_sample_frequency</span></a></span> and perhaps <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_sample_channels"><span class="a">al_get_sample_channels</span></a></span>, converting it to a channel count first.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 02 Feb 2017 06:53:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><tt>al_get_sample_instance_length()</tt> is actually tremendously helpful, thanks! What&#39;s weird, though, is that when I use my brute force method and compare it to <tt>al_get_sample_instance_position()</tt>, I get a value that is less than my brute force output.</p><p>I&#39;m trying to get a song to loop back on itself, but it has an intro. So I&#39;m trying to play the intro and then get the main looping part of the song to play immediately after, seamlessly. The problem is that I am not aware of a way to track when the song is finished playing to tell this thing to loop, and I thought that if I could know the length I could nail it that way. This works somewhat, except that I am getting different values when I play the song. I can&#39;t begin to postulate what this means, but it does create a conundrum for me.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AgentBaron)</author>
		<pubDate>Wed, 08 Feb 2017 10:50:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Get the duration of the sample as I suggested earlier and use a timer, or otherwise call <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_sample_instance_playing"><span class="a">al_get_sample_instance_playing</span></a></span> repeatedly until it returns false.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 08 Feb 2017 20:58:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You could use an audio stream and feed the sample data to it manually, thereby eliminating the glitch? It might not lead to the best performance possible, but it will sound perfect.</p><p>Trying to use CPU timing or system clock timing to place an audio sample will always be imperfect. It&#39;s much better if you can specify the exact position in the output stream that the sample should start (which you can do if you&#39;re feeding the data to a stream yourself).</p><p>Or does Allegro have a &#39;play something at a scheduled instant in the audio output&#39; feature? Could one be added?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Perry)</author>
		<pubDate>Wed, 08 Feb 2017 21:24:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Maybe you could also use <tt>al_set_audio_stream_loop_secs</tt> directly to set the stream&#39;s loop points, if you use audio streams via <tt>al_load_audio_stream()</tt>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Thu, 09 Feb 2017 03:48:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Edgar&#39;s idea worked perfectly for what I was trying to do. I should have known better, but for some reason I was under the impression that the <tt>playing</tt> property wouldn&#39;t get kicked to false once it stopped playing.</p><p>Monitoring that and throwing a bool around helped me get everything taken care of. Thanks so much for the help!</p><p>For the sake of time, this seems like the best option, and then once I no longer have due dates on this project, I can experiment with some of the other ideas you all have thrown around to see what I can do about optimization.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AgentBaron)</author>
		<pubDate>Fri, 10 Feb 2017 08:08:13 +0000</pubDate>
	</item>
</rss>
