/*
//////////////////////////////////////////////////////////////
//	SNDXD.C													//
//////////////////////////////////////////////////////////////
//	Module d'exploitation des samples PCM en 3D				//
//------------ version 2D (Dx2D, WinMM,..)-------------------------------
//////////////////////////////////////////////////////////////
*/
#include "SNDinc.h"
 
#ifndef DISABLE_ADPCM
 
 
 
#ifndef NO_ACP_SOUND
 
#if defined(_DLL_COMPILATION_MODE) 
#include "snddll.h"
#endif
 
#include "sndres.h"
#include "sndxdapm.h"
#include "sndadpcm.h"
#include "sndxd.h"
 
/*
 * FADE DURATION EXPRESSED IN "SNDREAL"
 */
#define M_FADE_DURATION_ADPCM ( 1 << 16 )
 
 
static SndBool g_bInitOK=FALSE;
 
long SND_CALL SND_fn_lPlaySxdADPCM(tduRefRes res,SoundParam *par3D,long prio,SND_td_pfn_vSoundCallback fn_callback,long par_callback)
{
	long ret;
	SampleParam par2D;
 
	if (!g_bInitOK)
		return C_PLAY_FAILED;
 
	SND_fn_vParam3Dto2D(par3D,&par2D);
 
	ret=SND_fn_lPlaySampleADPCM(res,&par2D,prio,fn_callback,par_callback);
 
	return ret;
}
 
void SND_CALL SND_fn_vRemoveCallbackSxdADPCM(long voice)
{
	SND_fn_vRemoveCallbackSampleADPCM(voice);
}
 
SndBool	SND_CALL SND_fn_bSetParamSxdADPCM(long voice,SoundParam *par3D)
{
	SndBool ret;
	SampleParam par2D;
 
	SND_fn_vParam3Dto2D(par3D,&par2D);
 
	ret=SND_fn_bSetParamSampleADPCM(voice,&par2D);
 
	return ret;
}
 
SndBool	SND_CALL SND_fn_bTestIsPlayingSxdADPCM(long voice)
{
	return SND_fn_bTestIsPlayingSampleADPCM(voice);
}
 
void SND_CALL SND_fn_vStopSxdADPCM(long voice)
{
	SND_fn_vStopSampleADPCM(voice);
}
 
void SND_CALL SND_fn_vPauseSxdADPCM(long voice)
{
	SND_fn_vPauseSampleADPCM(voice);
}
 
void SND_CALL SND_fn_vResumeSxdADPCM(long voice)
{
	SND_fn_vResumeSampleADPCM(voice);
}
 
SndBool SND_CALL SND_fn_bIsResourceLoopingSxdADPCM(tduRefRes res)
{
	return SND_fn_bIsResourceLoopingSampleADPCM(res);
}
 
SndReal	SND_CALL SND_fn_rGetPosSxdADPCM(long voice)
{
	return SND_fn_rGetPosSampleADPCM(voice);
}
 
SndReal	SND_CALL SND_fn_rGetLengthSxdADPCM(long voice)
{
	return SND_fn_rGetLengthSampleADPCM(voice);
}
 
void SND_CALL SND_fn_vSetSoundVolumeSxdADPCM(unsigned char vol)
{
	SND_fn_vSetSoundVolumeSampleADPCM(vol);
}
 
unsigned char SND_CALL SND_fn_ucGetSoundVolumeSxdADPCM()
{
	return SND_fn_ucGetSoundVolumeSampleADPCM();
}
 
void SND_CALL SND_fn_vSetStereoSxdADPCM(SndBool active)
{
	SND_fn_vSetStereoSampleADPCM(active);
}
 
SndBool	SND_CALL SND_fn_bGetStereoSxdADPCM(void)
{
	return SND_fn_bGetStereoSampleADPCM();
}
 
void SND_CALL SND_fn_vSetReverseStereoSxdADPCM(SndBool active)
{
	SND_fn_vSetReverseStereoSampleADPCM(active);
}
 
SndBool	SND_CALL SND_fn_bGetReverseStereoSxdADPCM(void)
{
	return SND_fn_bGetReverseStereoSampleADPCM();
}
 
int SND_CALL SND_fn_iInitSxdADPCM(SND_tdstInitStruct *pInitStruct)
{
#ifndef DISABLE_ADPCM
	g_bInitOK=TRUE;
 
#if defined(_DLL_COMPILATION_MODE)
    SND_DllInitEntryPoints_StaticFunctions((HMODULE)pInitStruct->hProcessInstance );
    SND_DllInitEntryPoints_WavFunctions(SND_hWavModule);
#endif
 
	return SND_fn_iInitSampleADPCM(pInitStruct);
#else
	return C_INIT_FAILED;
#endif /*DISABLE_ADPCM*/
}
 
SndBool	SND_CALL SND_fn_bTestInitSxdADPCM(void)
{
	return SND_fn_bTestInitSampleADPCM();
}
 
void SND_CALL SND_fn_vDesInitSxdADPCM(void)
{
	SND_fn_vDesInitSampleADPCM();
}
 
