#ifndef DEVICES_AHI_H
#define DEVICES_AHI_H

/*
**	$VER: ahi.h 2.2 (12.7.96)
**
**	ahi.device definitions
**
**	(C) Copyright 1994-1996 Martin Blom
**	All Rights Reserved.
**
** (TAB SIZE: 8)
*/

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

#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif

#ifndef EXEC_LIBRARIES_H
#include <exec/io.h>
#endif

#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem.h>
#endif

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

 /* Device units */

#define AHI_FIRST_UNIT		0
#define AHI_NO_UNIT		255

 /* AHIRequest */

struct AHIRequest
{
	struct	IOStdReq	 ahir_Std;	/* Standard IO request */
	UWORD			 ahir_Version;	/* Needed version */
};

/* FUNCTION INTERFACE DEFINITIONS FOLLOWS ************************************/

typedef LONG	Fixed;				/* A fixed-point value, 16 bits
						   to the left of the point and
						   16 bits to the right */
typedef Fixed	sposition;

/*** STRUCTURES */

 /* AHIAudioCtrl */
struct AHIAudioCtrl
{
	APTR	ahiac_UserData;
	/* Lots of private data follows! */
};

 /* AHISoundMessage */
struct AHISoundMessage
{
 	UWORD	ahism_Channel;
};

 /* AHIRecordMessage */
struct AHIRecordMessage
{
	ULONG	ahirm_Type;			/* Format of buffer (object) */
	APTR	ahirm_Buffer;			/* Pointer to the sample array */
	ULONG	ahirm_Length;			/* Number of sample frames in buffer */
};

 /* AHISampleInfo */
struct AHISampleInfo
{
	ULONG	ahisi_Type;			/* Format of samples */
	APTR	ahisi_Address;			/* Address to array of samples */
	ULONG	ahisi_Length;			/* Number of samples in array */
};


/*
* An array of AHIMultiLoop structures are used to describe how to play multi-
* looped sounds. ahiml_Command can be a number from 1 to 65535 to play the
* segment that number of times before proceeding to the next structure in the
* array, or 0 to play the segment forever (terminating the array). If
* the last ahiml_Command in the array is ~0 the sound will be stopped
* (ahiml_Offset and ahiml_Length should be set to 0 in this case).
*/

 /* AHIMultiLoop */
struct AHIMultiLoop
{
	ULONG	ahiml_Command;
	ULONG	ahiml_Offset;			/* Offset in samples */
	ULONG	ahiml_Length;			/* Length in samples */
};

 /* AHILoopInfo (size is variable) */
struct AHILoopInfo
{
	UWORD		    ahili_Sound;	/* The source sound */
	UWORD		    ahili_Pad;
	struct AHIMultiLoop ahili_LoopArray[0];
};

 /* AHIAudioModeRequester */
struct AHIAudioModeRequester
{
	ULONG	ahiam_AudioID;			/* Selected audio mode */
	ULONG	ahiam_MixFreq;			/* Selected mixing/sampling frequency */
	
	WORD	ahiam_LeftEdge;			/* Coordinates of requester on exit */
	WORD	ahiam_TopEdge;
	WORD	ahiam_Width;
	WORD	ahiam_Height;

	BOOL	ahiam_InfoOpened;		/* Info window opened on exit? */
	WORD	ahiam_InfoLeftEdge;		/* Last coordinates of Info window */
	WORD	ahiam_InfoTopEdge;
	WORD	ahiam_InfoWidth;
	WORD	ahiam_InfoHeight;

	APTR	ahiam_UserData;			/* You can store your own data here */
};

 /* AHIEffMasterVolume */
struct AHIEffMasterVolume
{
	ULONG	ahie_Effect;			/* Set to AHIET_MASTERVOLUME */
	Fixed	ahiemv_Volume;			/* See autodocs for range! */
};

 /* AHIEffOutputBuffer */
