Android al_fseek() and al_ftell() Not Working
Todd Cope

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.

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 al_fseek().

As a test, I added some calls to al_ftell() to see what position was being reported before and after the al_fseek() call. Both times it was reported as 0.

Looking at the code in android_apk_file.c I see that al_fseek() relies on APK_tell() to function. APK_tell() seems to always return 0 which means any call to al_fseek() will fail to work correctly. That means any loading function that needs al_fseek() or al_ftell() will not work.

I have been having trouble getting any of the audio codecs to work and I have a feeling this is why.

Append: I "fixed" al_fseek() and al_ftell() by storing the current position in the ALLEGRO_FILE_APK struct. I don't really know how the _jni_call* stuff works so I don't know if there is a better way than what I'm doing.

By fixing these functions, the WAV and MOD audio codecs are now working. Still can't get Vorbis or FLAC to work but I think that might be a different problem.

Trent Gamblin

That's strange. It's the Java code that does the seeking so that'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?

Todd Cope

TTF worked fine after turning off compression of the APK. What kind of seeking does Freetype use? SEEK_SET works fine. SEEK_CUR is the only one that doesn't work, actually, and that's because it relies on APK_tell() which always returns 0.

Looking at the Java code, I see that the position is already stored there. I don't see anything obviously wrong. Maybe there's something wrong in the jni_helpers.c?

Edit: The function used by APK_tell() is actually located in include/allegro5/internal/aintern_android.h. Still don't see anything wrong there. I'll make a test program later to see if I can replicate the issue outside of the audio codecs add-on.

Edit 2: Just confirmed that al_ftell() always returns 0 in a small test program. Something has to be wrong with APK_tell().

Edit 3: I figured out what the problem is. I've attached a patch that fixes the issue. The problem was the APK_tell() function returns a bool instead of a long.

Trent Gamblin

Thanks. Committing in a minute.

Thread #611167. Printed from Allegro.cc