ReactOS  0.4.14-dev-323-g6fe6a88
control.c
Go to the documentation of this file.
1 #include <sndblst.h>
2 
3 /*
4  TODO: MmMapIoSpace()
5 */
6 
7 /*
8  This checks the read or write status port of the device.
9 */
10 
11 BOOLEAN
14  UCHAR Port)
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 }
29 
30 BOOLEAN
33  UCHAR Data)
34 {
35  if ( ! WaitToWrite(SBDevice) )
36  return FALSE;
37 
38  DPRINT("Writing 0x%x to Sound Blaster card (data)\n", Data);
39  SbWrite(SBDevice, SB_WRITE_DATA_PORT, Data);
40 
41  return TRUE;
42 }
43 
44 BOOLEAN
47  PUCHAR Data)
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 }
57 
58 BOOLEAN
61 {
62  BOOLEAN acked = FALSE;
63  ULONG timeout;
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 }
93 
94 ULONG
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 }
131 
132 
133 BOOLEAN
135  PSOUND_BLASTER_PARAMETERS SBDevice,
136  ULONG SampleRate)
137 {
138  /* TODO */
139  return TRUE;
140 }
141 
142 BOOLEAN
144  PSOUND_BLASTER_PARAMETERS SBDevice,
145  ULONG SampleRate)
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 }
156 
157 BOOLEAN
159  PSOUND_BLASTER_PARAMETERS SBDevice)
160 {
161  DPRINT("Enabling speaker\n");
162 
163  return SbWriteData(SBDevice, SbEnableSpeaker);
164 }
165 
166 BOOLEAN
168  PSOUND_BLASTER_PARAMETERS SBDevice)
169 {
170  DPRINT("Disabling speaker\n");
171 
172  return SbWriteData(SBDevice, SbDisableSpeaker);
173 }
174 
175 BOOLEAN
177  PSOUND_BLASTER_PARAMETERS SBDevice,
178  ULONG BitDepth,
179  ULONG Channels,
180  ULONG BlockSize)
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 }
BOOLEAN SbWriteData(PSOUND_BLASTER_PARAMETERS SBDevice, UCHAR Data)
Definition: control.c:31
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
#define SbWriteReset(sbdevice, data)
Definition: sndblst.h:83
Definition: dhcpd.h:245
ULONG GetSoundBlasterModel(PSOUND_BLASTER_PARAMETERS SBDevice)
Definition: control.c:95
GLbitfield GLuint64 timeout
Definition: glext.h:7164
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOLEAN ResetSoundBlaster(PSOUND_BLASTER_PARAMETERS SBDevice)
Definition: control.c:59
BOOLEAN SetOutputSampleRate(PSOUND_BLASTER_PARAMETERS SBDevice, ULONG SampleRate)
Definition: control.c:143
unsigned char BOOLEAN
#define SB_TIMEOUT
Definition: sndblst.h:17
void DPRINT(...)
Definition: polytest.cpp:61
#define SB_DSP_READY
Definition: sndblst.h:19
BOOLEAN StartSoundOutput(PSOUND_BLASTER_PARAMETERS SBDevice, ULONG BitDepth, ULONG Channels, ULONG BlockSize)
Definition: control.c:176
#define SbRead(sbdevice, subport)
Definition: sndblst.h:80
BOOLEAN IsSampleRateCompatible(PSOUND_BLASTER_PARAMETERS SBDevice, ULONG SampleRate)
Definition: control.c:134
#define WaitToWrite(sbdevice)
Definition: sndblst.h:106
unsigned char UCHAR
Definition: xmlstorage.h:181
#define SbReadDataWithoutWait(sbdevice)
Definition: sndblst.h:89
#define SbWrite(sbdevice, subport, data)
Definition: sndblst.h:77
GLenum mode
Definition: glext.h:6217
BOOLEAN DisableSpeaker(PSOUND_BLASTER_PARAMETERS SBDevice)
Definition: control.c:167
BOOLEAN EnableSpeaker(PSOUND_BLASTER_PARAMETERS SBDevice)
Definition: control.c:158
BOOLEAN WaitForReady(PSOUND_BLASTER_PARAMETERS SBDevice, UCHAR Port)
Definition: control.c:12
#define WaitToRead(sbdevice)
Definition: sndblst.h:109
BOOLEAN SbReadData(PSOUND_BLASTER_PARAMETERS SBDevice, PUCHAR Data)
Definition: control.c:45
unsigned int ULONG
Definition: retypes.h:1