SOUNDINT.H 9.1 KB

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