ReactOS 0.4.15-dev-7924-g5949c20
control.c File Reference
#include <sndblst.h>
Include dependency graph for control.c:

Go to the source code of this file.

Functions

BOOLEAN WaitForReady (PSOUND_BLASTER_PARAMETERS SBDevice, UCHAR Port)
 
BOOLEAN SbWriteData (PSOUND_BLASTER_PARAMETERS SBDevice, UCHAR Data)
 
BOOLEAN SbReadData (PSOUND_BLASTER_PARAMETERS SBDevice, PUCHAR Data)
 
BOOLEAN ResetSoundBlaster (PSOUND_BLASTER_PARAMETERS SBDevice)
 
ULONG GetSoundBlasterModel (PSOUND_BLASTER_PARAMETERS SBDevice)
 
BOOLEAN IsSampleRateCompatible (PSOUND_BLASTER_PARAMETERS SBDevice, ULONG SampleRate)
 
BOOLEAN SetOutputSampleRate (PSOUND_BLASTER_PARAMETERS SBDevice, ULONG SampleRate)
 
BOOLEAN EnableSpeaker (PSOUND_BLASTER_PARAMETERS SBDevice)
 
BOOLEAN DisableSpeaker (PSOUND_BLASTER_PARAMETERS SBDevice)
 
BOOLEAN StartSoundOutput (PSOUND_BLASTER_PARAMETERS SBDevice, ULONG BitDepth, ULONG Channels, ULONG BlockSize)
 

Function Documentation

◆ DisableSpeaker()

BOOLEAN DisableSpeaker ( PSOUND_BLASTER_PARAMETERS  SBDevice)

Definition at line 167 of file control.c.

169{
170 DPRINT("Disabling speaker\n");
171
172 return SbWriteData(SBDevice, SbDisableSpeaker);
173}
BOOLEAN SbWriteData(PSOUND_BLASTER_PARAMETERS SBDevice, UCHAR Data)
Definition: control.c:31
@ SbDisableSpeaker
Definition: sndblst.h:51
#define DPRINT
Definition: sndvol32.h:71

◆ EnableSpeaker()

BOOLEAN EnableSpeaker ( PSOUND_BLASTER_PARAMETERS  SBDevice)

Definition at line 158 of file control.c.

160{
161 DPRINT("Enabling speaker\n");
162
163 return SbWriteData(SBDevice, SbEnableSpeaker);
164}
@ SbEnableSpeaker
Definition: sndblst.h:50

Referenced by CreateSoundBlaster(), and InitDevice().

◆ GetSoundBlasterModel()

ULONG GetSoundBlasterModel ( PSOUND_BLASTER_PARAMETERS  SBDevice)

Definition at line 95 of file control.c.

97{
98 UCHAR MajorVer, MinorVer;
99
100 DPRINT("Querying DSP version\n");
101
102 if ( ! SbWriteData(SBDevice, SbGetDspVersion) )
103 return NotDetected;
104
105 if ( ! WaitToRead(SBDevice) )
106 return NotDetected;
107
108 if ( SbReadData(SBDevice, &MajorVer) )
109 {
110 if ( SbReadData(SBDevice, &MinorVer) )
111 {
112 DPRINT("Version %d.%d\n", MajorVer, MinorVer);
113
114 SBDevice->dsp_version = (MajorVer * 256) + MinorVer;
115
116 if ( SBDevice->dsp_version < 0x0200 )
117 return SoundBlaster;
118 else if ( ( SBDevice->dsp_version & 0xFF00 ) == 0x0200 )
119 return SoundBlaster2;
120 else if ( ( SBDevice->dsp_version & 0xFF00 ) == 0x0300 )
121 return SoundBlasterPro;
122 else if ( SBDevice->dsp_version >= 0x0400 )
123 return SoundBlaster16;
124
125 return NotDetected;
126 }
127 }
128
129 return NotDetected;
130}
BOOLEAN SbReadData(PSOUND_BLASTER_PARAMETERS SBDevice, PUCHAR Data)
Definition: control.c:45
@ NotDetected
Definition: sndblst.h:23
@ SoundBlaster
Definition: sndblst.h:24
@ SoundBlaster2
Definition: sndblst.h:26
@ SoundBlaster16
Definition: sndblst.h:29
@ SoundBlasterPro
Definition: sndblst.h:25
@ SbGetDspVersion
Definition: sndblst.h:53
#define WaitToRead(sbdevice)
Definition: sndblst.h:109
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ IsSampleRateCompatible()

BOOLEAN IsSampleRateCompatible ( PSOUND_BLASTER_PARAMETERS  SBDevice,
ULONG  SampleRate 
)

Definition at line 134 of file control.c.

137{
138 /* TODO */
139 return TRUE;
140}
#define TRUE
Definition: types.h:120

◆ ResetSoundBlaster()

BOOLEAN ResetSoundBlaster ( PSOUND_BLASTER_PARAMETERS  SBDevice)

Definition at line 59 of file control.c.

