ReactOS  0.4.13-dev-563-g0561610
sndblst.h File Reference
#include <debug.h>
#include <ntddk.h>
Include dependency graph for sndblst.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SOUND_BLASTER_PARAMETERS
 

Macros

#define SB_WAVE_IN_DEVICE_NAME   L"\\Device\\SBWaveIn"
 
#define SB_WAVE_OUT_DEVICE_NAME   L"\\Device\\SBWaveOut"
 
#define SB_AUX_DEVICE_NAME   L"\\Device\\SBAux"
 
#define SB_MIXER_DEVICE_NAME   L"\\Device\\SBMixer"
 
#define DEFAULT_PORT   0x220
 
#define DEFAULT_IRQ   5
 
#define DEFAULT_DMA   1
 
#define DEFAULT_BUFFER_SIZE   65535
 
#define SB_TIMEOUT   1000000
 
#define SB_DSP_READY   0xaa
 
#define SbWrite(sbdevice, subport, data)   WRITE_PORT_UCHAR((PUCHAR) sbdevice->port + subport, data)
 
#define SbRead(sbdevice, subport)   READ_PORT_UCHAR((PUCHAR) sbdevice->port + subport)
 
#define SbWriteReset(sbdevice, data)   SbWrite(sbdevice, SB_RESET_PORT, data)
 
#define SbWriteDataWithoutWait(sbdevice, data)   SbWrite(sbdevice, SB_WRITE_DATA_PORT, data)
 
#define SbReadDataWithoutWait(sbdevice)   SbRead(sbdevice, SB_READ_DATA_PORT)
 
#define SbGetWriteStatus(sbdevice)   SbRead(sbdevice, SB_WRITE_STATUS_PORT)
 
#define SbGetReadStatus(sbdevice)   SbRead(sbdevice, SB_READ_STATUS_PORT)
 
#define WaitToWrite(sbdevice)   WaitForReady(sbdevice, SB_WRITE_STATUS_PORT)
 
#define WaitToRead(sbdevice)   WaitForReady(sbdevice, SB_READ_STATUS_PORT)
 

Typedefs

typedef struct _SOUND_BLASTER_PARAMETERS SOUND_BLASTER_PARAMETERS
 
typedef struct _SOUND_BLASTER_PARAMETERSPSOUND_BLASTER_PARAMETERS
 
typedef NTAPI NTSTATUS REGISTRY_CALLBACK_ROUTINE(PDRIVER_OBJECT DriverObject, PWSTR RegistryPath)
 
typedef REGISTRY_CALLBACK_ROUTINEPREGISTRY_CALLBACK_ROUTINE
 

Enumerations

enum  {
  NotDetected, SoundBlaster, SoundBlasterPro, SoundBlaster2,
  SoundBlasterPro2, SoundBlasterProMCV, SoundBlaster16
}
 
enum  {
  SB_RESET_PORT = 0x06, SB_READ_DATA_PORT = 0x0a, SB_WRITE_DATA_PORT = 0x0c, SB_WRITE_STATUS_PORT = 0x0c,
  SB_READ_STATUS_PORT = 0x0e
}
 
enum  {
  SbAutoInitDmaOutput = 0x1c, SbAutoInitDmaInput = 0x2c, SbSetOutputRate = 0x41, SbSetInputRate = 0x42,
  SbSetBlockSize = 0x48, SbPauseDac = 0x80, SbPauseDmaOutput = 0xd0, SbEnableSpeaker = 0xd1,
  SbDisableSpeaker = 0xd3, SbGetSpeakerStatus = 0xd8, SbGetDspVersion = 0xe1
}
 

Functions

BOOLEAN WaitForReady (PSOUND_BLASTER_PARAMETERS SBDevice, UCHAR Port)
 
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)
 
NTSTATUS EnableIrq (PDEVICE_OBJECT DeviceObject)
 

Macro Definition Documentation

◆ DEFAULT_BUFFER_SIZE

#define DEFAULT_BUFFER_SIZE   65535

Definition at line 15 of file sndblst.h.

◆ DEFAULT_DMA

#define DEFAULT_DMA   1

Definition at line 14 of file sndblst.h.

◆ DEFAULT_IRQ

#define DEFAULT_IRQ   5

Definition at line 13 of file sndblst.h.

◆ DEFAULT_PORT

#define DEFAULT_PORT   0x220

Definition at line 12 of file sndblst.h.

◆ SB_AUX_DEVICE_NAME

#define SB_AUX_DEVICE_NAME   L"\\Device\\SBAux"

Definition at line 9 of file sndblst.h.

◆ SB_DSP_READY

