SOUNDINT.H 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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:1;
  74. /*
  75. ** This flags whether the sample is loading or has been started.
  76. */
  77. unsigned Loading:1;
  78. /*
  79. ** This semaphore ensures that simultaneous update of this structure won't
  80. ** occur. This is necessary since both interrupt and regular code can modify
  81. ** this structure.
  82. */
  83. unsigned DontTouch:1;
  84. /*
  85. ** If this sample is really to be considered a score rather than
  86. ** a sound effect, then special rules apply. These largely fall into
  87. ** the area of volume control.
  88. */
  89. unsigned IsScore:1;
  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 in low ram.
  103. */
  104. VOID *Buffer[2];
  105. /*
  106. ** The number of bytes in the buffer that has been filled but is not
  107. ** yet playing. This value is normally the size of the buffer,
  108. ** except for the case of the last bit of the sample.
  109. */
  110. LONG DataLength;
  111. /*
  112. ** This is the buffer index for the low buffer that
  113. ** has been filled with data but not yet being
  114. ** played.
  115. */
  116. WORD Index;
  117. /*
  118. ** Pointer to the sound data that has not yet been copied
  119. ** to the playback buffers.
  120. */
  121. VOID *Source;
  122. /*
  123. ** This is the number of bytes remaining in the source data as
  124. ** pointed to by the "Source" element.
  125. */
  126. LONG Remainder;
  127. /*
  128. ** Samples maintain a priority which is used to determine
  129. ** which sounds live or die when the maximum number of
  130. ** sounds are being played.
  131. */
  132. WORD Priority;
  133. /*
  134. ** This is the handle as returned by sosDIGIStartSample function.
  135. */
  136. WORD Handle;
  137. /*
  138. ** This is the current volume of the sample as it is being played.
  139. */
  140. WORD Volume;
  141. WORD Reducer; // Amount to reduce volume per tick.
  142. /*
  143. ** This flags whether the sample is in stereo.
  144. */
  145. WORD Stereo;
  146. /*
  147. ** This is the compression that the sound data is using.
  148. */
  149. SCompressType Compression;
  150. WORD TrailerLen; // Number of trailer bytes in buffer.
  151. BYTE Trailer[SONARC_MARGIN]; // Maximum number of 'order' samples needed.
  152. DWORD Pitch;
  153. WORD Flags;
  154. /*
  155. ** This flag indicates whether this sample needs servicing.
  156. ** Servicing entails filling one of the empty low buffers.
  157. */
  158. WORD Service;
  159. /*
  160. ** This flag is TRUE when the sample has stopped playing,
  161. ** BUT there is more data available. The sample must be
  162. ** restarted upon filling the low buffer.
  163. */
  164. BOOL Restart;
  165. /*
  166. ** Streaming control handlers.
  167. */
  168. BOOL (*Callback)(WORD id, WORD *odd, VOID **buffer, LONG *size);
  169. VOID *QueueBuffer; // Pointer to continued sample data.
  170. LONG QueueSize; // Size of queue buffer attached.
  171. WORD Odd; // Block number tracker (0..StreamBufferCount-1).
  172. int FilePending; // Number of buffers already filled ahead.
  173. long FilePendingSize; // Number of bytes in last filled buffer.
  174. /*
  175. ** The file variables are used when streaming directly off of the
  176. ** hard drive.
  177. */
  178. WORD FileHandle; // Streaming file handle (ERROR = not in use).
  179. VOID *FileBuffer; // Temporary streaming buffer (allowed to be freed).
  180. /*
  181. ** The following structure is used if the sample if compressed using
  182. ** the sos 16 bit compression Codec.
  183. */
  184. _SOS_COMPRESS_INFO sosinfo;
  185. } SampleTrackerType;
  186. typedef struct LockedData {
  187. unsigned int DigiHandle; // = -1;
  188. BOOL ServiceSomething; // = FALSE;
  189. long MagicNumber; // = 0xDEAF;
  190. VOID *UncompBuffer; // = NULL;
  191. long StreamBufferSize; // = (2*SFX_MINI_STAGE_BUFFER_SIZE)+128;
  192. short StreamBufferCount; // = 32;
  193. SampleTrackerType SampleTracker[MAX_SFX];
  194. unsigned int SoundVolume;
  195. unsigned int ScoreVolume;
  196. BOOL _int;
  197. int MaxSamples;
  198. int Rate;
  199. } LockedDataType;
  200. extern LockedDataType LockedData;
  201. #pragma pack(4);
  202. void Init_Locked_Data(void);
  203. void Unlock_Locked_Data(void);
  204. long Simple_Copy(void ** source, long * ssize, void ** alternate, long * altsize, void **dest, long size);
  205. long Sample_Copy(SampleTrackerType *st, void ** source, long * ssize, void ** alternate, long * altsize, void * dest, long size, SCompressType scomp, void * trailer, WORD *trailersize);
  206. VOID far cdecl maintenance_callback(VOID);
  207. VOID cdecl far DigiCallback(unsigned int driverhandle, unsigned int callsource, unsigned int sampleid);
  208. void far HMI_TimerCallback(void);
  209. void *Audio_Add_Long_To_Pointer(void const *ptr, long size);
  210. void DPMI_Unlock(VOID const *ptr, long const size);
  211. extern "C" {
  212. void Audio_Mem_Set(void const *ptr, unsigned char value, long size);
  213. void Mem_Copy(void const *source, void *dest, unsigned long bytes_to_copy);
  214. long Decompress_Frame(void * source, void * dest, long size);
  215. int Decompress_Frame_Lock(void);
  216. int Decompress_Frame_Unlock(void);
  217. int sosCODEC_Lock(void);
  218. int sosCODEC_Unlock(void);
  219. void __GETDS(void);
  220. }