struct AHIEffOutputBuffer
{
	ULONG		 ahie_Effect;		/* Set to AHIET_OUTPUTBUFFER */
	struct Hook	*ahieob_Func;
 /* These fields are filled by AHI */
	ULONG		 ahieob_Type;		/* Format of buffer */
	APTR		 ahieob_Buffer;		/* Pointer to the sample array */
	ULONG		 ahieob_Length;		/* Number of sample frames in buffer */
};

/*** TAGS */

#define AHI_TagBase		(TAG_USER)
#define AHI_TagBaseR		(AHI_TagBase|0x8000)

 /* AHI_AllocAudioA tags */
#define AHIA_AudioID		(AHI_TagBase+1)		/* Desired audio mode */
#define AHIA_MixFreq		(AHI_TagBase+2)		/* Suggested mixing frequency */
#define AHIA_Channels		(AHI_TagBase+3)		/* Suggested number of channels */
#define AHIA_Sounds		(AHI_TagBase+4)		/* Number of sounds to use */
#define AHIA_SoundFunc		(AHI_TagBase+5)		/* End-of-Sound Hook */
#define AHIA_PlayerFunc		(AHI_TagBase+6)		/* Player Hook */
#define AHIA_PlayerFreq		(AHI_TagBase+7)		/* Frequency for player Hook */
#define AHIA_MinPlayerFreq	(AHI_TagBase+8)		/* Minimum Frequency for player Hook */
#define AHIA_MaxPlayerFreq	(AHI_TagBase+9)		/* Maximum Frequency for player Hook */
#define AHIA_RecordFunc		(AHI_TagBase+10)	/* Sample recording Hook */
#define AHIA_UserData		(AHI_TagBase+11)	/* What to put in ahiac_UserData */

 /* AHI_ControlAudioA tags */
#define AHIC_Play		(AHI_TagBase+80)	/* Boolean */
#define AHIC_Record		(AHI_TagBase+81)	/* Boolean */
#define AHIC_MonitorVolume	(AHI_TagBase+82)
#define AHIC_MonitorVolume_Query (AHI_TagBase+83)	/* ti_Data is pointer to Fixed (LONG) */
#define AHIC_MixFreq_Query	(AHI_TagBase+84)	/* ti_Data is pointer to ULONG */
/* --- New for V2, they will be ignored by V1 --- */
#define AHIC_InputGain		(AHI_TagBase+85)
#define AHIC_InputGain_Query	(AHI_TagBase+86)	/* ti_Data is pointer to Fixed (LONG) */
#define AHIC_OutputVolume	(AHI_TagBase+87)
#define AHIC_OutputVolume_Query	(AHI_TagBase+88)	/* ti_Data is pointer to Fixed (LONG) */
#define AHIC_Input		(AHI_TagBase+89)
#define AHIC_Input_Query	(AHI_TagBase+90)	/* ti_Data is pointer to ULONG */
#define AHIC_Output		(AHI_TagBase+91)
#define AHIC_Output_Query	(AHI_TagBase+92)	/* ti_Data is pointer to ULONG */

 /* AHI_GetAudioAttrsA tags */
