test_music.c 3.24 KB

/*************************************************************

  test_music.c : Nintendo 64 Music Tools Library Sample
  (c) Copyright 1998, Software Creations (Holdings) Ltd.

  Version 3.11

  N64DD demo music related source file. 

**************************************************************/

/* include system header files */
#ifndef F3DEX_GBI
#define F3DEX_GBI
#endif

#include <ultra64.h>
#include <leo.h>
#include <libmus.h>

/* include application main header file */
#include "test_rom.h"

/* include application specific header files */
#include "test_n64dd.h"		/* disk access functions */
#include "test_mem.h"		/* memory manager functions */


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  [GLOBAL FUNCTION]
  InitMusicDriver()

  [Explantion]
  Download ROM files and initialise the music player.

  [Return value]
  NONE
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/

/* 'makerom' generated labels */

/* ROM addresses */
#define DISKWBANK_START	_wbankSegmentDiskStart
#define DISKWBANK_END	_wbankSegmentDiskEnd
#define DISKPBANK_START _pbankSegmentDiskStart
#define DISKPBANK_END	_pbankSegmentDiskEnd
#define DISKMUSIC_START	_tuneSegmentDiskStart
#define DISKMUSIC_END	_tuneSegmentDiskEnd

#ifdef __GNUC__
extern short int DISKWBANK_START;
extern short int DISKWBANK_END;
extern short int DISKPBANK_START;
extern short int DISKPBANK_END;
extern short int DISKMUSIC_START;
extern short int DISKMUSIC_END;
#else
extern char DISKWBANK_START[];
extern char DISKWBANK_END[];
extern char DISKPBANK_START[];
extern char DISKPBANK_END[];
extern char DISKMUSIC_START[];
extern char DISKMUSIC_END[];
#endif

/* permanent RAM buffers */
#define AUDIO_HEAP_SIZE	300000

/* memory buffers claimed from application heap */
unsigned char *audio_heap;
unsigned char *pointer_buffer;
unsigned char *sample_buffer;
unsigned char *tune_buffer;

void InitMusicDriver(void)
{
   musConfig init;

   /* allocate memory for audio heap */
   audio_heap = MemMalloc(AUDIO_HEAP_SIZE);

   /* allocate and read sample .ptr file */
   pointer_buffer = MemMalloc(DiskSize(DISKPBANK_START, DISKPBANK_END));
   DiskRead(DISKPBANK_START, DISKPBANK_END, pointer_buffer);

   /* allocate and read sample .wbk file */
   sample_buffer = MemMalloc(DiskSize(DISKWBANK_START, DISKWBANK_END));
   DiskRead(DISKWBANK_START, DISKWBANK_END, sample_buffer);

   /* allocate and read song .bin file */
   tune_buffer = MemMalloc(DiskSize(DISKPBANK_START, DISKPBANK_END));
   DiskRead(DISKMUSIC_START, DISKMUSIC_END, tune_buffer);

   /* setup configuration structure */
   init.control_flag	   = MUSCONTROL_RAM;    /* samples will be RAM based */
   init.channels		   = 16;
   init.sched		      = &sc;
   init.thread_priority	= 12;
   init.heap		      = audio_heap;
   init.heap_length	   = AUDIO_HEAP_SIZE;
   init.fifo_length	   = 64;
   init.ptr		         = pointer_buffer;
   init.wbk		         = sample_buffer;
   init.default_fxbank  = NULL;
   init.syn_output_rate	= 32000;
   init.syn_updates	   = 256;
   init.syn_rsp_cmds	   = 4096;
   init.syn_retraceCount= 1;
   init.syn_num_dma_bufs= 36;
   init.syn_dma_buf_size= 0x800;

// Special Addition for DDROM
   init.diskrom_handle = osDriveRomInit();
   MusInitialize(&init);
}


/* end of file */