<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Android al_fseek() and al_ftell() Not Working</title>
		<link>http://www.allegro.cc/forums/view/611167</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 03 Oct 2012 10:53:04 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am in the process of trying to get the Allegro sound and audio codecs working on Android. I made a simple test program that just tries to load a WAV file and allows playback by touching the screen.</p><p>The WAV file failed to load so I started digging into the Allegro code to see if I could figure out where it is failing. I found that the loading began to fail immediately following a call to <span class="source-code"><a href="http://www.allegro.cc/manual/al_fseek"><span class="a">al_fseek</span></a><span class="k2">(</span><span class="k2">)</span></span>.</p><p>As a test, I added some calls to <span class="source-code"><a href="http://www.allegro.cc/manual/al_ftell"><span class="a">al_ftell</span></a><span class="k2">(</span><span class="k2">)</span></span> to see what position was being reported before and after the <span class="source-code"><a href="http://www.allegro.cc/manual/al_fseek"><span class="a">al_fseek</span></a><span class="k2">(</span><span class="k2">)</span></span> call. Both times it was reported as 0.</p><p>Looking at the code in <tt>android_apk_file.c</tt> I see that <span class="source-code"><a href="http://www.allegro.cc/manual/al_fseek"><span class="a">al_fseek</span></a><span class="k2">(</span><span class="k2">)</span></span> relies on <span class="source-code">APK_tell<span class="k2">(</span><span class="k2">)</span></span> to function. <span class="source-code">APK_tell<span class="k2">(</span><span class="k2">)</span></span> seems to always return 0 which means any call to <span class="source-code"><a href="http://www.allegro.cc/manual/al_fseek"><span class="a">al_fseek</span></a><span class="k2">(</span><span class="k2">)</span></span> will fail to work correctly. That means any loading function that needs <span class="source-code"><a href="http://www.allegro.cc/manual/al_fseek"><span class="a">al_fseek</span></a><span class="k2">(</span><span class="k2">)</span></span> or <span class="source-code"><a href="http://www.allegro.cc/manual/al_ftell"><span class="a">al_ftell</span></a><span class="k2">(</span><span class="k2">)</span></span> will not work.</p><p>I have been having trouble getting any of the audio codecs to work and I have a feeling this is why.</p><p>Append: I &quot;fixed&quot; <span class="source-code"><a href="http://www.allegro.cc/manual/al_fseek"><span class="a">al_fseek</span></a><span class="k2">(</span><span class="k2">)</span></span> and <span class="source-code"><a href="http://www.allegro.cc/manual/al_ftell"><span class="a">al_ftell</span></a><span class="k2">(</span><span class="k2">)</span></span> by storing the current position in the <span class="source-code">ALLEGRO_FILE_APK</span> struct. I don&#39;t really know how the <span class="source-code">_jni_call<span class="k3">*</span></span> stuff works so I don&#39;t know if there is a better way than what I&#39;m doing.</p><p>By fixing these functions, the WAV and MOD audio codecs are now working. Still can&#39;t get Vorbis or FLAC to work but I think that might be a different problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Tue, 02 Oct 2012 09:21:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s strange. It&#39;s the Java code that does the seeking so that&#39;s where to look. I has to rely on CRAP file routines provided by the Java api. I know freetype fonts do a lot of seeking and those work fine for me. How did you fix them?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 02 Oct 2012 09:25:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>TTF worked fine after turning off compression of the APK. What kind of seeking does Freetype use? <span class="source-code">SEEK_SET</span> works fine. <span class="source-code">SEEK_CUR</span> is the only one that doesn&#39;t work, actually, and that&#39;s because it relies on <span class="source-code">APK_tell<span class="k2">(</span><span class="k2">)</span></span> which always returns 0.</p><p>Looking at the Java code, I see that the position is already stored there. I don&#39;t see anything obviously wrong. Maybe there&#39;s something wrong in the <span class="source-code">jni_helpers.c</span>?</p><p>Edit: The function used by <span class="source-code">APK_tell<span class="k2">(</span><span class="k2">)</span></span> is actually located in <tt>include/allegro5/internal/aintern_android.h</tt>. Still don&#39;t see anything wrong there. I&#39;ll make a test program later to see if I can replicate the issue outside of the audio codecs add-on.</p><p>Edit 2: Just confirmed that <span class="source-code"><a href="http://www.allegro.cc/manual/al_ftell"><span class="a">al_ftell</span></a><span class="k2">(</span><span class="k2">)</span></span> always returns 0 in a small test program. Something has to be wrong with <span class="source-code">APK_tell<span class="k2">(</span><span class="k2">)</span></span>.</p><p>Edit 3: I figured out what the problem is. I&#39;ve attached a patch that fixes the issue. The problem was the <span class="source-code">APK_tell<span class="k2">(</span><span class="k2">)</span></span> function returns a <span class="source-code"><span class="k1">bool</span></span> instead of a <span class="source-code"><span class="k1">long</span></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Wed, 03 Oct 2012 10:28:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks. Committing in a minute.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Wed, 03 Oct 2012 10:53:04 +0000</pubDate>
	</item>
</rss>