#define AHIDB_AudioID		(AHI_TagBase+100)	/* Private! */
#define AHIDB_Driver		(AHI_TagBaseR+101)	/* Pointer to name of driver */
#define AHIDB_Flags		(AHI_TagBase+102)	/* Private! */
#define AHIDB_Volume		(AHI_TagBase+103)	/* Boolean */
#define AHIDB_Panning		(AHI_TagBase+104)	/* Boolean */
#define AHIDB_Stereo		(AHI_TagBase+105)	/* Boolean */
#define AHIDB_HiFi		(AHI_TagBase+106)	/* Boolean */
#define AHIDB_PingPong		(AHI_TagBase+107)	/* Boolean */
#define AHIDB_MultTable		(AHI_TagBase+108)	/* Private! */
#define AHIDB_Name		(AHI_TagBaseR+109)	/* Pointer to name of this mode */
#define AHIDB_Bits		(AHI_TagBase+110)	/* Output bits */
#define AHIDB_MaxChannels	(AHI_TagBase+111)	/* Max supported channels */
#define AHIDB_MinMixFreq	(AHI_TagBase+112)	/* Min mixing freq. supported */
#define AHIDB_MaxMixFreq	(AHI_TagBase+113)	/* Max mixing freq. supported */
#define AHIDB_Record		(AHI_TagBase+114)	/* Boolean */
#define AHIDB_Frequencies	(AHI_TagBase+115)
#define AHIDB_FrequencyArg	(AHI_TagBase+116)	/* ti_Data is frequency index */
#define AHIDB_Frequency		(AHI_TagBase+117)
#define AHIDB_Author		(AHI_TagBase+118)	/* Pointer to driver author name */
#define AHIDB_Copyright		(AHI_TagBase+119)	/* Pointer to driver copyright notice */
#define AHIDB_Version		(AHI_TagBase+120)	/* Pointer to driver version string */
#define AHIDB_Annotation	(AHI_TagBase+121)	/* Pointer to driver annotation text */
#define AHIDB_BufferLen		(AHI_TagBase+122)	/* Specifies the string buffer size */
#define AHIDB_IndexArg		(AHI_TagBase+123)	/* ti_Data is frequency! */
#define AHIDB_Index		(AHI_TagBase+124)
#define AHIDB_Realtime		(AHI_TagBase+125)	/* Boolean */
#define AHIDB_MaxPlaySamples	(AHI_TagBase+126)	/* It's sample *frames* */
#define AHIDB_MaxRecordSamples	(AHI_TagBase+127)	/* It's sample *frames* */
#define AHIDB_FullDuplex	(AHI_TagBase+129)	/* Boolean */
/* --- New for V2, they will be ignored by V1 --- */
#define AHIDB_MinMonitorVolume	(AHI_TagBase+130)
#define AHIDB_MaxMonitorVolume	(AHI_TagBase+131)
#define AHIDB_MinInputGain	(AHI_TagBase+132)
#define AHIDB_MaxInputGain	(AHI_TagBase+133)
#define AHIDB_MinOutputVolume	(AHI_TagBase+134)
#define AHIDB_MaxOutputVolume	(AHI_TagBase+135)
#define AHIDB_Inputs		(AHI_TagBase+136)
#define AHIDB_InputArg		(AHI_TagBase+137)	/* ti_Data is input index */
#define AHIDB_Input		(AHI_TagBase+138)
#define AHIDB_Outputs		(AHI_TagBase+139)
#define AHIDB_OutputArg		(AHI_TagBase+140)	/* ti_Data is input index */
#define AHIDB_Output		(AHI_TagBase+141)

 /* AHI_AudioRequestA tags */
	/* Window control */
#define AHIR_Window		(AHI_TagBase+200)	/* Parent window */
#define AHIR_Screen		(AHI_TagBase+201)	/* Screen to open on if no window */
#define AHIR_PubScreenName	(AHI_TagBase+202)	/* Name of public screen */
#define AHIR_PrivateIDCMP	(AHI_TagBase+203)	/* Allocate private IDCMP? */
#define AHIR_IntuiMsgFunc	(AHI_TagBase+204)	/* Function to handle IntuiMessages */
#define AHIR_SleepWindow	(AHI_TagBase+205)	/* Block input in AHIR_Window? */
#define AHIR_UserData		(AHI_TagBase+206)	/* What to put in ahiam_UserData */
	/* Text display */
#define AHIR_TextAttr		(AHI_TagBase+220)	/* Text font to use for gadget text */
#define AHIR_Locale		(AHI_TagBase+221)	/* Locale to use for text */
#define AHIR_TitleText		(AHI_TagBase+222)	/* Title of requester */
#define AHIR_PositiveText	(AHI_TagBase+223)	/* Positive gadget text */
#define AHIR_NegativeText	(AHI_TagBase+224)	/* Negative gadget text */
	/* Initial settings */
