_MULTIVC.H 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. Copyright (C) 1994-1995 Apogee Software, Ltd.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. /**********************************************************************
  16. file: _MULTIVC.H
  17. author: James R. Dose
  18. date: December 20, 1993
  19. Private header for MULTIVOC.C
  20. (c) Copyright 1993 James R. Dose. All Rights Reserved.
  21. **********************************************************************/
  22. #ifndef ___MULTIVC_H
  23. #define ___MULTIVC_H
  24. #define TRUE ( 1 == 1 )
  25. #define FALSE ( !TRUE )
  26. #define VOC_8BIT 0x0
  27. #define VOC_CT4_ADPCM 0x1
  28. #define VOC_CT3_ADPCM 0x2
  29. #define VOC_CT2_ADPCM 0x3
  30. #define VOC_16BIT 0x4
  31. #define VOC_ALAW 0x6
  32. #define VOC_MULAW 0x7
  33. #define VOC_CREATIVE_ADPCM 0x200
  34. #define T_SIXTEENBIT_STEREO 0
  35. #define T_8BITS 1
  36. #define T_MONO 2
  37. #define T_16BITSOURCE 4
  38. #define T_LEFTQUIET 8
  39. #define T_RIGHTQUIET 16
  40. #define T_DEFAULT T_SIXTEENBIT_STEREO
  41. #define MV_MaxPanPosition 31
  42. #define MV_NumPanPositions ( MV_MaxPanPosition + 1 )
  43. #define MV_MaxTotalVolume 255
  44. //#define MV_MaxVolume 63
  45. #define MV_NumVoices 8
  46. #define MIX_VOLUME( volume ) \
  47. ( ( max( 0, min( ( volume ), 255 ) ) * ( MV_MaxVolume + 1 ) ) >> 8 )
  48. // ( ( max( 0, min( ( volume ), 255 ) ) ) >> 2 )
  49. //#define SILENCE_16BIT 0x80008000
  50. #define SILENCE_16BIT 0
  51. #define SILENCE_8BIT 0x80808080
  52. //#define SILENCE_16BIT_PAS 0
  53. #define MixBufferSize 256
  54. #define NumberOfBuffers 16
  55. #define TotalBufferSize ( MixBufferSize * NumberOfBuffers )
  56. #define PI 3.1415926536
  57. typedef enum
  58. {
  59. Raw,
  60. VOC,
  61. DemandFeed,
  62. WAV
  63. } wavedata;
  64. typedef enum
  65. {
  66. NoMoreData,
  67. KeepPlaying
  68. } playbackstatus;
  69. typedef struct VoiceNode
  70. {
  71. struct VoiceNode *next;
  72. struct VoiceNode *prev;
  73. wavedata wavetype;
  74. char bits;
  75. playbackstatus ( *GetSound )( struct VoiceNode *voice );
  76. void ( *mix )( unsigned long position, unsigned long rate,
  77. char *start, unsigned long length );
  78. char *NextBlock;
  79. char *LoopStart;
  80. char *LoopEnd;
  81. unsigned LoopCount;
  82. unsigned long LoopSize;
  83. unsigned long BlockLength;
  84. unsigned long PitchScale;
  85. unsigned long FixedPointBufferSize;
  86. char *sound;
  87. unsigned long length;
  88. unsigned long SamplingRate;
  89. unsigned long RateScale;
  90. unsigned long position;
  91. int Playing;
  92. int handle;
  93. int priority;
  94. void ( *DemandFeed )( char **ptr, unsigned long *length );
  95. short *LeftVolume;
  96. short *RightVolume;
  97. unsigned long callbackval;
  98. } VoiceNode;
  99. typedef struct
  100. {
  101. VoiceNode *start;
  102. VoiceNode *end;
  103. } VList;
  104. typedef struct
  105. {
  106. char left;
  107. char right;
  108. } Pan;
  109. typedef signed short MONO16;
  110. typedef signed char MONO8;
  111. typedef struct
  112. {
  113. MONO16 left;
  114. MONO16 right;
  115. // unsigned short left;
  116. // unsigned short right;
  117. } STEREO16;
  118. typedef struct
  119. {
  120. MONO16 left;
  121. MONO16 right;
  122. } SIGNEDSTEREO16;
  123. typedef struct
  124. {
  125. // MONO8 left;
  126. // MONO8 right;
  127. char left;
  128. char right;
  129. } STEREO8;
  130. typedef struct
  131. {
  132. char RIFF[ 4 ];
  133. unsigned long file_size;
  134. char WAVE[ 4 ];
  135. char fmt[ 4 ];
  136. unsigned long format_size;
  137. } riff_header;
  138. typedef struct
  139. {
  140. unsigned short wFormatTag;
  141. unsigned short nChannels;
  142. unsigned long nSamplesPerSec;
  143. unsigned long nAvgBytesPerSec;
  144. unsigned short nBlockAlign;
  145. unsigned short nBitsPerSample;
  146. } format_header;
  147. typedef struct
  148. {
  149. unsigned char DATA[ 4 ];
  150. unsigned long size;
  151. } data_header;
  152. typedef MONO8 VOLUME8[ 256 ];
  153. typedef MONO16 VOLUME16[ 256 ];
  154. typedef char HARSH_CLIP_TABLE_8[ MV_NumVoices * 256 ];
  155. static void MV_Mix( VoiceNode *voice, int buffer );
  156. static void MV_PlayVoice( VoiceNode *voice );
  157. static void MV_StopVoice( VoiceNode *voice );
  158. static void MV_ServiceVoc( void );
  159. static playbackstatus MV_GetNextVOCBlock( VoiceNode *voice );
  160. static playbackstatus MV_GetNextDemandFeedBlock( VoiceNode *voice );
  161. static playbackstatus MV_GetNextRawBlock( VoiceNode *voice );
  162. static playbackstatus MV_GetNextWAVBlock( VoiceNode *voice );
  163. static void MV_ServiceRecord( void );
  164. static VoiceNode *MV_GetVoice( int handle );
  165. static VoiceNode *MV_AllocVoice( int priority );
  166. static short *MV_GetVolumeTable( int vol );
  167. static void MV_SetVoiceMixMode( VoiceNode *voice );
  168. static void MV_SetVoicePitch( VoiceNode *voice, unsigned long rate, int pitchoffset );
  169. static void MV_CalcVolume( int MaxLevel );
  170. static void MV_CalcPanTable( void );
  171. #define ATR_INDEX 0x3c0
  172. #define STATUS_REGISTER_1 0x3da
  173. #define SetBorderColor(color) \
  174. { \
  175. inp (STATUS_REGISTER_1); \
  176. outp (ATR_INDEX,0x31); \
  177. outp (ATR_INDEX,color); \
  178. }
  179. void ClearBuffer_DW( void *ptr, unsigned data, int length );
  180. #pragma aux ClearBuffer_DW = \
  181. "cld", \
  182. "push es", \
  183. "push ds", \
  184. "pop es", \
  185. "rep stosd", \
  186. "pop es", \
  187. parm [ edi ] [ eax ] [ ecx ] modify exact [ ecx edi ];
  188. void MV_Mix8BitMono( unsigned long position, unsigned long rate,
  189. char *start, unsigned long length );
  190. void MV_Mix8BitStereo( unsigned long position,
  191. unsigned long rate, char *start, unsigned long length );
  192. void MV_Mix16BitMono( unsigned long position,
  193. unsigned long rate, char *start, unsigned long length );
  194. void MV_Mix16BitStereo( unsigned long position,
  195. unsigned long rate, char *start, unsigned long length );
  196. void MV_Mix16BitMono16( unsigned long position,
  197. unsigned long rate, char *start, unsigned long length );
  198. void MV_Mix8BitMono16( unsigned long position, unsigned long rate,
  199. char *start, unsigned long length );
  200. void MV_Mix8BitStereo16( unsigned long position,
  201. unsigned long rate, char *start, unsigned long length );
  202. void MV_Mix16BitStereo16( unsigned long position,
  203. unsigned long rate, char *start, unsigned long length );
  204. void MV_16BitReverb( char *src, char *dest, VOLUME16 *volume, int count );
  205. #pragma aux MV_16BitReverb parm [eax] [edx] [ebx] [ecx] modify exact [eax ebx ecx edx esi edi]
  206. void MV_8BitReverb( signed char *src, signed char *dest, VOLUME16 *volume, int count );
  207. #pragma aux MV_8BitReverb parm [eax] [edx] [ebx] [ecx] modify exact [eax ebx ecx edx esi edi]
  208. void MV_16BitReverbFast( char *src, char *dest, int count, int shift );
  209. #pragma aux MV_16BitReverbFast parm [eax] [edx] [ebx] [ecx] modify exact [eax ebx ecx edx esi edi]
  210. void MV_8BitReverbFast( signed char *src, signed char *dest, int count, int shift );
  211. #pragma aux MV_8BitReverbFast parm [eax] [edx] [ebx] [ecx] modify exact [eax ebx ecx edx esi edi]
  212. #endif