#define SB_DSP_READY   0xaa

Definition at line 19 of file sndblst.h.

◆ SB_MIXER_DEVICE_NAME

#define SB_MIXER_DEVICE_NAME   L"\\Device\\SBMixer"

Definition at line 10 of file sndblst.h.

◆ SB_TIMEOUT

#define SB_TIMEOUT   1000000

Definition at line 17 of file sndblst.h.

◆ SB_WAVE_IN_DEVICE_NAME

#define SB_WAVE_IN_DEVICE_NAME   L"\\Device\\SBWaveIn"

Definition at line 6 of file sndblst.h.

◆ SB_WAVE_OUT_DEVICE_NAME

#define SB_WAVE_OUT_DEVICE_NAME   L"\\Device\\SBWaveOut"

Definition at line 7 of file sndblst.h.

◆ SbGetReadStatus

#define SbGetReadStatus (   sbdevice)    SbRead(sbdevice, SB_READ_STATUS_PORT)

Definition at line 96 of file sndblst.h.

◆ SbGetWriteStatus

#define SbGetWriteStatus (   sbdevice)    SbRead(sbdevice, SB_WRITE_STATUS_PORT)

Definition at line 93 of file sndblst.h.

◆ SbRead

#define SbRead (   sbdevice,
  subport 
)    READ_PORT_UCHAR((PUCHAR) sbdevice->port + subport)

Definition at line 80 of file sndblst.h.

◆ SbReadDataWithoutWait

#define SbReadDataWithoutWait (   sbdevice)    SbRead(sbdevice, SB_READ_DATA_PORT)

Definition at line 89 of file sndblst.h.

◆ SbWrite

#define SbWrite (   sbdevice,
  subport,
  data 
)    WRITE_PORT_UCHAR((PUCHAR) sbdevice->port + subport, data)

Definition at line 77 of file sndblst.h.

◆ SbWriteDataWithoutWait

#define SbWriteDataWithoutWait (   sbdevice,
  data 
)    SbWrite(sbdevice, SB_WRITE_DATA_PORT, data)

Definition at line 86 of file sndblst.h.

◆ SbWriteReset

#define SbWriteReset (   sbdevice,
  data 
)    SbWrite(sbdevice, SB_RESET_PORT, data)

Definition at line 83 of file sndblst.h.

◆ WaitToRead

#define WaitToRead (   sbdevice)    WaitForReady(sbdevice, SB_READ_STATUS_PORT)

Definition at line 109 of file sndblst.h.

◆ WaitToWrite

#define WaitToWrite (   sbdevice)    WaitForReady(sbdevice, SB_WRITE_STATUS_PORT)

Definition at line 106 of file sndblst.h.

Typedef Documentation

◆ PREGISTRY_CALLBACK_ROUTINE

Definition at line 70 of file sndblst.h.

◆ PSOUND_BLASTER_PARAMETERS

◆ REGISTRY_CALLBACK_ROUTINE

typedef NTAPI NTSTATUS REGISTRY_CALLBACK_ROUTINE(PDRIVER_OBJECT DriverObject, PWSTR RegistryPath)

Definition at line 69 of file sndblst.h.

◆ SOUND_BLASTER_PARAMETERS

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
NotDetected 
SoundBlaster 
SoundBlasterPro 
SoundBlaster2 
SoundBlasterPro2 
SoundBlasterProMCV 
SoundBlaster16 

Definition at line 21 of file sndblst.h.

◆ anonymous enum

anonymous enum
Enumerator
SB_RESET_PORT 
SB_READ_DATA_PORT 
SB_WRITE_DATA_PORT 
SB_WRITE_STATUS_PORT 
SB_READ_STATUS_PORT 

Definition at line 32 of file sndblst.h.

◆ anonymous enum

anonymous enum
Enumerator
SbAutoInitDmaOutput 
SbAutoInitDmaInput 
SbSetOutputRate 
SbSetInputRate 
SbSetBlockSize 
SbPauseDac 
SbPauseDmaOutput 
SbEnableSpeaker 
SbDisableSpeaker 
SbGetSpeakerStatus 
SbGetDspVersion 

Definition at line 41 of file sndblst.h.

42 {
43  SbAutoInitDmaOutput = 0x1c,
44  SbAutoInitDmaInput = 0x2c,
45  SbSetOutputRate = 0x41, /* DSP v4.xx */
46  SbSetInputRate = 0x42, /* DSP v4.xx */
47  SbSetBlockSize = 0x48, /* DSP v2.00 + */
48  SbPauseDac = 0x80,
49  SbPauseDmaOutput = 0xd0,
50  SbEnableSpeaker = 0xd1,
51  SbDisableSpeaker = 0xd3,
52  SbGetSpeakerStatus = 0xd8, /* DSP v2.00 + */
53  SbGetDspVersion = 0xe1
54 };

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
void DPRINT(...)
Definition: polytest.cpp:61