#define AHIR_InitialLeftEdge	(AHI_TagBase+240)	/* Initial requester coordinates */
#define AHIR_InitialTopEdge	(AHI_TagBase+241)
#define AHIR_InitialWidth	(AHI_TagBase+242)	/* Initial requester dimensions */
#define AHIR_InitialHeight	(AHI_TagBase+243)
#define AHIR_InitialAudioID	(AHI_TagBase+244)	/* Initial audio mode id */
#define AHIR_InitialMixFreq	(AHI_TagBase+245)	/* Initial mixing/sampling frequency */
#define AHIR_InitialInfoOpened	(AHI_TagBase+246)	/* Info window initially opened? */
#define AHIR_InitialInfoLeftEdge (AHI_TagBase+247)	/* Initial Info window coords. */
#define AHIR_InitialInfoTopEdge (AHI_TagBase+248)
#define AHIR_InitialInfoWidth	(AHI_TagBase+249)
#define AHIR_InitialInfoHeight	(AHI_TagBase+250)
	/* Options */
#define AHIR_DoMixFreq		(AHI_TagBase+260)	/* Allow selection of mixing frequency? */
	/* Filtering */
#define AHIR_FilterTags		(AHI_TagBase+270)	/* Pointer to filter taglist */
#define AHIR_FilterFunc		(AHI_TagBase+271)	/* Function to filter mode id's */


/*** DEFS */

#define AHINAME			"ahi.device"
#define AHI_INVALID_ID		(~0)			/* Invalid Audio ID */
#define AHI_DEFAULT_ID		0x00000000		/* Only for AHI_AllocAudioA()! */
#define AHI_LOOPBACK_ID		0x00000001		/* Special sample render Audio ID */
#define AHI_DEFAULT_FREQ	0			/* Only for AHI_AllocAudioA()! */
#define AHI_MIXFREQ		(~0)			/* Special frequency for AHI_SetFreq() */
#define AHI_NOSOUND		0xffff			/* Turns a channel off */

 /* Set#? Flags */
#define AHISF_IMM		(1<<0)
#define AHISB_IMM		0

 /* Effect Types */
#define AHIET_CANCEL		(1<<31)			/* OR with effect to disable */
#define AHIET_MASTERVOLUME	1
#define AHIET_OUTPUTBUFFER	2

 /* Sound Types */
#define AHIST_NOTYPE		(~0)			/* Private */
#define AHIST_SAMPLE		0			/* 8 or 16 bit sample */
#define AHIST_DYNAMICSAMPLE	1			/* Dynamic sample */
#define AHIST_BW		2			/* Private */
#define AHIST_INPUT		257			/* The input from your sampler */
#define AHIST_LOOP		(1<<31)			/* Multi-loop sound */

 /* Sample types */
/* Note that only AHIST_M8S, AHIST_M8U and AHIST_M16S */
/* are supported by AHI_LoadSound(). */
#define AHIST_M8S		0			/* Mono, 8 bit signed (BYTE) */
#define AHIST_M16S		1			/* Mono, 16 bit signed (WORD) */
#define AHIST_S16S		3			/* Stereo, 16 bit signed (2ŚWORD) */
#define AHIST_M8U		4			/* Mono, 8 bit unsigned (UBYTE) */
#define AHIST_M32S		8			/* Mono, 32 bit signed (LONG) */
#define AHIST_S32S		10			/* Stereo, 32 bit signed (2ŚLONG) */

 /* Error codes */
#define AHIE_OK			0			/* No error */
#define AHIE_NOMEM		1			/* Out of memory */
#define AHIE_BADSOUNDTYPE	2			/* Unknown sound type */
#define AHIE_BADSAMPLETYPE	3			/* Unknown/unsupported sample type */
#define AHIE_ABORTED		4			/* User-triggered abortion */

#endif /* DEVICES_AHI_H */
