<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Audio: Modules loop even with ALLEGRO_PLAYMODE_ONCE</title>
		<link>http://www.allegro.cc/forums/view/615265</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 10 Apr 2015 11:24:36 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Exactly what the post title says, if you use the audio stream API to load a module (.it, etc.), even if you set the playmode to ALLEGRO_PLAYMODE_ONCE, the music will loop indefinitely.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Wed, 08 Apr 2015 07:17:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ll investigate this a bit, but keep in mind that (as far as I know), modules may specify a loop inside the file itself. If that&#39;s the case, there&#39;s nothing Allegro can do about that. Maybe try playing this file inside a different player and see if it loops forever there as well.</p><p>EDIT: I tried out a few mod&#39;s and xm&#39;s I had, and indeed many of them had internal loop events (or worse, events that literally just stopped the music). That said, turns out Allegro <b>can</b> do something about it. I&#39;ll investigate what&#39;s appropriate to do, but perhaps we could disable those loop points for PLAYMODE_ONCE.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Wed, 08 Apr 2015 08:13:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Having finally gotten Allegro to build on Windows, I tried making this experimental change at the beginning of modaudio_stream_update() (I know this will blow up if it&#39;s not an .it file, hence why it&#39;s experimental):</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 112</span>itr <span class="k3">=</span> duh_get_it_sigrenderer<span class="k2">(</span>df-&gt;sig<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 113</span>dumb_it_set_loop_callback<span class="k2">(</span>itr, stream-&gt;spl.loop <span class="k3">=</span><span class="k3">=</span> _ALLEGRO_PLAYMODE_STREAM_ONCE
<span class="number"> 114</span>    ? dumb_it_callback_terminate <span class="k2">:</span> NULL, NULL<span class="k2">)</span><span class="k2">;</span>
</div></div><p>

This indeed prevented it from looping, but caused a buffer overrun that I can&#39;t track down.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Wed, 08 Apr 2015 22:55:41 +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/615265/1011949#target">Bruce Pascoe</a> said:</div><div class="quote"><p> I know this will blow up if it&#39;s not an .it file, hence why it&#39;s experimental</p></div></div><p>It actually won&#39;t, those functions work for most module formats (although you need to check the return <span class="source-code">itr</span> just in case regardless). Strange about your buffer overrun though, I did not observe that when I tried the very same modification yesterday.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 09 Apr 2015 06:10:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, with that modification in place, when the stream is destroyed, MSVC reports heap corruption, breaking into the debugger in kcm_stream.c on line 152:</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_free"><span class="a">al_free</span></a><span class="k2">(</span>stream-&gt;main_buffer<span class="k2">)</span><span class="k2">;</span></span></p><p>Meaning stream-&gt;main_buffer was overrun somehow.  In Release mode, the application segfaults after the track ends, so it&#39;s not specific to a debug build.  Compiler is MSVC 2013 x86, for what it&#39;s worth.  Assuming the forums will let me post it, here&#39;s a link to the .it file I used for testing:</p><p><a href="https://drive.google.com/open?id=0BxPKLRqQOUSNVXhxNEpNdUJWbUE&amp;authuser=0">https://drive.google.com/open?id=0BxPKLRqQOUSNVXhxNEpNdUJWbUE&amp;authuser=0</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Thu, 09 Apr 2015 07:55:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks that was useful, it crashed for me too. There indeed was a buffer overflow bug, which is now fixed.</p><p>I&#39;ve also committed essentially the change you suggested, alongside with disabling the XM zero-speed events entirely: <a href="http://sourceforge.net/p/alleg/allegro/ci/954a979f17adcc6d9b1e157cb4782fc4b5d4f12e/">commit</a>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Fri, 10 Apr 2015 08:22:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Awesome, this fixes both issues.  I&#39;m glad, because I never would have found that buffer overrun... who knew it would be something as stupid as writing ints instead of bytes?  Certainly not me! <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Fri, 10 Apr 2015 11:24:36 +0000</pubDate>
	</item>
</rss>