void SND_CALL SND_fn_vSetEffectSxdADPCM(long num)
{
	SND_fn_vSetEffectSampleADPCM(num);
}
 
void SND_CALL SND_fn_vCreateMicroSxdADPCM(MicroParam* par,long id)
{
	/*rien à faire en 2D*/
}
 
void SND_CALL SND_fn_vSetMicroParamSxdADPCM(long sxdId,MicroParam* par)
{
	/*rien à faire en 2D*/
}
 
void SND_CALL SND_fn_vDestroyMicroSxdADPCM(long sxdId)
{
	/*rien à faire en 2D*/
}
 
/*gestion de buffers*/
long SND_CALL SND_fn_lCreateNewBufferSxdADPCM(unsigned long nb_samples,unsigned short uwResolution,unsigned short uwNbChannels,unsigned long ulFreq,SoundParam* par3D,td_pfn_vRefreshBufferClient callback,long user_id)
{
	long ret;
	SampleParam par2D;
 
	if (!g_bInitOK)
		return C_PLAY_FAILED;
 
	SND_fn_vParam3Dto2D(par3D,&par2D);
 
	ret=SND_fn_lCreateNewBufferSampleADPCM(nb_samples,uwResolution,uwNbChannels,ulFreq,&par2D,callback,user_id);
 
	return ret;
}
 
void SND_CALL SND_fn_vSetParamBufferSxdADPCM(long id_buffer,SoundParam *par3D)
{
	SampleParam par2D;
 
	SND_fn_vParam3Dto2D(par3D,&par2D);
 
	SND_fn_vSetParamBufferSampleADPCM(id_buffer,&par2D);
}
 
void SND_CALL SND_fn_vDeleteBufferSxdADPCM(long id_buffer)
{
	SND_fn_vDeleteBufferSampleADPCM(id_buffer);
}
 
void SND_CALL SND_fn_vPauseBufferSxdADPCM(long id_buffer)
{
	SND_fn_vPauseBufferSampleADPCM(id_buffer);
}
 
void SND_CALL SND_fn_vResumeBufferSxdADPCM(long id_buffer)
{
	SND_fn_vResumeBufferSampleADPCM(id_buffer);
}
 
void* SND_CALL SND_fn_pvGetPtrBufferSxdADPCM(long id_buffer)
{
	return SND_fn_pvGetPtrBufferSampleADPCM(id_buffer);
}
 
SndReal	SND_CALL SND_fn_rGetPosBufferSxdADPCM(long id_buffer)
{
	return SND_fn_rGetPosBufferSampleADPCM(id_buffer);
}
 
#if !defined(NO_ACP_SCRIPT) || defined(_DLL_COMPILATION_MODE)
/*this function must be defined in Script/Hybrid or DLL mode*/
SndBool SND_CALL SND_fn_bLoadResScriptSxdADPCM(tdstBlockResourceDisk *disk,tdstBlockResourceMem *mem)
{
	return SND_fn_bLoadResScriptSampleADPCM( disk, mem );
}
#endif
 
SndBool SND_CALL SND_fn_bLoadResBinarySxdADPCM(tdstBlockResourceDisk *disk,tdstBlockResourceMem *mem,char *pDataBloc)
{
	return SND_fn_bLoadResBinarySampleADPCM(disk,mem,pDataBloc);
}
 
#if !defined(NO_ACP_SCRIPT) || defined(_DLL_COMPILATION_MODE)
/*this function must be defined in Script/Hybrid or DLL mode*/
SndBool SND_CALL SND_fn_bLoadResScriptAndConvertToWAVSxdADPCM(tdstBlockResourceDisk *disk,tdstBlockResourceMem *mem)
{
	return SND_fn_bLoadResScriptAndConvertToWAVSampleADPCM( disk, mem );
}
#endif
 
SndBool SND_CALL SND_fn_bLoadResBinaryAndConvertToWAVSxdADPCM(tdstBlockResourceDisk *disk,tdstBlockResourceMem *mem,char *pDataBloc)
{
	return SND_fn_bLoadResBinaryAndConvertToWAVSampleADPCM(disk,mem,pDataBloc);
}
 
void SND_CALL SND_fn_vUnLoadResSxdADPCM(tdstBlockResourceMem* mem)
{
	SND_fn_vUnLoadResSampleADPCM(mem);
}
 
SndBool SND_CALL SND_fn_bIsResLoadedSxdADPCM(tdstBlockResourceMem *mem)
{
	return SND_fn_bIsResLoadedSampleADPCM(mem);
}
 
/*---themes*/
long SND_CALL SND_fn_lPlayTransitionSxdADPCM(tduRefRes FirstRes,tduRefRes NextRes,SND_td_pfn_vSoundCallback transition_callback,long param_callback,SoundParam* par3D)
{
	SampleParam par2D;
 
	snd_assert(FirstRes.pstPtr->uRes.stSample.eZip==SAMPLE_ADPCM);snd_assert(NextRes.pstPtr->uRes.stSample.eZip==SAMPLE_ADPCM);
 
	if (!g_bInitOK)
		return C_PLAY_FAILED;
 
	SND_fn_vParam3Dto2D(par3D,&par2D);
 
	return SND_fn_lPlayTransitionSampleADPCM(FirstRes,NextRes,transition_callback,param_callback,&par2D);
}
 
