Getting soundbank filenames or using directory as soundbank

support for the gba/nds sound library from www.maxmod.org

Moderator: eKid

Post Reply
tasteforreality
Posts: 4
Joined: Fri Jul 11, 2008 4:37 pm

Getting soundbank filenames or using directory as soundbank

Post by tasteforreality » Sun Jan 25, 2009 2:00 am

Hi, two questions

firstly, is it possible to get a list of the filenames within the soundbank? i'd like to use maxmod in a sample/loop player and i basically want to be able to reassign what sound effects a specific button/touchscreen sprite will play. from reading the documentation it seems that the names of songs/effects need to be hardcoded when everything is compiled. is this the case or is there some way of reading the names in from the header file or some such?

second question is exactlly what it sounds

would it be possible to use a directory as a soundbank so that the sounds don't have to be pre compiled in? im guessing that it might be possible using the streaming functions but this seems like it would over complicate things quite alot. is there possibly something using mmSetCustomSoundBankHandler??

cheers for any help on this stuff

eKid
Posts: 65
Joined: Sat Dec 06, 2008 6:07 pm
Contact:

Re: Getting soundbank filenames or using directory as soundbank

Post by eKid » Tue Jan 27, 2009 1:03 pm

tasteforreality wrote:firstly, is it possible to get a list of the filenames within the soundbank?
No, all extra strings are removed from the files.
tasteforreality wrote:i'd like to use maxmod in a sample/loop player and i basically want to be able to reassign what sound effects a specific button/touchscreen sprite will play. from reading the documentation it seems that the names of songs/effects need to be hardcoded when everything is compiled. is this the case or is there some way of reading the names in from the header file or some such?
Are the set of sounds going to be fixed? Or do you want to change them during runtime? If they are fixed then it's just a matter of organizing the produced song/sample indexes. Otherwise it gets much more complicated :( The soundbank system is mostly designed for easily adding audio to a game.
tasteforreality wrote: would it be possible to use a directory as a soundbank so that the sounds don't have to be pre compiled in? im guessing that it might be possible using the streaming functions but this seems like it would over complicate things quite alot. is there possibly something using mmSetCustomSoundBankHandler??
Hmm, you could use the custom handler to load data from files in the directory, but everything will still be indexed based, and the system is pretty complicated :/... Will mmEffectEx suffice? mmEffectEx can play external samples that are not contained in your soundbank.

tasteforreality
Posts: 4
Joined: Fri Jul 11, 2008 4:37 pm

Re: Getting soundbank filenames or using directory as soundbank

Post by tasteforreality » Tue Jan 27, 2009 7:55 pm

the idea would be to make it possible to change the samples being triggered during runtime. id prefer not to have to recompile and recode sections of the program every time i want to add in a new sample.

i hadn't noticed that mmEffectEx could be used to play samples outside of the soundbank. does that mean that i could have, say, a folder into which wav files were dropped, then some function to load them into memory and assign an ID top them as they are needed?

if this is the case, how could i go about doing that? if not, what would i be able to use it for.

i appreciate that this is getting outside of what maxmod was designed for so i appreciate any help

eKid
Posts: 65
Joined: Sat Dec 06, 2008 6:07 pm
Contact:

Re: Getting soundbank filenames or using directory as soundbank

Post by eKid » Wed Jan 28, 2009 5:03 am

If you're using mmEffectEx to play an external sound then they don't need IDs. You just give an 'mm_ds_sample' as the 'sample' instead of giving an ID.

An example to create a generated sample: (in your case you want to replace the synthesis with a WAV loader)

Code: Select all

//-----------------------------------------------------------------
	// create our custom sample
	//-----------------------------------------------------------------
	
	// allocate memory for sample
	// the sample header and data must be in mainram (for ARM7 side)
	my_very_own_sample = malloc( sizeof( mm_ds_sample ) );
	
	// disable loop
	my_very_own_sample->loop_start = 0;
	
	// set length = 1000 words (4000 samples @ 8bit)
	my_very_own_sample->length = 1000;
	
	// format: 0 = 8bit, 1 = 16bit, 2 = adpcm
	my_very_own_sample->format = 0;
	
	// repeat, 1 = looping sample, 2 = one-shot sample
	my_very_own_sample->repeat_mode = 2;
	
	// base rate, 0x400/2 = 16KHz, (KHz = (base_rate * 32) / 0x400)
	my_very_own_sample->base_rate = 0x400/2;
	
	// allocate sample data
	my_very_own_sample->data = malloc( my_very_own_sample->length * 4 );
	
	{
		//-------------------------------------------
		// generate fading square wave as sample data
		//-------------------------------------------
		
		int t;
		s8* sample = my_very_own_sample->data;
		int a;
		int volume = 1000*4;
		for( t = 0; t < my_very_own_sample->length * 4; t++ )
		{
			if( (t & 63) > 20 )
				a = 127;
			else
				a = -128;
			*sample++ = (a * volume) / (1000*4);
			volume--;
		}
	}
Then with mmEffectEx:

Code: Select all

mm_sound_effect sound;
	
	// sample = sample address of our sample
	// the 'id' parameter is not used
	sound.sample = my_very_own_sample;
	
	// rate = 0x400 which is 1.0 which is original playback rate
	sound.rate = 0x400;
	
	// handle = 0 means allocate a new handle
	sound.handle = 0;
	
	// volume = 200/256 = ~78%
	sound.volume = 200;
	
	// panning = 128/256 = centered
	sound.panning = 128;
	
	// play sound
	mmEffectEx( &sound );

tasteforreality
Posts: 4
Joined: Fri Jul 11, 2008 4:37 pm

Re: Getting soundbank filenames or using directory as soundbank

Post by tasteforreality » Thu Jan 29, 2009 7:50 pm

wow, thanks very much for all of that its really helpful


i figure that in the spirit of community ill post this on here

http://www.thisisnotalabel.com/How-to-R ... and-VB.php

explains how to go about reading wav files with C and what the headers in normal wav files are composed of. should be useful for other people finding this topic

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests