void SoundSetup( BlackBox* sndeng, int srate, int bufsize ){
	GenSoundEngine = sndeng;
	mm_ds_system* sys = (mm_ds_system*)malloc( sizeof( mm_ds_system) );
	
	sys->mod_count 			= 0;
	sys->samp_count			= 0;
	sys->mem_bank			= 0;
	sys->fifo_channel		= FIFO_MAXMOD;
	
	mmInit( sys );
	
	//----------------------------------------------------------------
	// open stream
	//----------------------------------------------------------------
	
	mm_stream* mystream = (mm_stream*)malloc( sizeof( mm_stream ) );

	mystream->sampling_rate	= srate;					// sampling rate = 25khz
	mystream->buffer_length	= bufsize;					// 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		= false;					// use automatic filling
	mmStreamOpen( mystream );
}
Example #2
0
int initAudio()
{
	//----------------------------------------------------------------
	// initialize maxmod without any soundbank (unusual setup)
	//----------------------------------------------------------------
	
	sys.mod_count 			= 0;
	sys.samp_count			= 0;
	sys.mem_bank			= 0;
	sys.fifo_channel		= FIFO_MAXMOD;
	mmInit( &sys );
    
    // setup mixer stack
	for (int i=0; i<maxPoly; i++) {
		mixerStack[i].active = -1;
	}
	numPlaying = 0;
	
	stream.sampling_rate =  outputSampleRate;        // outputSampleRate
    stream.buffer_length = streamBufferLen;          // should be adequate
    stream.callback = fill_stream;       			// give fill routine
    stream.format = MM_STREAM_16BIT_MONO; 		// 16-bit mono
    stream.timer = MM_TIMER0;            		// use timer0
    stream.manual = 0;                   		// auto filling
    
    mmStreamOpen( &stream );
	
	return 0;
}
Example #3
0
/**********************************************************************************
 * main
 *
 * Program Entry Point
 **********************************************************************************/
int main( void ) {
//---------------------------------------------------------------------------------

    //----------------------------------------------------------------
    // print out some stuff
    //----------------------------------------------------------------
    consoleDemoInit();
    iprintf( "\n    Maxmod Streaming Example   \n");

    //----------------------------------------------------------------
    // initialize maxmod without any soundbank (unusual setup)
    //----------------------------------------------------------------
    mm_ds_system sys;
    sys.mod_count 			= 0;
    sys.samp_count			= 0;
    sys.mem_bank			= 0;
    sys.fifo_channel		= FIFO_MAXMOD;
    mmInit( &sys );

    //----------------------------------------------------------------
    // open stream
    //----------------------------------------------------------------
    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
    mmStreamOpen( &mystream );

    //----------------------------------------------------------------
    // when using 'automatic' filling, your callback will be triggered
    // every time half of the wave buffer is processed.
    //
    // so:
    // 25000 (rate)
    // ----- = ~21 Hz for a full pass, and ~42hz for half pass
    // 1200  (length)
    //----------------------------------------------------------------
    // with 'manual' filling, you must call mmStreamUpdate
    // periodically (and often enough to avoid buffer underruns)
    //----------------------------------------------------------------

    SetYtrigger( 0 );
    irqEnable( IRQ_VCOUNT );

    while( 1 )
    {
        // wait until line 0
        swiIntrWait( 0, IRQ_VCOUNT);

        // update stream
        mmStreamUpdate();

        // restore backdrop (some lines were drawn with another colour to show cpu usage)
        BG_PALETTE_SUB[0] = bg_colour;

        // wait until next frame
        swiWaitForVBlank();

        // set backdrop to show cpu usage
        BG_PALETTE_SUB[0] = cpu_colour;
    }

    return 0;
}