SndBool SND_CALL SND_fn_bSetParamTransitionSxdADPCM(long voice,SoundParam *par3D)
{
	SampleParam par2D;
 
	SND_fn_vParam3Dto2D(par3D,&par2D);
 
	return SND_fn_bSetParamTransitionSampleADPCM(voice,&par2D);
}
 
SndBool SND_CALL SND_fn_bSetNextTransitionSxdADPCM(long voice,tduRefRes new_res)
{
	snd_assert(new_res.pstPtr->uRes.stSample.eZip==SAMPLE_ADPCM);
 
	return SND_fn_bSetNextTransitionSampleADPCM(voice,new_res);
}
 
SndBool SND_CALL SND_fn_bDoTransitionWithFadeSxdADPCM(long voice,tduRefRes new_res)
{
	return SND_fn_bDoTransitionWithFadeSampleADPCM( voice, new_res, M_FADE_DURATION_ADPCM );
}
 
SndBool SND_CALL SND_fn_bDoTransitionWithFadeSxdADPCM2( long voice, tduRefRes new_res, SndReal rDuration )
{
	return SND_fn_bDoTransitionWithFadeSampleADPCM( voice, new_res, rDuration );
}
 
void SND_CALL SND_fn_vStopTransitionSxdADPCM(long voice)
{
	SND_fn_vStopTransitionSampleADPCM(voice);
}
 
void SND_CALL SND_fn_vPauseTransitionSxdADPCM(long voice)
{
	SND_fn_vPauseTransitionSampleADPCM(voice);
}
 
void SND_CALL SND_fn_vResumeTransitionSxdADPCM(long voice)
{
	SND_fn_vResumeTransitionSampleADPCM(voice);
}
 
#ifndef NO_ACP_LDBIN
SndBool SND_CALL SND_fn_bCanFreeDataADPCM(void)
{
	return SND_fn_bCanFreeDataSampleADPCM();
}
#endif
 
/*--relache-reprise a chaud des drives*/
void SND_CALL SND_fn_vReleaseDriverSxdADPCM(void)
{
	SND_fn_vReleaseDriverSampleADPCM();
}
 
void SND_CALL SND_fn_vRestoreDriverSxdADPCM(void)
{
	SND_fn_vRestoreDriverSampleADPCM();
}
 
void SND_CALL SND_fn_vGetTargetLabelSxdADPCM(char* name,int nb_char)
{
	SND_fn_vGetTargetLabelSampleADPCM(name,nb_char);
}
 
void SND_CALL SND_fn_vSetupTargetSxdADPCM()
{
	SND_fn_vSetupTargetSampleADPCM();
}
 
SndBool SND_CALL SND_fn_bCanSetupTargetSxdADPCM()
{
	return SND_fn_bCanSetupTargetSampleADPCM();
}
 
void SND_CALL SND_fn_vSynchroSxdADPCM()
{
	SND_fn_vSynchroSampleADPCM();
}
 
/*nouveaux buffers-clients*/
long SND_CALL SND_fn_lCreateNewBufferExSxdADPCM(SND_tdstFormat* pformat,SND_tdstCallback* pCallback,SoundParam* par,long user_id)
{
	if (!g_bInitOK)
		return C_PLAY_FAILED;
 
	return SND_fn_lCreateNewBufferExSampleADPCM(pformat,pCallback,par,user_id);
}
 
long SND_CALL SND_fn_lGetPosBufferExSxdADPCM(long id_buffer)
{
	return SND_fn_lGetPosBufferExSampleADPCM(id_buffer);
}
 
long SND_CALL SND_fn_lPushBufferExSxdADPCM(long id_buffer,SND_tdstStackBuffer* pStack)
{
	return SND_fn_lPushBufferExSampleADPCM(id_buffer,pStack);
}
 
void SND_CALL SND_fn_vSetDefaultRollOffSxdADPCM(RollOffParam* rolloff)
{
	/*nothing to do in this version!!*/
}
 
SndBool SND_CALL SND_fn_bCheckVersionResourceSxdADPCM(tdstBlockResourceDisk* disk)
{
	return SND_fn_bCheckVersionResourceSampleADPCM(disk);
}
 
long SND_CALL SND_fn_lGetNbVoiceWishedSxdADPCM()
{
	return SND_fn_lGetNbVoiceWishedSampleADPCM();
}
 
SndBool SND_CALL SND_fn_bIsLibActiveSxdADPCM()
{
#ifndef DISABLE_ADPCM
	return TRUE;
#else
	return FALSE;
#endif
}
 
SndBool SND_CALL SND_fn_bSetResourceStaticVolumeSxdADPCM(tdstBlockResourceMem* pstRes,unsigned char ucVolume)
{
	return SND_fn_bSetResourceStaticVolumeSampleADPCM(pstRes,ucVolume);
}
 
 
#endif /*NO_ACP_SOUND*/
 
#endif /* DISABLE_ADPCM*/
 
