Broken MaxMod example.

support for the gba/nds sound library from

Moderator: eKid

Post Reply
Posts: 7
Joined: Tue Feb 24, 2009 8:53 am

Broken MaxMod example.

Post by mido » Thu Mar 05, 2009 12:00 am

edit: FFFFFFFFUUUUUU I should've put this in the libnds section


This example doesn't actually work when you run it. It compiled fine, latest devkitpro (I made sure this time :| ). At first I thought it just wasn't making noise, so I put some iprintf("Test")'s in there, lazy debugging, and it appears to freeze on

mmStreamOpen( &mystream ); is the offending line

Code: Select all

mm_stream mystream;
	mystream.sampling_rate	= 25000;					// sampling rate = 25khz
	mystream.buffer_length	= 1200;						// buffer length = 1200 samples
	mystream.callback		= on_stream_request;		// set callback function
	mystream.format			= MM_STREAM_16BIT_STEREO;	// format = stereo 16-bit
	mystream.timer			= MM_TIMER0;				// use hardware timer 0
	mystream.manual			= true;						// use manual filling
This is the struct getting fed into the stream initiate function, I tried a few things, make was throwing a warning from on_Stream_request as not being a valid pointer conversion, so I casted it to (void*) for kicks and giggles, same problem. If I comment out that section of code (the init function) the rest of the program that I loaded up with iprintf's runs fine. Only problem being that I can't use the stream functionality.

Tried running it on both no$gba and my actual DS, same problem on both.

In summary: Example program freezes on the line that initiates a stream, on hardware and emulation.

What's Maxmod doing? I'd like the streaming functionality.

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

Re: Broken MaxMod example.

Post by eKid » Thu Mar 05, 2009 3:26 pm

Oops, looks like that example wasn't updated for the latest release. To fix it, change the return type of the callback to 'mm_word' and add 'return length;' to the end of it (and also don't modify length). is updated for the last release.

What this new feature allows is that you can return how many samples you actually output, so if you're not ready to output all of the samples you can fill an amount smaller than the amount asked for (or maybe 0 to skip the fill completely).

Posts: 7
Joined: Tue Feb 24, 2009 8:53 am

Re: Broken MaxMod example.

Post by mido » Sat Mar 07, 2009 10:57 am


THE ISSUE: The original example code didn't take the mm_word return addition into account (returning how much you want to have next update), and the old for loop worked by decrementing [length] by one till the loop broke (clever, but not for the updated maxmod). So after dicking with it for a few hours I made length unaffected.

edit: Let it be clear that I didnt spend hours editing the for loop <_<. The issue was identifying why it wasn't working like you described it should. No worries though, thanks for the help

Code: Select all

 * on_stream_request
 * Audio stream data request handler.
mm_word on_stream_request( mm_word length, mm_addr dest, mm_stream_formats format ) {
	mm_word n;
	s16 *target = dest;
	// synthensize a sine wave with an LFO applied to the pitch
	// the stereo data is interleaved
	for( n = 0 ; n < length ; ++n )
		int sample = sinLerp(sine);
		// output sample for left
		*target++ = sample;
		// output inverted sample for right
		*target++ = -sample;
		sine += sine_freq + (sinLerp(lfo) >> lfo_shift);
		lfo = (lfo + lfo_freq);

	return length;

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest