/*----------------------------------------------------------------------------
  Shinobi2 Sample
  COPYRIGHT (C) SEGA ENTERPRISES, LTD.
----------------------------------------------------------------------------*/

#include	<shinobi.h>
#include	<sg_sd.h>
#include	"sd.h"

/*----------------------------------------------------------------------------
	サウンド初期化
----------------------------------------------------------------------------*/
Void SoundInit( Void )
{
	SDMEMBLK	memblk = NULL;
	Void		*ptr;
	Void		*drv_ptr = NULL;
	Sint32		drv_sz = 0;
	SDS_VER		drv_ver;

		/* サウンドライブラリの初期化 */
	/* Initialize sound library.  */
	sdLibInit( NULL, 0, 0 );
	sdDrvGetBuildinImage( &drv_ptr, &drv_sz, &drv_ver);
	ptr = syMalloc( drv_sz + 32);
	memcpy( ptr, drv_ptr, drv_sz);

	/* 	Download and Initialize Sound driver.	 */
	/*	Create Memory block handle  */
	sdMemBlkCreate( &memblk );

	/*  Setting Memoby block handle  */
	sdMemBlkSetPrm( memblk, ptr, drv_sz, SDD_MEMBLK_SYNC_FUNC, NULL );

	/*	Initialize Sound driver  */
	sdDrvInit( memblk );
	sdMemBlkDestroy( memblk );
	
	syFree( ptr);
}
/*----------------------------------------------------------------------------
	サウンド終了
----------------------------------------------------------------------------*/
Void SoundExit( Void )
{
	/*	Stop All Sound  */
	sdSndStopAll();
	/*	Clear current FX program  */
	sdSndClearFxPrg();
	/*	Close all MIDI port  */
	sdMidiCloseAll();
	/*	Close all PCM Stream port  */
	sdPstmCloseAll();
	/*	Close all One Shot port  */
	sdShotCloseAll();
	/*	Destory all memory block handle  */
	sdMemBlkDestroyAll();

	/* サウンドライブラリ・サウンドドライバの終了処理 */
	/* Finalize sound library and sound driver.      */
	sdSysFinish();
}
/*--------------------------------------------------------------------------*/
