1 //
2 //      ID Engine
3 //      ID_SD.h - Sound Manager Header
4 //      Version for Wolfenstein
5 //      By Jason Blochowiak
6 //
7 
8 #ifndef __ID_SD__
9 #define __ID_SD__
10 
11 #include <SDL_mixer.h>
12 
13 #include "wl_def.h"
14 #include "sndinfo.h"
15 
16 #define alOut(n,b) 		YM3812Write(oplChip, n, b, AdlibVolume)
17 #define alOutMusic(n,b)	YM3812Write(oplChip, n, b, MusicVolume)
18 
19 typedef enum
20 {
21 	sdm_Off,
22 	sdm_PC,sdm_AdLib,
23 } SDMode;
24 
25 typedef enum
26 {
27 	smm_Off,smm_AdLib
28 } SMMode;
29 
30 typedef enum
31 {
32 	sds_Off,sds_PC,sds_SoundBlaster
33 } SDSMode;
34 
35 #pragma pack(push, 1)
36 typedef struct
37 {
38 	longword        length;
39 	word            priority;
40 } SoundCommon;
41 
42 #define ORIG_SOUNDCOMMON_SIZE 6
43 
44 //      PC Sound stuff
45 #define pcTimer         0x42
46 #define pcTAccess       0x43
47 #define pcSpeaker       0x61
48 
49 #define pcSpkBits       3
50 
51 typedef struct
52 {
53 	SoundCommon     common;
54 	byte            data[1];
55 } PCSound;
56 
57 //      Register addresses
58 // Operator stuff
59 #define alChar          0x20
60 #define alScale         0x40
61 #define alAttack        0x60
62 #define alSus           0x80
63 #define alWave          0xe0
64 // Channel stuff
65 #define alFreqL         0xa0
66 #define alFreqH         0xb0
67 #define alFeedCon       0xc0
68 // Global stuff
69 #define alEffects       0xbd
70 
71 typedef struct
72 {
73 	byte    mChar,cChar,
74 			mScale,cScale,
75 			mAttack,cAttack,
76 			mSus,cSus,
77 			mWave,cWave,
78 			nConn,
79 
80 			// These are only for Muse - these bytes are really unused
81 			voice,
82 			mode;
83 	byte    unused[3];
84 } Instrument;
85 
86 #define ORIG_INSTRUMENT_SIZE 16
87 
88 typedef struct
89 {
90 	SoundCommon     common;
91 	Instrument      inst;
92 	byte            block;
93 	byte            data[1];
94 } AdLibSound;
95 
96 #define ORIG_ADLIBSOUND_SIZE (ORIG_SOUNDCOMMON_SIZE + ORIG_INSTRUMENT_SIZE + 2)
97 
98 //
99 //      Sequencing stuff
100 //
101 #define sqMaxTracks     10
102 #define OPL_CHANNELS	9
103 
104 typedef struct
105 {
106 	word    length;
107 	word    values[1];
108 } MusicGroup;
109 
110 typedef struct
111 {
112 	int valid;
113 	fixed globalsoundx, globalsoundy;
114 } globalsoundpos;
115 #pragma pack(pop)
116 
117 extern globalsoundpos channelSoundPos[];
118 
119 // Global variables
120 extern  bool			AdLibPresent,
121 						SoundBlasterPresent,
122 						SoundPositioned;
123 extern  SDMode          SoundMode;
124 extern  SDSMode         DigiMode;
125 extern  SMMode          MusicMode;
126 static const int MAX_VOLUME = 20;
MULTIPLY_VOLUME(const int & v)127 static inline double MULTIPLY_VOLUME(const int &v)
128 {
129 	return (double(v)+0.3)/(MAX_VOLUME+0.3);
130 }
131 extern	int				AdlibVolume;
132 extern	int				MusicVolume;
133 extern	int				SoundVolume;
134 extern bool SD_UpdatePCSpeakerVolume(int which=0);
135 extern bool SD_UpdateMusicVolume(int which);
136 
137 enum SoundChannel
138 {
139 	SD_GENERIC = -1,
140 	SD_WEAPONS,
141 	SD_BOSSWEAPONS
142 };
143 
144 extern	Mix_Music		*music;
145 
146 #define GetTimeCount()  ((SDL_GetTicks()*7)/100)
147 
Delay(int wolfticks)148 inline void Delay(int wolfticks)
149 {
150 	if(wolfticks>0) SDL_Delay(wolfticks * 100 / 7);
151 }
152 
153 // Function prototypes
154 extern  void    SD_Startup(void),
155 				SD_Shutdown(void);
156 
157 extern  void    SD_PositionSound(int leftvol,int rightvol);
158 extern  int		SD_PlaySound(const char* sound,SoundChannel chan=SD_GENERIC);
159 extern  void    SD_SetPosition(int channel, int leftvol,int rightvol);
160 extern  void    SD_StopSound(void),
161 				SD_WaitSoundDone(void);
162 
163 extern  void    SD_StartMusic(const char* chunk);
164 extern  int     SD_PauseMusic(void);
165 extern  void    SD_ContinueMusic(const char* chunk, int startoffs);
166 extern  void    SD_MusicOn(void),
167 				SD_FadeOutMusic(void);
168 extern  int     SD_MusicOff(void);
169 
170 extern  bool	SD_MusicPlaying(void);
171 extern  bool	SD_SetSoundMode(SDMode mode);
172 extern  bool	SD_SetMusicMode(SMMode mode);
173 extern  bool    SD_SoundPlaying(void);
174 
175 extern  void    SD_SetDigiDevice(SDSMode);
176 extern  byte*	SD_PrepareSound(int which);
177 extern  int     SD_PlayDigitized(const SoundData &which,int leftpos,int rightpos,SoundChannel chan=SD_GENERIC);
178 extern  void    SD_StopDigitized(void);
179 
180 #endif
181