#ifndef _SNDTYPE_H_
#define _SNDTYPE_H_
 
#if (defined(__cplusplus)&& !defined(CPA_ForceCplusplus))
extern "C" {
#endif /* __cplusplus*/
 
/*
//////////////////////////////////////////////////////
//	SNDTYPE.H - Librairie SOUNDxd version 2.0		//
//////////////////////////////////////////////////////
//	Definitions des types et constantes utilisees	//
//	par tous les modules de SOUNDxD et strictement	//
//	portables (noms et membres communs)				//
//////////////////////////////////////////////////////
*/
#include "SND/snddef.h"
 
/*#include "cpa_std.h"*/
 
 
/*#include "sndhard.h"*/
 
 
#ifdef M_SET_ALIGNMENT
#pragma pack(push)
#pragma pack(M_SET_ALIGNMENT)
#endif
 
 
/*handles partages avec les autres moduless*/
#include "SND\sndhandl.h"
 
/*--------------------type PseudoReel-------------------*/
typedef long SndReal;
#define C_SNDREAL_1 0x10000 
#define C_SNDREAL_0 0x00000 
 
/*melting of 2 SndReal onto one 32-bits long*/
typedef long SndRealTwin;/*r1r1r2r2 nota:1.0/128<abs(r1)<128.0*/
/*extract 2 SndReal (poiter value passed) from 1 SndRealTwin (value passed)*/
#define M_SndRealTwinToSndReal(rtwin,pr1,pr2) *(pr1)=(((rtwin)>>16)<<8);*(pr2)=(((rtwin)<<16)>>8);
/*generate a SndRealTwin (return) from 2 SndReal passed*/
#define M_SndRealToSndRealTwin(r1,r2) ((SndRealTwin)(((r1)<<8)&xFFFF0000)&(((r2>>8)&0xFFFF)))
 
/***************** EVENTs **************************************/
/*declarations des types communs*/
typedef struct _SND_tdstBlockEvent SND_tdstBlockEvent;
typedef struct _SndVector SndVector;
typedef struct _MicroLink MicroLink;
typedef struct _SoundParam SoundParam;
typedef struct _ExtraSoundParam ExtraSoundParam;
typedef struct _RollOffParam RollOffParam;
typedef struct _SwitchParam SwitchParam;
typedef struct _SampleParam SampleParam;
typedef struct _MicroParam MicroParam;
typedef union _SND_tduRefEvt SND_tduRefEvt;
typedef struct _tdstSndPolyEvent tdstSndPolyEvent;
typedef struct _tdstAllRetObjectSound tdstAllRetObjectSound;
typedef struct _tdstAllRetMicroSound tdstAllRetMicroSound;
typedef struct _tdstAllRetChannelSound tdstAllRetChannelSound;
typedef union _tduRefRes tduRefRes;
 
/*structures definies ulterieuremenr*/
typedef struct _tdstBlockResourceDisk tdstBlockResourceDisk;
typedef struct _tdstBlockResourceMem tdstBlockResourceMem;
typedef struct _tdstSndPolyResource tdstSndPolyResource;
typedef struct _tdstInfoTrackDisk tdstInfoTrackDisk;
typedef struct _tdstInfoTrackMem tdstInfoTrackMem;
typedef struct _tdstTypeSampleDisk tdstTypeSampleDisk;
typedef struct _tdstSampleMemory        tdstSampleMemory;
typedef struct _tdstSampleStreaming     tdstSampleStreaming;
typedef union _tduDataSample tduDataSample;
typedef struct _tdstTypeSampleMem tdstTypeSampleMem;
typedef struct _tdstTypeMidiDisk tdstTypeMidiDisk;
typedef struct _tdstMidiMemory tdstMidiMemory;
typedef struct _tdstMidiStreaming tdstMidiStreaming;
typedef union _tduDataMidi tduDataMidi;
typedef struct _tdstTypeMidiMem tdstTypeMidiMem;
typedef struct _tdstTypeCD tdstTypeCD;
typedef struct _tdstTypeSequenceDisk tdstTypeSequenceDisk;
typedef struct _tdstTypeSequenceMem     tdstTypeSequenceMem;
typedef union _tduResDisk tduResDisk;
typedef union _tduResMem tduResMem;
typedef struct _tdstTypeSwitchDisk   tdstTypeSwitchDisk;
typedef struct _tdstTypeSwitchMem       tdstTypeSwitchMem;
typedef struct _tdstRefResList  tdstRefResList;
typedef struct _tdstRefRes      tdstRefRes;
typedef struct _tdstTypeSplitDisk      tdstTypeSplitDisk;
typedef struct _tdstTypeSplitMem       tdstTypeSplitMem;
typedef struct _tdstRangeSplitDisk  tdstRangeSplitDisk;
typedef struct _tdstRangeSplitListDisk tdstRangeSplitListDisk;
typedef struct _tdstRangeSplitMem  tdstRangeSplitMem;
typedef struct _tdstRangeSplitListMem tdstRangeSplitListMem;
typedef struct _tdstSwitchElement tdstSwitchElement;
typedef struct _tdstSwitchList tdstSwitchList;
typedef union _tduBlockResource tduBlockResource;
typedef struct _tdstThemeBridge tdstThemeBridge;
typedef struct _tdstThemePart tdstThemePart;
typedef struct _tdstThemePartOutro tdstThemePartOutro;
typedef struct _tdstTypeThemeDisk tdstTypeThemeDisk;
typedef struct _tdstTypeThemeMem tdstTypeThemeMem;
typedef struct _tdstRandomElement tdstRandomElement;
typedef struct _tdstTypeRandomDisk       tdstTypeRandomDisk;
typedef struct _tdstTypeRandomMem       tdstTypeRandomMem;
 
 
/*typedef struct _tdstRefRes tdstRefRes;*/
/*typedef struct _tdstRefResList tdstRefResList;*/
typedef struct _tdstInfoTrackList tdstInfoTrackList;
 
/*banques binaires*/
typedef struct tdstSndBankDescriptorList_ tdstSndBankDescriptorList;
typedef struct _tdstSndBankDescriptor	tdstSndBankDescriptor;
typedef struct _tdstSndBankHeader tdstSndBankHeader;
typedef struct _tdstSndBankHead tdstSndBankHead;
 
 
 
#ifdef FILE_MODE_C_WIN95
	typedef HANDLE tdhSndFile;
#else
	#ifdef	DREAMCAST
		typedef FMN_tdstFile* tdhSndFile;
	#else
		#ifdef FILE_MODE_C_STANDARD
			typedef int tdhSndFile;
		#else
			typedef long tdhSndFile;
		#endif
	#endif
#endif
 
typedef long tdhSndFileAsync;
 
/*designation d'un evt*/
union _SND_tduRefEvt{
	tdxId				Id;
	SND_tdstBlockEvent	*pstPtr;
} ;
 
/*designation d'une ressource*/
union _tduRefRes {
        tdxId                                   Id;
        tdstBlockResourceMem    *pstPtr;
} ;
 
/*description d'un vecteur spatial*/
struct _SndVector {
	SndReal x ;
	SndReal y ;
	SndReal z ;
};
 
/*parametres d'un son 2D*/
struct _SampleParam{
	SndReal Freq;	/*frequence relative du sample à jouer */
	unsigned char ucVol;		/*volume du sample (0 inaudible à 127 maxi)*/
	unsigned char ucPan;		/*panoramique (0 gauche à 127 droite)*/
	unsigned char ucSpace;		/*parametre de spatialisation (codage DOLBY= 0 tout à l’avant, 127 tout à l’arriere)*/
	unsigned char ucReverb;	/*parametre de la reverberation (tunnels...)*/
} ;
 
 
 
extern SampleParam C_SAMPLEPARAM_MUET;
extern SampleParam C_SAMPLEPARAM_NEUTRE;
 
/*parametres d'un son 3D*/
struct _MicroLink{
    long    lId;
    SndBool bLinked;
};
 
/*-------------SoundParam transcendentale structure (varaible geometry to allow compatibility)*/
/*	&SoundParamTranscendentale+0:	->SoundParam (without astMicro)*/
/*	&SoundParamTranscendentale+sizeof(SoundParam)-sizeof(astMicro[NB_LINK])*/
/*									->n * astMicro (one for each micro)*/
/*	&SoundParamTranscendentale+SoundParam->iNbLinks*sizeof(astMicro)*/
/*									->ExtraSoundParam (if SoundParam->iFlags & C_SOUNDPARAM_ROLLOFF)*/
/* This system must be keeped for compatibility between previous DLL and new LIB (version 5.7.0)*/
 
#ifdef NB_MICRO_MAX
#define NB_LINK NB_MICRO_MAX	/*SoundParam will be a sized struct big enough to always describe NB_MICRO_MAX microphones*/
#else
#define NB_LINK 8  	/*SoundParam will be a UNsized struct; declaration use a size struct for compatibility; NEVER use a static instance of SoundParam*/
#endif
 
/*flags du champs SoundParam->iFlags*/
#define C_SOUNDPARAM_NO_POSITION 1	/*si TRUE, SoundParam->Pos et Vit ne sont pas à exploiter*/
#define C_SOUNDPARAM_NO_DOPPLER 2	/*si TRUE, SoundParam->Vit n'est pas à exploiter*/
#define C_SOUNDPARAM_COEF_VOL 4		/*si TRUE, SondParam->ucVol doit etre exploite*/
#define C_SOUNDPARAM_COEF_FREQ 8	/*obsolete*/
#define C_SOUNDPARAM_ROLLOFF 16		/*when TRUE, RollOff parameters are given*/
#define C_SOUNDPARAM_SWITCH 32		/*when TRUE, lSwitchIndice is given*/
 
struct _RollOffParam {
	SndReal		rDistSatur;	/*distance de saturation=pour d<rDistSatur, vol=MAXI*/
	SndReal		rDistBackGround;	/*distance du bruit de fond=pour d>rDistBackGround, VOL=cte*/
};
 
struct _SwitchParam {
	long	lObjectType;
	long	lObjectId;
};
 
struct _ExtraSoundParam {
	RollOffParam	stRollOff;	/*must always be the first extra data in SoundParam*/
	SwitchParam		stSwitch;	/*indice of active switch element (if any)*/
};
 
struct _SoundParam{
	SndReal     Freq;	    /*frequence relative du sample à jouer */
	unsigned char ucVol;	/*volume du sample (0 inaudible à 127 maxi)*/
	unsigned char ucPan;	/*panoramique (0 gauche à 127 droite)*/
	unsigned char ucSpace;	/*parametre de spatialisation (codage DOLBY= 0 tout à l’avant, 127 tout à l’arriere)*/
	unsigned char ucReverb;	/*parametre de la reverberation (tunnels...)*/
	SndVector   Pos;	    /*position de la source associee*/
	SndVector   Vit;	    /*vitesse de la source associee*/
	int         iFlags ;	/*flags justifiant les champs (cf plus loin)*/
	int         iNbLinks;    /*nombre d'element du champ suivant*/
	MicroLink   astMicro[NB_LINK];	/*liste statique des liens micros<->objet*/
	ExtraSoundParam	xExtra;	/*!!!!! this field should be never refered; it's only used to pre-size the struct SoundParam*/
} ;
 
 
#define C_ROLLOFFPARAM_INFINITE 0x7FFFFFFF
#define C_ROLLOFFPARAM_DEFAULT 0x7FFFFFFE
 
/*get the offst of effective ExtraSoundParam filed from SoundParam*; BE CAREFUL: effective ExtraSoundParam is NOT the extra field, but depend on iNbLinks*/
#define SND_M_GetExtraParamFromSoundParam(pstSoundParam)	(ExtraSoundParam*)((char*)pstSoundParam+sizeof(SoundParam)-sizeof(ExtraSoundParam)+(pstSoundParam->iNbLinks-NB_LINK)*sizeof(MicroLink))
 
#define SND_M_lGetSizeOfSoundParamFromNbLink(nb) (sizeof(SoundParam)+(nb-NB_LINK)*sizeof(MicroLink))
#define SND_M_lGetSizeOfSoundParam( _pObj) (SND_M_lGetSizeOfSoundParamFromNbLink(_pObj->iNbLinks))
 
 
/*parametres d'un micro*/
struct _MicroParam{
	SndVector	pos;
	SndVector	vit;
	SndVector	dirnor;
	SndVector	dirtan;
} ;
 
/*proptotype d'une fonction RetObjectSound..*/
typedef SndReal (*td_pfn_rRetSoundCoord)(long obj);
typedef unsigned char (*td_pfn_ucRetSoundMidi)(long obj);
typedef void (*td_pfn_vRetSoundExtraCoef)(long obj,SND_tduRefEvt evt,SndReal* pitch,SndReal* pan,SndReal* vol);
typedef long (*td_pfn_lRetSoundLong)(long obj);
typedef SND_tdxHandleToSoundInfo (*td_pfn_lRetSoundSwitch)(long obj,long type_switch);
typedef SndBool (*td_pfn_bRetSoundLink)(long obj,long micro);
typedef void (*td_pfn_vCopyString)(long obj,char* str,long size_str);
typedef SndBool (*td_pfn_bRetRollOffFactor)(long obj,RollOffParam* rolloff);/*distance absolue en m.*/
typedef void (*td_pfn_vRetSoundVector)(long obj,SndVector* vect);
 
/*proptotype for RetChannelSound..*/
typedef SndReal (*td_pfn_rRetChannelCoord)(long obj, long channel);
typedef SndBool (*td_pfn_bRetChannelActive)(long obj, long channel);
typedef SndBool (*td_pfn_bRetChannelAbsCoord)(long obj, long channel);

/*fonctions liees à un type d'objet*/
struct _tdstAllRetObjectSound{ 
	td_pfn_rRetSoundCoord		X,Y,Z,VX,VY,VZ;
	td_pfn_ucRetSoundMidi		REVERB;
	td_pfn_vRetSoundExtraCoef	ExtraCoef;
	td_pfn_lRetSoundSwitch		Switch;
    td_pfn_bRetSoundLink        MicroLink;

	//plalancette - added 31/05/99
	td_pfn_vRetSoundVector		VectorI;
	td_pfn_vRetSoundVector		VectorJ;
	td_pfn_vRetSoundVector		VectorK;

};


/* functions related to channels*/
struct _tdstAllRetChannelSound{ 
	td_pfn_rRetChannelCoord		X,Y,Z,VX,VY,VZ;
	td_pfn_bRetChannelActive	Active;
	SndBool	bAbsCoord;
};

 
/*fonctions liees aux parametres d'un micro*/
struct _tdstAllRetMicroSound{ 
	td_pfn_rRetSoundCoord		X,Y,Z,VX,VY,VZ;
	td_pfn_rRetSoundCoord		DNX,DNY,DNZ,DTX,DTY,DTZ;
	td_pfn_lRetSoundLong		Filtre;
};
 
/*constantes particulieres pour vo,pan,space et reverb*/
#define C_SOUNDPAN_MEDIAN 64
#define C_SOUNDPAN_LEFT 0
#define C_SOUNDPAN_RIGHT 127
 
#define C_SOUNDVOL_MINI 0
#define C_SOUNDVOL_MAXI 127
 
#define C_SOUNDSPACE_FRONT 0
#define C_SOUNDSPACE_BACK 127
 
#define NO_REVERB 0
 
/*obtenir les volumes des voies physiques à partir des params Midi*/
#define M_VolLeft(vol,pan)			(((int)(vol)*(pan))>>7)
#define M_VolRight(vol,pan)			(((int)(vol)*(127-(pan)))>>7)
#define M_VolFront(vol,space)		(((int)(vol)*(127-(space)))>>7)
#define M_VolBack(vol,space)		(((int)(vol)*(space))>>7)
/*obtenir les params midi à partir des volumes physiques*/
#define M_GetVol(voll,volr,volb)	((int)(voll)+(volr)+(volb))
#define M_GetPan(voll,volr,volb)	(((voll)==0) ? 0 : ((int)127*(voll)/((voll)+(volr))))
#define M_GetSpace(voll,volr,volb)	((((voll)+(volr))==0) ? 127 : ((int)127*(volb)/((voll)+(volr))))
 
#define C_CREATEMICRO_FAILED -1
#define C_PLAY_FAILED -1
#define C_GETVOLUME_FAILED 255
#define C_INIT_FAILED 2
#define C_INIT_OK 3
#define C_INIT_RUNNING 4
#define C_INIT_UNCOMPLETED 5
 
#define LOW_LATENCY 0x1000
extern SND_tduRefEvt SND_EVT_FANTOME;
/*
//liste des evts
struct _tdstSndPolyEvent {
//	M_LstParentDeclaration(SND_tdstBlockEvent);
	LST2_M_StaticParentDeclaration(SND_tdstBlockEvent*)
};
 
//liste de references à des events
struct _tdstSndPolyRefEvt{
//	M_LstParentDeclaration(SND_tduRefEvt);
	LST2_M_StaticParentDeclaration(SND_tduRefEvt*)
};
 
//liste de references à des ressources
struct _tdstSndPolyRefRes{
//	M_LstParentDeclaration(tduRefRes);
	LST2_M_StaticParentDeclaration(tduRefRes*)
};
*/
/*----------------------- buffers clients*/
typedef enum{
    SAMPLE_INVALID,
    SAMPLE_PCM,
    SAMPLE_MPEG,
	SAMPLE_AIFF,
	SAMPLE_ADPCM,
	SAMPLE_ADPCM_TO_CONVERT,
    SAMPLE_FOR_ALIGNEMENT=SND_ENUM_ALIGNEMENT
} tdeTypeZip;
 
typedef struct _tdstFormatPCM {
	unsigned long	ulNbSamples;	/*nb sample (0 si pas de choix)*/
	unsigned short	uwResolution;	/*8 ou 16 bits*/
	unsigned short	uwNbChannels;	/*1=mono 2=stereo*/
	unsigned long	ulFreq;			/*freq de restitution*/
} tdstFormatPCM;
typedef struct _tdstFormatPCM tdstFormatMPEG;	/*pas de format MPEG specifique pour l'instant*/
typedef struct _tdstFormatPCM tdstFormatADPCM;	/*pas de format ADPCM specifique pour l'instant*/
 
typedef struct _SND_tdstFormat {
	tdeTypeZip	eZip;
	union {
		tdstFormatPCM	stPCM;
		tdstFormatMPEG	stMPEG;
		tdstFormatADPCM	stADPCM;
	} uFormat;
} SND_tdstFormat;
 
typedef struct _SND_tdstStackBuffer {
	unsigned long	ulNbSamples;
	void			*ptrData;
} SND_tdstStackBuffer;
 
typedef void (SND_CALL *td_pfn_vBufferClientPoped)(long user_id,long poped_id);
typedef void (SND_CALL *td_pfn_vRefreshBufferClient)(long user_id,unsigned long first,unsigned long nb,void* ptr_first_sample);
/*id_buffer=id/voie du biffer client concerne*/
/*first=id du 1° sample à rafraichir (pas en octets)*/
/*nb=nb de samples à calculer */
/*ptr_first_sample=adresse cible*/
 
/*parametre pour le type de CallbackClient*/
typedef enum _SND_tdstTypeCallback {
		BUFFER_ASYNCHRONE,	/*buffer bouclant rafraichis asynchroniquement (ancien bufferclient)*/
		BUFFER_SYNCHRONE,			/*rafraichissement d'un tampon en "juste à temps"*/
		BUFFER_STACK,				/*empillage par le client de buffers à enchainer*/
		ALIGN_FOR_BUFFER_CLIENT=0x12345678
} SND_tduTypeCallback;
 
typedef struct _SND_tdstCallback {
	SND_tduTypeCallback	eType;/*type de rafraichissement*/
	union {/*pointeur sur la fonction client pour callback*/
		td_pfn_vRefreshBufferClient CallbackASynchrone;	/*fonction de callback asynchrone*/
		td_pfn_vRefreshBufferClient CallbackSynchrone;	/*fonction de callback en "juste à temps"*/
		td_pfn_vBufferClientPoped	CallbackStack;		/*fonction indiquant qu'un buffer pushed à ete joue (peut etre libere)*/
	} uCallback;
	union {/*indication retournee au client pour la gestion de son bufferclient*/
		SndReal	rCallbackPeriod;	/*periode indicative de la callback (pas de calcul plus long SVP)*/
		long	lNbSampleToPush;	/*nb de sample devant etre pushes en permanence*/
	} uInfo;
} SND_tdstCallback;
 
 
/*pour SNDVIRT*/
/*!!!ATTENTION: ne jamais passer une macro LST2_M_ en parametre à une autre macro LST2_M_*/
typedef struct _virtual_module *SND_tdhVirtualModule;
 
/*Callback pour obtenir le nom d'une ressource*/
typedef const char * (*tdpfnResNameCallback)(unsigned long);
 
 
#ifdef M_SET_ALIGNMENT
#pragma pack(pop)
#endif
 
 
#if (defined(__cplusplus)&& !defined(CPA_ForceCplusplus))
}
#endif /* __cplusplus*/
 
#endif /*_SNDTYPE_H_*/
 
