CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

SOUNDINT.H (9450B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 /***************************************************************************
     17  **      C O N F I D E N T I A L --- W E S T W O O D   S T U D I O S      **
     18  ***************************************************************************
     19  *                                                                         *
     20  *                 Project Name : Westwood 32 bit Library                  *
     21  *                                                                         *
     22  *                    File Name : SOUNDINT.H                               *
     23  *                                                                         *
     24  *                   Programmer : Phil W. Gorrow                           *
     25  *                                                                         *
     26  *                   Start Date : June 23, 1995                            *
     27  *                                                                         *
     28  *                  Last Update : June 23, 1995   [PWG]                    *
     29  *                                                                         *
     30  * This file is the include file for the Westwood Sound Sytem defines and  *
     31  * routines that are handled in an interrupt.
     32  *                                                                         *
     33  *-------------------------------------------------------------------------*
     34  * Functions:                                                              *
     35  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     36 
     37 #include "sound.h"
     38 
     39 /*
     40 ** Defines for true and false.  These are included because we do not allow
     41 ** the sound int to include any of the westwood standard headers.  If we
     42 ** did, there might be too much temptation to call another library function.
     43 ** this would be bad, because then that function would not be locked.
     44 */
     45 #define	FALSE		0
     46 #define	TRUE		1
     47 
     48 /*
     49 ** Define the different type of sound compression avaliable to the westwood
     50 ** library.
     51 */
     52 typedef enum {
     53 	SCOMP_NONE=0,			// No compression -- raw data.
     54 	SCOMP_WESTWOOD=1,		// Special sliding window delta compression.
     55 	SCOMP_SONARC=33,		// Sonarc frame compression.
     56 	SCOMP_SOS=99			// SOS frame compression.
     57 } SCompressType;
     58 
     59 /*
     60 **	This is the safety overrun margin for the sonarc compressed
     61 ** data frames.  This value should be equal the maximum 'order' times
     62 **	the maximum number of bytes per sample.  It should be evenly divisible
     63 **	by 16 to aid paragraph alignment.
     64 */
     65 #define	SONARC_MARGIN				32
     66 
     67 
     68 /*
     69 ** Define the sample control structure which helps us to handle feeding
     70 ** data to the sound interrupt.
     71 */
     72 #pragma pack(1);
     73 typedef struct {
     74 	/*
     75 	**	This flags whether this sample structure is active or not.
     76 	*/
     77 	unsigned Active;
     78 	//unsigned Active:1;
     79 
     80 	/*
     81 	**	This flags whether the sample is loading or has been started.
     82 	*/
     83 	//unsigned Loading:1;
     84 	unsigned Loading;
     85 
     86 	/*
     87 	**	This semaphore ensures that simultaneous update of this structure won't
     88 	**	occur.  This is necessary since both interrupt and regular code can modify
     89 	**	this structure.
     90 	*/
     91 	//unsigned DontTouch:1;
     92 	unsigned DontTouch;
     93 
     94 	/*
     95 	**	If this sample is really to be considered a score rather than
     96 	**	a sound effect, then special rules apply.  These largely fall into
     97 	**	the area of volume control.
     98 	*/
     99 	//unsigned IsScore:1;
    100 	unsigned IsScore;
    101 
    102 	/*
    103 	**	This is the original sample pointer. It is used to control the sample based on
    104 	**	pointer rather than handle. The handle method is necessary when more than one
    105 	**	sample could be playing simultaneously. The pointer method is necessary when
    106 	**	the dealing with a sample that may have stopped behind the programmer's back and
    107 	**	this occurance is not otherwise determinable.  It is also used in
    108 	** conjunction with original size to unlock a sample which has been DPMI
    109 	** locked.
    110 	*/
    111 	void const *Original;
    112 	long OriginalSize;
    113 
    114 	/*
    115 	**	These are pointers to the double buffers.
    116 	*/
    117 	LPDIRECTSOUNDBUFFER PlayBuffer;
    118 
    119 	/*
    120 	** Variable to keep track of the playback rate of this buffer
    121 	*/
    122 	int	PlaybackRate;
    123 
    124 	/*
    125 	** Variable to keep track of the sample type ( 8 or 16 bit ) of this buffer
    126 	*/
    127 	int	BitSize;
    128 
    129 	/*
    130 	** Variable to keep track of the stereo ability of this buffer
    131 	*/
    132 	int	Stereo;
    133 
    134 	/*
    135 	**	The number of bytes in the buffer that has been filled but is not
    136 	**	yet playing.  This value is normally the size of the buffer,
    137 	**	except for the case of the last bit of the sample.
    138 	*/
    139 	LONG DataLength;
    140 
    141 	/*
    142 	**	This is the buffer index for the low buffer that
    143 	**	has been filled with data but not yet being
    144 	**	played.
    145 	*/
    146 //	short int Index;
    147 
    148 	/*
    149 	**	Pointer into the play buffer for writing the next
    150 	**  chunk of sample to
    151 	**
    152 	*/
    153 	VOID *DestPtr;
    154 
    155 	/*
    156 	**	This flag indicates that there is more source data
    157 	**  to copy to the play buffer
    158 	**
    159 	*/
    160 	BOOL MoreSource;
    161 
    162 	/*
    163 	**	This flag indicates that the entire sample fitted inside the
    164 	** direct sound secondary buffer
    165 	**
    166 	*/
    167 	BOOL OneShot;
    168 
    169 	/*
    170 	**	Pointer to the sound data that has not yet been copied
    171 	**	to the playback buffers.
    172 	*/
    173 	VOID *Source;
    174 
    175 	/*
    176 	**	This is the number of bytes remaining in the source data as
    177 	**	pointed to by the "Source" element.
    178 	*/
    179 	LONG Remainder;
    180 
    181 	/*
    182 	**	Object to use with Enter/LeaveCriticalSection
    183 	**
    184 	*/
    185 	CRITICAL_SECTION AudioCriticalSection;
    186 
    187 	/*
    188 	**	Samples maintain a priority which is used to determine
    189 	**	which sounds live or die when the maximum number of
    190 	**	sounds are being played.
    191 	*/
    192 	int Priority;
    193 
    194 	/*
    195 	**	This is the handle as returned by sosDIGIStartSample function.
    196 	*/
    197 	short int Handle;
    198 
    199 	/*
    200 	**	This is the current volume of the sample as it is being played.
    201 	*/
    202 	int Volume;
    203 	int Reducer;		// Amount to reduce volume per tick.
    204 
    205 	/*
    206 	**	This is the compression that the sound data is using.
    207 	*/
    208 	SCompressType Compression;
    209 	short int TrailerLen;						// Number of trailer bytes in buffer.
    210 	BYTE Trailer[SONARC_MARGIN];		// Maximum number of 'order' samples needed.
    211 
    212 
    213 	DWORD Pitch;
    214 	WORD Flags;
    215 
    216 	/*
    217 	**	This flag indicates whether this sample needs servicing.
    218 	**	Servicing entails filling one of the empty low buffers.
    219 	*/
    220 	short int Service;
    221 
    222 	/*
    223 	**	This flag is TRUE when the sample has stopped playing,
    224 	**	BUT there is more data available.  The sample must be
    225 	**	restarted upon filling the low buffer.
    226 	*/
    227 	BOOL Restart;
    228 
    229 	/*
    230 	**	Streaming control handlers.
    231 	*/
    232 	BOOL (*Callback)(short int id, short int *odd, VOID **buffer, LONG *size);
    233 	VOID	*QueueBuffer;	// Pointer to continued sample data.
    234 	LONG	QueueSize;		// Size of queue buffer attached.
    235 	short int	Odd;				// Block number tracker (0..StreamBufferCount-1).
    236 	int	FilePending;	// Number of buffers already filled ahead.
    237 	long	FilePendingSize;	// Number of bytes in last filled buffer.
    238 
    239 	/*
    240 	**	The file variables are used when streaming directly off of the
    241 	**	hard drive.
    242 	*/
    243 	int	FileHandle;		// Streaming file handle (ERROR = not in use).
    244 	VOID	*FileBuffer;	// Temporary streaming buffer (allowed to be freed).
    245 	/*
    246 	** The following structure is used if the sample if compressed using
    247 	** the sos 16 bit compression Codec.
    248 	*/
    249 
    250 	_SOS_COMPRESS_INFO sosinfo;
    251 
    252 
    253 } SampleTrackerType;
    254 
    255 
    256 typedef struct LockedData {
    257 	unsigned int 		DigiHandle; 			// = -1;
    258 	BOOL 					ServiceSomething;		// = FALSE;
    259 	long 					MagicNumber; 			// = 0xDEAF;
    260 	VOID 					*UncompBuffer;			// = NULL;
    261 	long 					StreamBufferSize; 	// = (2*SECONDARY_BUFFER_SIZE)+128;
    262 	short 				StreamBufferCount; 	// = 32;
    263 	SampleTrackerType SampleTracker[MAX_SFX];
    264 	unsigned int		SoundVolume;
    265 	unsigned int		ScoreVolume;
    266 	BOOL					_int;
    267 } LockedDataType;
    268 
    269 extern LockedDataType LockedData;
    270 #pragma pack(4);
    271 
    272 void Init_Locked_Data(void);
    273 long Simple_Copy(void ** source, long * ssize, void ** alternate, long * altsize, void **dest, long size);
    274 long Sample_Copy(SampleTrackerType *st, void ** source, long * ssize, void ** alternate, long * altsize, void * dest, long size, SCompressType scomp, void * trailer, short int *trailersize);
    275 VOID far __cdecl maintenance_callback(VOID);
    276 VOID __cdecl far DigiCallback(unsigned int driverhandle, unsigned int callsource, unsigned int sampleid);
    277 void far HMI_TimerCallback(void);
    278 void *Audio_Add_Long_To_Pointer(void const *ptr, long size);
    279 void	DPMI_Unlock(VOID const *ptr, long const size);
    280 extern "C" {
    281 	void __cdecl Audio_Mem_Set(void const *ptr, unsigned char value, long size);
    282 //	void	Mem_Copy(void *source, void *dest, unsigned long bytes_to_copy);
    283 	long  __cdecl Decompress_Frame(void * source, void * dest, long size);
    284 	int	__cdecl Decompress_Frame_Lock(void);
    285 	int	__cdecl Decompress_Frame_Unlock(void);
    286 	int	__cdecl sosCODEC_Lock(void);
    287 	int	__cdecl sosCODEC_Unlock(void);
    288 	void	__GETDS(void);
    289 }