gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > Loading MOD audio files into the GBA

#27577 - gbawiz - Fri Oct 15, 2004 11:26 pm

Hello all,
I am trying to write a MOD player for my GBA projects and have some problems on incorporating the MOD file data into the ROM image.

The method which I have used thus far is to convert the binary MOD file into an object then include this object in compilation.
Then I have created a structure which is supposed to mirror the structure of the file. NOTE that i have set the sample name to 30. I have done this because there are 30 bytes per sample and the name is at the beginning of every sample.
Here is the code:
Code:

include"gba.h"

extern const unsigned char _binary_tunefile_mod_start[];

unsigned char *wram= (u8*)0x2000000;

typedef struct sample{
   unsigned char name[30]; // i set this to 30 because there are 30 bytes per sample
                     //i just want to try reading sample name first
}sampletype;

typedef struct mod{
   unsigned char song_name[20];
   sampletype sam[31];
}modtype;

int main()
{
   int n=0;
   modtype *music=(modtype*)_binary_tunefile_mod_start;

   for(n=0;n<20;n++)wram[n]=music->song_name[n];
   unsigned char *samname=music->sam[1].name;   // change this number to move through the samples
   
   for(n=0;n<22;n++)wram[n+21]=samname[n]; // displays the information found in the wram memory for viewing
}



The problem is that when i scan through the samples, there seems to be data missing, where as the sample number progresses, more of the sample name seems to vanish.
Im not sure what is the best way to load MOD files.
Can anyone help?

Thanks

#27581 - DekuTree64 - Sat Oct 16, 2004 12:54 am

Probably what's happening is that your struct is being padded to 4 bytes, so when you say music->sam[1].name, you're actually getting 32 bytes past music->sam, skipping over the first 2 letters of its name.

I wouldn't really suggest trying to work with straight MOD files in your GBA project, it'll just bog your game down trying to deal with all the quirky aspects of it, and probably be even more work trying to keep your head straight than just writing a converter tool up front to format the data exactly to your liking.

<shameless plug>
I'm not sure if you've seen it or not, but I'm writing an article series on creating a MOD player, check out day 3 for some info on creating a converter tool. They're always more ugly than they should be, but usually not too hard to get running properly anyway.
</shameless plug>
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#27600 - gbawiz - Sat Oct 16, 2004 6:17 pm

Thanks Dekutree,
I had a feeling that it may have had something to do with the padding after reading another article in this forum which had similar problems.

What you suggest is to use some kind of converter, and link the converted file into the ROM?

Would this mean that you would have to create structures and copy the data into them, resulting in 2 copies of the data? one in the linked file and the other in the structures.

Thanks

#27604 - DekuTree64 - Sat Oct 16, 2004 8:17 pm

I'm not sure I fully understand what you mean by having 2 copies of the data, the purpose of the converter is to avoid duplicating data.

Using the original MOD file, you'd either have to handle all the things like misalignment and unscrambling the pattern data while playing, or reformat the data into a temporary location in RAM to make it easy to use.

Instead of doing all that on the GBA, the converter (which is a regular PC program) should read in the data from the file, and reformat it the same way you'd do it into that temporary RAM location, and then print it all out into C/assembly/header/binary files that you include in ROM. That way, you only have that one ROM copy of the data, and you can use it like it is.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku