Question about streaming

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

Moderator: eKid

Post Reply
ben
Posts: 1
Joined: Sun Jun 10, 2012 1:25 pm

Question about streaming

Post by ben » Sun Jun 10, 2012 2:21 pm

Hi everybody,

I'm new in DS programming, and I want to create a synth with maxmod. The idea is to stream sinus, triangle and square waveforms to create sound (like Moog synths if you know them).

I downloaded and ran the code found here, it works on my DS, but I don't understand how the buffer is working...

Can I fill the buffer with a period of a square (like this one but with one single period: Image) ?
Does the size of the buffer will change the sound i'll hear if I stream this buffer ?
And in what direction do I write the buffer and I read it ?

Thanks for your help.

Ben

Tomwi
Posts: 1
Joined: Tue Jun 12, 2012 11:35 am

Re: Question about streaming

Post by Tomwi » Tue Jun 12, 2012 12:06 pm

You can indeed fill the buffer with "square waves". But well let me explain what happens:

when you open the stream in maxmod, you have to provide a callback:

Code: Select all

mystream.callback       = on_stream_request;    
Maxmod will call this callback function to get some new samples. So essentially what this function should do, is giving maxmod new samples to play.

So a simple callback which writes zeroes could look like:

Code: Select all

mm_word on_stream_request( mm_word length, mm_addr dest, mm_stream_formats format ) {

	s16 *outBuf = dest; // Maxmod passes a pointer to a buffer you should write to
    
	/* We'll write the requested amount of samples to this buffer.
	 * This should be done in an upward direction
	 */
	int len = length;
    for( ; len; len-- )
    {
		/* This function simply writes zeroes, you should add your own code to write squares here */
        *outBuf++ = 0; 
    }
    /* You should return the amount of samples you've written, that doesn't have to be equal to length, 
     * it could be less 
     */
    return length;
}
I don't know what the minimum buffer size is (that maxmod can handle), so you may not be able to write one period of your square wave. This shouldn't be a big problem though as you can write multiple square waves in the callback.
Does the size of the buffer will change the sound i'll hear if I stream this buffer ?
Yes it can change the sound you'll be hearing. If an underrun occurs (the samples aren't written fast enough to the buffer), you'll hear noise. When I was streaming OGG files with maxmod, my initial buffer was too small and that caused maxmod to run out of samples before I could write new samples.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests