ReactOS  0.4.15-dev-506-ga3ec01c
sbdsp.h
Go to the documentation of this file.
1 /*
2  ReactOS Sound System
3  Sound Blaster DSP support
4 
5  Author:
6  Andrew Greenwood (silverblade@reactos.org)
7 
8  History:
9  26 May 2008 - Created
10 
11  Notes:
12  Where timeouts are concerned, a value of 0 is interpreted as "forever".
13 */
14 
15 #ifndef ROS_SOUND_SBDSP_H
16 #define ROS_SOUND_SBDSP_H
17 
18 /*
19  Product versions
20  DSP 1.0, 1.5, 2.0, 2.01 correspond with respective Sound Blaster versions.
21  DSP 3.xx is Sound Blaster Pro
22  DSP 4.xx is Sound Blaster 16
23 */
24 
25 #define SOUND_BLASTER_1_0 L"Sound Blaster 1.0"
26 #define SOUND_BLASTER_1_5 L"Sound Blaster 1.5"
27 #define SOUND_BLASTER_2_0 L"Sound Blaster 2.0"
28 #define SOUND_BLASTER_PRO L"Sound Blaster Pro"
29 #define SOUND_BLASTER_16 L"Sound Blaster 16"
30 
31 
32 /*
33  Sound Blaster ports I/O
34 */
35 #define READ_SB_FM1_STATUS(bp) READ_PORT_UCHAR((PUCHAR) bp)
36 #define WRITE_SB_FM1_REGISTER(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp, x)
37 #define WRITE_SB_FM1_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x01, x)
38 
39 #define READ_SB_AFM_STATUS(bp) READ_PORT_UCHAR((PUCHAR) bp+0x02)
40 #define WRITE_SB_AFM_REGISTER(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x02, x)
41 #define WRITE_SB_AFM_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x03, x)
42 
43 #define WRITE_SB_MIXER_REGISTER(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x04, x)
44 #define READ_SB_MIXER_DATA(bp) READ_PORT_UCHAR((PUCHAR) bp+0x05)
45 #define WRITE_SB_MIXER_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x05, x)
46 
47 #define WRITE_SB_DSP_RESET(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x06, x)
48 
49 #define READ_SB_FM2_STATUS(bp) READ_PORT_UCHAR((PUCHAR) bp+0x08)
50 #define WRITE_SB_FM2_REGISTER(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x08, x)
51 #define WRITE_SB_FM2_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x09, x)
52 
53 #define READ_SB_DSP_DATA(bp) READ_PORT_UCHAR((PUCHAR) bp+0x0A)
54 #define WRITE_SB_DSP_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x0C, x)
55 #define WRITE_SB_DSP_COMMAND(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x0C, x)
56 
57 /* Clear to send */
58 #define SB_DSP_CLEAR_TO_SEND(bp) \
59  ( ! (READ_PORT_UCHAR((PUCHAR) bp+0x0C) & 0x80 ) )
60 
61 /* Data available for reading */
62 #define SB_DSP_DATA_AVAILABLE(bp) \
63  ( READ_PORT_UCHAR((PUCHAR) bp+0x0E) & 0x80 )
64 
65 
66 #define SB_DSP_READY 0xAA
67 
68 /*
69  Sound Blaster DSP commands
70  (partial list)
71 */
72 #define SB_DSP_OUTPUT_RATE 0x41
73 #define SB_DSP_INPUT_RATE 0x42
74 #define SB_DSP_BLOCK_SIZE 0x48
75 #define SB_DSP_SPEAKER_ON 0xD1
76 #define SB_DSP_SPEAKER_OFF 0xD3
77 #define SB_DSP_SPEAKER_STATUS 0xD8
78 #define SB_DSP_VERSION 0xE1
79 
80 /*
81  Mixer lines (legacy)
82 */
83 #define SB_MIX_VOC_LEVEL 0x04
84 #define SB_MIX_LEGACY_MIC_LEVEL 0x0A
85 #define SB_MIX_MASTER_LEVEL 0x22
86 #define SB_MIX_FM_LEVEL 0x26
87 #define SB_MIX_CD_LEVEL 0x28
88 #define SB_MIX_LINE_LEVEL 0x2E
89 
90 /*
91  Mixer lines
92 */
93 #define SB_MIX_RESET 0x00
94 #define SB_MIX_MASTER_LEFT_LEVEL 0x30
95 #define SB_MIX_MASTER_RIGHT_LEVEL 0x31
96 #define SB_MIX_VOC_LEFT_LEVEL 0x32
97 #define SB_MIX_VOC_RIGHT_LEVEL 0x33
98 #define SB_MIX_MIDI_LEFT_LEVEL 0x34
99 #define SB_MIX_MIDI_RIGHT_LEVEL 0x35
100 #define SB_MIX_CD_LEFT_LEVEL 0x36
101 #define SB_MIX_CD_RIGHT_LEVEL 0x37
102 #define SB_MIX_LINE_LEFT_LEVEL 0x38
103 #define SB_MIX_LINE_RIGHT_LEVEL 0x39
104 #define SB_MIX_MIC_LEVEL 0x3A
105 #define SB_MIX_PC_SPEAKER_LEVEL 0x3B
106 #define SB_MIX_OUTPUT_SWITCHES 0x3C
107 #define SB_MIX_INPUT_LEFT_SWITCHES 0x3D
108 #define SB_MIX_INPUT_RIGHT_SWITCHES 0x3E
109 #define SB_MIX_INPUT_LEFT_GAIN 0x3F
110 #define SB_MIX_INPUT_RIGHT_GAIN 0x40
111 #define SB_MIX_OUTPUT_LEFT_GAIN 0x41
112 #define SB_MIX_OUTPUT_RIGHT_GAIN 0x42
113 #define SB_MIX_AGC 0x43
114 #define SB_MIX_TREBLE_LEFT_LEVEL 0x44
115 #define SB_MIX_TREBLE_RIGHT_LEVEL 0x45
116 #define SB_MIX_BASS_LEFT_LEVEL 0x46
117 #define SB_MIX_BASS_RIGHT_LEVEL 0x47
118 
119 /*
120  Mixer switches
121  (are these correct?)
122 */
123 #define SB_MIX_MIDI_LEFT_SWITCH 0x01
124 #define SB_MIX_MIDI_RIGHT_SWITCH 0x02
125 #define SB_MIX_LINE_LEFT_SWITCH 0x04
126 #define SB_MIX_LINE_RIGHT_SWITCH 0x08
127 #define SB_MIX_CD_LEFT_SWITCH 0x10
128 #define SB_MIX_CD_RIGHT_SWITCH 0x20
129 #define SB_MIX_MIC_SWITCH 0x40
130 
131 
132 /*
133  Reset the Sound Blaster DSP.
134 */
135 NTSTATUS
136 SbDspReset(
137  IN PUCHAR BasePort,
138  IN ULONG Timeout);
139 
140 /*
141  Wait for the Sound Blaster DSP to be ready for data to be written to it.
142 */
143 NTSTATUS
145  IN PUCHAR BasePort,
146  IN ULONG Timeout);
147 
148 /*
149  Wait for data to be ready for reading from the Sound Blaster DSP.
150 */
151 NTSTATUS
153  IN PUCHAR BasePort,
154  IN ULONG Timeout);
155 
156 /*
157  Wait for the Sound Blaster DSP to be ready for data to be written to it,
158  then (providing it becomes ready within the timeout period), write the
159  data to it.
160 */
161 NTSTATUS
162 SbDspWrite(
163  IN PUCHAR BasePort,
164  IN UCHAR DataByte,
165  IN ULONG Timeout);
166 
167 /*
168  Wait for the Sound Blaster DSP to be ready for data to be read from it,
169  then read the data from it into the pointer supplied as DataByte. If
170  the timeout is exceeded, DataByte will not be modified.
171 */
172 NTSTATUS
173 SbDspRead(
174  IN PUCHAR BasePort,
175  OUT PUCHAR DataByte,
176  IN ULONG Timeout);
177 
178 /*
179  This can only be called immediately after a reset has been issued. The
180  major version and minor version are returned in MajorVersion and
181  MinorVersion, respectively.
182 
183  The timeout applies to each DSP read/write performed. Note that the
184  data pointed to by MajorVersion may still fail if the retrieval of
185  MinorVersion times out.
186 */
187 NTSTATUS
189  IN PUCHAR BasePort,
192  IN ULONG Timeout);
193 
194 /*
195  Turn the speaker on.
196 */
197 NTSTATUS
199  IN PUCHAR BasePort,
200  IN ULONG Timeout);
201 
202 /*
203  Turn the speaker off.
204 */
205 NTSTATUS
207  IN PUCHAR BasePort,
208  IN ULONG Timeout);
209 
210 /*
211  Obtains the speaker status, storing the result in IsEnabled. This will be
212  TRUE if the speaker is enabled, otherwise FALSE.
213 */
214 NTSTATUS
216  IN PUCHAR BasePort,
217  OUT PBOOLEAN IsEnabled,
218  IN ULONG Timeout);
219 
220 /*
221  Validate the input sample rate. The major and minor versions are required
222  to determine the capabilities of the card.
223 */
224 BOOLEAN
228  IN USHORT Rate,
229  IN BOOLEAN Stereo);
230 
231 /*
232  Validate the output sample rate. The major and minor versions are required
233  to determine the capabilities of the card.
234 */
235 BOOLEAN
239  IN USHORT Rate,
240  IN BOOLEAN Stereo);
241 
242 /*
243  Set the output/playback rate
244  * DSP 4.xx only
245 */
246 NTSTATUS
248  IN PUCHAR BasePort,
249  IN USHORT Rate,
250  IN ULONG Timeout);
251 
252 /*
253  Set the input/record rate
254  * DSP 4.xx only
255 */
256 NTSTATUS
258  IN PUCHAR BasePort,
259  IN USHORT Rate,
260  IN ULONG Timeout);
261 
262 
263 /*
264  Reset the mixer
265 */
266 VOID
267 SbMixerReset(IN PUCHAR BasePort);
268 
269 /*
270  Pack mixer level data
271 */
272 NTSTATUS
274  IN UCHAR Line,
275  IN UCHAR Level,
276  OUT PUCHAR PackedLevel);
277 
278 /*
279  Unpack mixer level data
280 */
281 NTSTATUS
283  IN UCHAR Line,
284  IN UCHAR PackedLevel,
285  OUT PUCHAR Level);
286 
287 /*
288  Set a mixer line level
289 */
290 NTSTATUS
292  IN PUCHAR BasePort,
293  IN UCHAR Line,
294  IN UCHAR Level);
295 
296 /*
297  Get a mixer line level
298 */
299 NTSTATUS
301  IN PUCHAR BasePort,
302  IN UCHAR Line,
303  OUT PUCHAR Level);
304 
305 /*
306  Enable automatic gain control
307 */
308 VOID
309 SbMixerEnableAGC(IN PUCHAR BasePort);
310 
311 /*
312  Disable automatic gain control
313 */
314 VOID
315 SbMixerDisableAGC(IN PUCHAR BasePort);
316 
317 /*
318  Retrieve the current state of the automatic gain control
319 */
320 BOOLEAN
321 SbMixerIsAGCEnabled(IN PUCHAR BasePort);
322 
323 
324 #endif
NTSTATUS SbDsp4SetOutputRate(IN PUCHAR BasePort, IN USHORT Rate, IN ULONG Timeout)
Definition: rate.c:117
#define IN
Definition: typedefs.h:39
NTSTATUS SbDspWrite(IN PUCHAR BasePort, IN UCHAR DataByte, IN ULONG Timeout)
Definition: dsp_io.c:99
ULONG MinorVersion
Definition: ros_glue.cpp:5
ULONG MajorVersion
Definition: ros_glue.cpp:4
NTSTATUS SbDspIsSpeakerEnabled(IN PUCHAR BasePort, OUT PBOOLEAN IsEnabled, IN ULONG Timeout)
Definition: speaker.c:38
NTSTATUS SbDspDisableSpeaker(IN PUCHAR BasePort, IN ULONG Timeout)
Definition: speaker.c:27
NTSTATUS SbDspReset(IN PUCHAR BasePort, IN ULONG Timeout)
Definition: dsp_io.c:19
NTSTATUS SbMixerSetLevel(IN PUCHAR BasePort, IN UCHAR Line, IN UCHAR Level)
Definition: mixer.c:151
NTSTATUS SbDspWaitToWrite(IN PUCHAR BasePort, IN ULONG Timeout)
Definition: dsp_io.c:63
NTSTATUS SbMixerUnpackLevelData(IN UCHAR Line, IN UCHAR PackedLevel, OUT PUCHAR Level)
Definition: mixer.c:96
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
NTSTATUS SbMixerGetLevel(IN PUCHAR BasePort, IN UCHAR Line, OUT PUCHAR Level)
Definition: mixer.c:185
NTSTATUS SbDspRead(IN PUCHAR BasePort, OUT PUCHAR DataByte, IN ULONG Timeout)
Definition: dsp_io.c:120
BOOLEAN SbMixerIsAGCEnabled(IN PUCHAR BasePort)
Definition: mixer.c:238
unsigned char BOOLEAN
NTSTATUS SbDspEnableSpeaker(IN PUCHAR BasePort, IN ULONG Timeout)
Definition: speaker.c:19
NTSTATUS SbDspWaitToRead(IN PUCHAR BasePort, IN ULONG Timeout)
Definition: dsp_io.c:81
BOOLEAN SbDspIsValidOutputRate(IN UCHAR MajorVersion, IN UCHAR MinorVersion, IN USHORT Rate, IN BOOLEAN Stereo)
Definition: rate.c:56
NTSTATUS SbDspGetVersion(IN PUCHAR BasePort, OUT PUCHAR MajorVersion, OUT PUCHAR MinorVersion, IN ULONG Timeout)
Definition: version.c:19
VOID SbMixerEnableAGC(IN PUCHAR BasePort)
Definition: mixer.c:222
NTSTATUS SbDsp4SetInputRate(IN PUCHAR BasePort, IN USHORT Rate, IN ULONG Timeout)
Definition: rate.c:135
Definition: ncftp.h:79
unsigned char UCHAR
Definition: xmlstorage.h:181
char * PBOOLEAN
Definition: retypes.h:11
VOID SbMixerReset(IN PUCHAR BasePort)
Definition: mixer.c:24
static ULONG Timeout
Definition: ping.c:61
unsigned short USHORT
Definition: pedump.c:61
BOOLEAN SbDspIsValidInputRate(IN UCHAR MajorVersion, IN UCHAR MinorVersion, IN USHORT Rate, IN BOOLEAN Stereo)
Definition: rate.c:19
VOID SbMixerDisableAGC(IN PUCHAR BasePort)
Definition: mixer.c:230
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS SbMixerPackLevelData(IN UCHAR Line, IN UCHAR Level, OUT PUCHAR PackedLevel)
Definition: mixer.c:31