◆ EnableIrq()

NTSTATUS EnableIrq ( PDEVICE_OBJECT  DeviceObject)

Definition at line 27 of file interrupt.c.

29 {
31  ULONG vector;
32  KIRQL irq_level;
35 
37  0,
38  parameters->irq,
39  parameters->irq,
40  &irq_level,
41  &affinity);
42 
43  DPRINT("Vector is 0x%x\n", vector);
44 
45  status = IoConnectInterrupt(&parameters->interrupt,
48  (PKSPIN_LOCK) NULL,
49  vector,
50  irq_level,
51  irq_level,
52  Latched, /* Latched / LevelSensitive */
53  FALSE, /* shareable */
54  affinity,
55  FALSE);
56 
59 
60  return status;
61 }
KAFFINITY affinity
Definition: wave.h:2
NTHALAPI ULONG NTAPI HalGetInterruptVector(INTERFACE_TYPE, ULONG, ULONG, ULONG, PKIRQL, PKAFFINITY)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
UCHAR KIRQL
Definition: env_spec_w32.h:591
BOOLEAN NTAPI ServiceSoundBlasterInterrupt(IN PKINTERRUPT Interrupt, IN PVOID Context)
Definition: interrupt.c:18
NTSTATUS NTAPI IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, IN PKSERVICE_ROUTINE ServiceRoutine, IN PVOID ServiceContext, IN PKSPIN_LOCK SpinLock, IN ULONG Vector, IN KIRQL Irql, IN KIRQL SynchronizeIrql, IN KINTERRUPT_MODE InterruptMode, IN BOOLEAN ShareVector, IN KAFFINITY ProcessorEnableMask, IN BOOLEAN FloatingSave)
Definition: irq.c:22
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PKINTERRUPT interrupt
Definition: sndblst.h:60
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
ULONG_PTR KAFFINITY
Definition: compat.h:75
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_DEVICE_CONFIGURATION_ERROR
Definition: ntstatus.h:605
return STATUS_SUCCESS
Definition: btrfs.c:2777
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ 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 }
BOOLEAN SbWriteData(PSOUND_BLASTER_PARAMETERS SBDevice, UCHAR Data)
Definition: control.c:31
void DPRINT(...)
Definition: polytest.cpp:61

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 SbWriteData(PSOUND_BLASTER_PARAMETERS SBDevice, UCHAR Data)
Definition: control.c:31
void DPRINT(...)
Definition: polytest.cpp:61
unsigned char UCHAR
Definition: xmlstorage.h:181
#define WaitToRead(sbdevice)
Definition: sndblst.h:109
BOOLEAN SbReadData(PSOUND_BLASTER_PARAMETERS SBDevice, PUCHAR Data)
Definition: control.c:45

◆ 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;
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 }
#define TRUE
Definition: types.h:120
#define SbWriteReset(sbdevice, data)
Definition: sndblst.h:83
Definition: dhcpd.h:245
GLbitfield GLuint64 timeout
Definition: glext.h:7164
unsigned char BOOLEAN
#define SB_TIMEOUT
Definition: sndblst.h:17
void DPRINT(...)
Definition: polytest.cpp:61
#define SB_DSP_READY
Definition: sndblst.h:19
#define SbReadDataWithoutWait(sbdevice)
Definition: sndblst.h:89
#define WaitToRead(sbdevice)
Definition: sndblst.h:109
unsigned int ULONG
Definition: retypes.h:1

Referenced by InitializeSoundBlaster().

◆ 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 }
BOOLEAN SbWriteData(PSOUND_BLASTER_PARAMETERS SBDevice, UCHAR Data)
Definition: control.c:31
#define TRUE
Definition: types.h:120
void DPRINT(...)
Definition: polytest.cpp:61

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 }
BOOLEAN SbWriteData(PSOUND_BLASTER_PARAMETERS SBDevice, UCHAR Data)
Definition: control.c:31
#define TRUE
Definition: types.h:120
void DPRINT(...)
Definition: polytest.cpp:61
unsigned char UCHAR
Definition: xmlstorage.h:181
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 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
Definition: dhcpd.h:245
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SB_TIMEOUT
Definition: sndblst.h:17
#define SbRead(sbdevice, subport)
Definition: sndblst.h:80
unsigned int ULONG
Definition: retypes.h:1