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.

DS development > Load sound banks/songs/samples..?

#173934 - Ruben - Sun May 09, 2010 6:32 am

Hi.

So I'm in the final stages of my Midi player [and yes, it WILL be adapted to libnds before that =P]... and just one thing remains unsettled: dynamic loading.

From what I've seen, official games load songs from their filesystem, followed by loading banks [instruments] and samples. While overall it seems easy... what exactly should be done? I mean... the main issues are keeping track of what has been malloc'd so that it may be free'd after. I have been able to load from a sound database file quite successfully, but only with this problem. I can't think of any proper way to keep track of what to free after it's all loaded.

Any ideas?

#173938 - headspin - Sun May 09, 2010 11:44 am

Um, free everything you malloc'ed. Why wouldn't you know what has been malloc'ed?

You can always have data buffers initialized to NULL and check it later.

Code:
char* buffer = NULL;

buffer = (char*) malloc(..);

if(buffer != NULL)
{
    free(buffer);
    buffer = NULL;
}

_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#173941 - Ruben - Sun May 09, 2010 12:19 pm

Because this is what is done [in ASM to make matters worse xP]:

-sxdsLoadSong which will load song data into memory with malloc [poitner returned to caller]
-this calls sxdsLoadBank, which will load a bank into memory with malloc, and will call sxdsLoadSamp
-this will load samples into memory with malloc

... See what I mean? xP

EDIT:
Probably doesn't help that I allow up to 8 songs playing at once, with up to 8 different banks and 256 different samples in memory at once >_>'

#174067 - dheart88 - Sun May 16, 2010 10:55 pm

is it fit in DS 4 MB ram?? why it has to be MIDI if mod is better? MOD has it's own sample and MIDI still depend on the hardware sample.. So you really put all the sample so this midi can work??

Suggestion:
how about this, first before generate the output, your program will only select resources/samples needed before it's loaded to RAM, so it'll be only 16 samples (if I'm not mistaken, midi can only have 16 channels right?? I still remember my old days with yamaha PSR series) so it won't ended with 256 samples... (or maybe because there are 16sample each song * 8 song =256??)

#174077 - Ruben - Mon May 17, 2010 5:10 am

It doesn't exactly work that way, because Midi 'patches' or 'programs' depend on more than one sample most of the time. But it doesn't matter anymore, cos I already sorted this: I do the exact opposite of the loading routines, going through all tones and instead of loading, freeing.

Now, if only porting to libnds was easier... >_<'