SOUNDINT.H 9.2 KB

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