61{
62 BOOLEAN acked = FALSE;
64
65 SbWriteReset(SBDevice, 0x01);
66 for (timeout = 0; timeout < 30000; timeout ++ );
67 SbWriteReset(SBDevice, 0x00);
68
69 DPRINT("Waiting for SB to acknowledge our reset request\n");
70
71 if ( ! WaitToRead(SBDevice) )
72 {
73 DPRINT("Didn't get an ACK :(\n");
74 return FALSE;
75 }
76
77 timeout = 0;
78
79 while ( ( ! acked ) && ( timeout < SB_TIMEOUT ) )
80 {
81 acked = ( SbReadDataWithoutWait(SBDevice) == SB_DSP_READY );
82 timeout ++;
83 }
84
85 if ( ! acked )
86 {
87 DPRINT("Didn't get an ACK :(\n");
88 return FALSE;
89 }
90
91 return TRUE;
92}
unsigned char BOOLEAN
#define FALSE
Definition: types.h:117
#define SB_TIMEOUT
Definition: sndblst.h:17
#define SbWriteReset(sbdevice, data)
Definition: sndblst.h:83
#define SbReadDataWithoutWait(sbdevice)
Definition: sndblst.h:89
#define SB_DSP_READY
Definition: sndblst.h:19
Definition: dhcpd.h:245
uint32_t ULONG
Definition: typedefs.h:59

Referenced by InitializeSoundBlaster().

◆ SbReadData()

BOOLEAN SbReadData ( PSOUND_BLASTER_PARAMETERS  SBDevice,
PUCHAR  Data 
)

Definition at line 45 of file control.c.

48{
49 if ( ! WaitToWrite(SBDevice) )
50 return FALSE;
51
52 *Data = SbRead(SBDevice, SB_READ_DATA_PORT);
53 DPRINT("Read 0x%x from Sound Blaster card (data)\n", *Data);
54
55 return TRUE;
56}
@ SB_READ_DATA_PORT
Definition: sndblst.h:35
#define SbRead(sbdevice, subport)
Definition: sndblst.h:80
#define WaitToWrite(sbdevice)
Definition: sndblst.h:106

Referenced by GetSoundBlasterModel().

◆ SbWriteData()

BOOLEAN SbWriteData ( PSOUND_BLASTER_PARAMETERS  SBDevice,
UCHAR  Data 
)

Definition at line 31 of file control.c.

34{
35 if ( ! WaitToWrite(SBDevice) )
36 return FALSE;
37
38 DPRINT("Writing 0x%x to Sound Blaster card (data)\n", Data);
40
41 return TRUE;
42}
@ SB_WRITE_DATA_PORT
Definition: sndblst.h:36
#define SbWrite(sbdevice, subport, data)
Definition: sndblst.h:77

Referenced by DisableSpeaker(), EnableSpeaker(), GetSoundBlasterModel(), SetOutputSampleRate(), and StartSoundOutput().

◆ SetOutputSampleRate()

BOOLEAN SetOutputSampleRate ( PSOUND_BLASTER_PARAMETERS  SBDevice,
ULONG  SampleRate 
)

Definition at line 143 of file control.c.

146{
147 /* Only works for DSP v4.xx */
148 DPRINT("Setting sample rate\n");
149
150 SbWriteData(SBDevice, SbSetOutputRate);
151 SbWriteData(SBDevice, SampleRate / 256);
152 SbWriteData(SBDevice, SampleRate % 256);
153
154 return TRUE;
155}
@ SbSetOutputRate
Definition: sndblst.h:45

Referenced by InitDevice().

◆ StartSoundOutput()

BOOLEAN StartSoundOutput ( PSOUND_BLASTER_PARAMETERS  SBDevice,
ULONG  BitDepth,
ULONG  Channels,
ULONG  BlockSize 
)

Definition at line 176 of file control.c.

181{
182 DPRINT("Initializing output with %d channels at %d bits/sample\n", Channels, BitDepth);
183
184 UCHAR command = 0xc6, mode = 0x00;
185
186 if ( ( Channels < 1 ) || ( Channels > 2 ) )
187 return FALSE;
188
189 if ( ( BitDepth != 8 ) && ( BitDepth != 16 ) )
190 return FALSE;
191
192 switch ( BitDepth )
193 {
194 case 8 : command = 0xc6; break;
195 case 16 : command = 0xb6; break;
196 };
197
198 switch ( Channels )
199 {
200 case 1 : mode = 0x00; break;
201 case 2 : mode = 0x20; break;
202 }
203#if 0
204 first_byte = (BitDepth == 16) ? 0xb6 : 0xc6;
205 second_byte = (Channels == 1) ? 0x20 : 0x00;
206#endif
207
208 if ( SBDevice->dsp_version < 0x0400 )
209 {
210 /* TODO: Additional programming required */
211 }
212
213 /* Send freq */
214 SbWriteData(SBDevice, command);
215 SbWriteData(SBDevice, mode);
216 SbWriteData(SBDevice, BlockSize % 256);
217 SbWriteData(SBDevice, BlockSize / 256);
218
219 DPRINT("Finished programming the DSP\n");
220
221 return TRUE;
222}
GLenum mode
Definition: glext.h:6217

◆ WaitForReady()

BOOLEAN WaitForReady ( PSOUND_BLASTER_PARAMETERS  SBDevice,
UCHAR  Port 
)

Definition at line 12 of file control.c.

15{
17 BOOL ready = FALSE;
18
19 while ( ( ! ready ) && ( timeout > 0 ) )
20 {
21 if ( SbRead(SBDevice, Port) & 0x80 )
22 return TRUE;
23
24 timeout --;
25 }
26
27 return FALSE;
28}
unsigned int BOOL
Definition: ntddk_ex.h:94
CPPORT Port[4]
Definition: headless.c:35