PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

OpenAL on Android: Is this a threading issue?

coreman2200 · 26 Apr 2012, 16:12 UTC
Hello,
I've taken upon a rather ambitious game dev project using Edgelib as middleware. I've stumbled through all of my other concerns (rather valiantly lol :) but this one I'm rather stumped on.

The game project required OGG Vorbis for the background audio, and obviously as Hekkus offered no such functionality and we are still seeking cross-platform portability, I had decided to implement OpenAL Soft for such uses, with the tremolo library for very quick ogg vorbis file decoding. After a bit I got OpenAL Soft to run as it should ~ sound effects work as they should, etc. I've finally gotten the music to start streaming, too, but then the issue arises.

Depending on the size of the buffers, the music will play for some bit of time (note that I set the initial buffers in the ESound_LoadMusic function) ~ somewhere between the load function and the play function, however, the file it seems is either seemingly deleted (*sometimes* you see a GC_CONCURRENT notice in the Android log saying that it has released an amount of memory equal to the size of the ogg file that had been loaded via a package) or otherwise un-accessible when a buffer needs to be updated with more decoded data.

I may very well just be reaching, here, but I was wondering if this is a threading issue - it loads the file in a separate thread, so the play/decode functions don't have the same access to this data (if it isn't, in fact, already purged from memory). What led me to think this is that when I move all of the initializing functions (setting the ogg_file, etc) to the ESound_PlayMusic function, it immediately crashes as soon as it gets to trying to decode any data supposedly stored in a SOUND_MUSIC struct.

Just trying to figure out how to handle that situation, as I'm wellllll into (further) murky waters when it comes to threading ~ I've very little hands-on experience in that realm of development... I guess this'd be a great way to be introduced ha.

Any help would be more than appreciated ~ any further details, I'm happy to provide.

Bests,
Cory
Coreman2200
coreman2200 · 26 Apr 2012, 22:17 UTC
Well, while not specifically the answer to my question, I did finally resolve the issue :)

I just re-jiggered the LoadBufferMemory function used for sound effects to essentially just Copy the memory from the data source to some newly allocated space pointed to by the data var in my SOUND_MUSIC struct, like so:

Code:

void LoadBufferMemory(SOUND_MUSIC *music, void *memory, unsigned long memorysize)
{
//LOGA("Loading Buffer Memory..");
music->data = (char *)ClassEMemory::Alloc(memorysize); //Reserve the space..
ClassEMemory::Set(music->data, 0, memorysize); // Initialize to zero (maybe unnecessary?
ClassEMemory::Copy(music->data, (unsigned char *)memory, memorysize); // Copy data over..
memory = music->data; // I changed what memory was pointing to in case it is passed on, later
music->dataSize = music->stream.size = memorysize; // Remember file size
music->stream.buffer = music->data; // Set the stream buffer to where data points
//LOGA("Loading Buffer Memory Complete.");
}


There was originally a call to alBufferData in there, somewhere but as I have that handled, elsewhere, it was unnecessary/possibly problematic.

Works well, now :)