ReactOS  0.4.13-dev-73-gcfe54aa
sndblst.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Sound System
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: dll/win32/sndblst/sndblst.c
5  *
6  * PURPOSE: Sound Blaster MME User-Mode Driver
7  *
8  * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
9  *
10  * NOTES: Currently very experimental and being used as a guinea-pig for
11  * changes to the MME-Buddy libraries.
12  * TODO: Adhere to maximum device name length!
13 */
14 
15 #define WIN32_NO_STATUS
16 #define _INC_WINDOWS
17 #define COM_NO_WINDOWS_H
18 
19 #include <stdarg.h>
20 
21 #include <windef.h>
22 #include <winuser.h>
23 
24 //#include <ntddsnd.h>
25 #include <sndtypes.h>
26 #include <mmddk.h>
27 #include <mmebuddy.h>
28 #include <mment4.h>
29 #include <mmebuddy_debug.h>
30 //#include <debug.h>
31 
32 /* TODO: Give individual device names if someone has > 1 card */
33 PWSTR SBWaveOutDeviceName = L"ROS Sound Blaster Wave Out";
34 PWSTR SBWaveInDeviceName = L"ROS Sound Blaster Wave In";
35 PWSTR SBMidiOutDeviceName = L"ROS Sound Blaster Midi Out";
36 PWSTR SBMidiInDeviceName = L"ROS Sound Blaster Midi In";
37 PWSTR SBAuxDeviceName = L"ROS Sound Blaster Aux";
38 PWSTR SBMixerDeviceName = L"ROS Sound Blaster Mixer";
39 /* TODO: Mixer etc */
40 
43  IN PSOUND_DEVICE SoundDevice,
44  IN DWORD DeviceId,
46  IN DWORD CapabilitiesSize)
47 {
50 
51  SND_ASSERT( SoundDevice );
53 
54  SND_TRACE(L"Sndblst - GetSoundBlasterDeviceCapabilities\n");
55 
56  Result = GetSoundDeviceType(SoundDevice, &DeviceType);
58 
59  /* Use the default method of obtaining device capabilities */
62  CapabilitiesSize);
63 
64  if ( ! MMSUCCESS(Result) )
65  return Result;
66 
67  /* Inject the appropriate device name */
68  switch ( DeviceType )
69  {
71  {
74  break;
75  }
76  case WAVE_IN_DEVICE_TYPE :
77  {
78  LPWAVEINCAPS WaveInCaps = (LPWAVEINCAPS) Capabilities;
80  break;
81  }
83  {
86  break;
87  }
88  case MIDI_IN_DEVICE_TYPE :
89  {
90  LPMIDIINCAPS MidiInCaps = (LPMIDIINCAPS) Capabilities;
92  break;
93  }
94  case AUX_DEVICE_TYPE :
95  {
96  LPAUXCAPS AuxCaps = (LPAUXCAPS) Capabilities;
98  break;
99  }
100  case MIXER_DEVICE_TYPE :
101  {
102  LPMIXERCAPS MixerCaps = (LPMIXERCAPS) Capabilities;
104  break;
105  }
106  }
107 
108  return MMSYSERR_NOERROR;
109 }
110 
113  PWSTR DevicePath)
114 {
116  PSOUND_DEVICE SoundDevice = NULL;
117  MMFUNCTION_TABLE FuncTable;
118  PWSTR PathCopy;
119 
120  SND_TRACE(L"(Callback) Found device: %wS\n", DevicePath);
121 
122  PathCopy = AllocateWideString(wcslen(DevicePath));
123 
124  if ( ! PathCopy )
125  return FALSE;
126 
127  CopyWideString(PathCopy, DevicePath);
128 
129  Result = ListSoundDevice(DeviceType, (PVOID) PathCopy, &SoundDevice);
130 
131  if ( ! MMSUCCESS(Result) )
132  return FALSE;
133 
134  /* Set up our function table */
135  ZeroMemory(&FuncTable, sizeof(MMFUNCTION_TABLE));
139  FuncTable.Open = OpenNt4SoundDevice;
140  FuncTable.Close = CloseNt4SoundDevice;
142  //FuncTable.SubmitWaveHeaderToDevice = SubmitWaveHeaderToDevice;
143 
144  SetSoundDeviceFunctionTable(SoundDevice, &FuncTable);
145 
146  return TRUE;
147 }
148 
151  DWORD DriverId,
152  HANDLE DriverHandle,
153  UINT Message,
154  LONG Parameter1,
155  LONG Parameter2)
156 {
158 
159  switch ( Message )
160  {
161  case DRV_LOAD :
162  {
163  SND_TRACE(L"DRV_LOAD\n");
164 
166 
167  if ( ! MMSUCCESS(Result) )
168  return 0L;
169 
171  0,
172  FoundDevice);
173 
174  if ( ! MMSUCCESS(Result) )
175  {
177 
179 
180  return 0L;
181  }
182 
183 /*
184  PSOUND_DEVICE snd;
185  GetSoundDevice(WAVE_OUT_DEVICE_TYPE, 0, &snd);
186  GetSoundDevice(AUX_DEVICE_TYPE, 0, &snd);
187  GetSoundDevice(AUX_DEVICE_TYPE, 1, &snd);
188  GetSoundDevice(AUX_DEVICE_TYPE, 2, &snd);
189 */
190 
191  SND_TRACE(L"Initialisation complete\n");
192 
193  return 1L;
194  }
195 
196  case DRV_FREE :
197  {
198  SND_TRACE(L"DRV_FREE\n");
199 
200  /* TODO: Clean up the path names! */
202 
204 
205  SND_TRACE(L"Unfreed memory blocks: %d\n",
207 
208  return 1L;
209  }
210 
211  case DRV_ENABLE :
212  case DRV_DISABLE :
213  {
214  SND_TRACE(L"DRV_ENABLE / DRV_DISABLE\n");
215  return 1L;
216  }
217 
218  case DRV_OPEN :
219  case DRV_CLOSE :
220  {
221  SND_TRACE(L"DRV_OPEN / DRV_CLOSE\n");
222  return 1L;
223  }
224 
225  case DRV_QUERYCONFIGURE :
226  {
227  SND_TRACE(L"DRV_QUERYCONFIGURE");
228  return 0L;
229  }
230  case DRV_CONFIGURE :
231  return DRVCNF_OK;
232 
233  default :
234  SND_TRACE(L"Unhandled message %d\n", Message);
235  return DefDriverProc(DriverId,
236  DriverHandle,
237  Message,
238  Parameter1,
239  Parameter2);
240  }
241 }
242 
244  HINSTANCE hinstDLL,
245  DWORD fdwReason,
247 {
248  switch ( fdwReason )
249  {
250  case DLL_PROCESS_ATTACH :
251  SND_TRACE(L"DLL_PROCESS_ATTACH\n");
252  break;
253  case DLL_PROCESS_DETACH :
254  SND_TRACE(L"DLL_PROCESS_DETACH\n");
255  break;
256  case DLL_THREAD_ATTACH :
257  SND_TRACE(L"DLL_THREAD_ATTACH\n");
258  break;
259  case DLL_THREAD_DETACH :
260  SND_TRACE(L"DLL_THREAD_DETACH\n");
261  break;
262  }
263 
264  return TRUE;
265 }
MIDIINCAPSA * LPMIDIINCAPS
Definition: mmsystem.h:2811
#define DRV_DISABLE
Definition: mmsystem.h:123
MMRESULT QueryNt4WaveDeviceFormatSupport(IN PSOUND_DEVICE SoundDevice, IN LPWAVEFORMATEX Format, IN DWORD FormatSize)
Definition: control.c:154
MMRESULT SetNt4WaveDeviceFormat(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN DWORD DeviceId, IN LPWAVEFORMATEX Format, IN DWORD FormatSize)
Definition: control.c:199
#define IN
Definition: typedefs.h:38
MMRESULT ListSoundDevice(IN MMDEVICE_TYPE DeviceType, IN PVOID Identifier OPTIONAL, OUT PSOUND_DEVICE *SoundDevice OPTIONAL)
Definition: devicelist.c:131
#define TRUE
Definition: types.h:120
CHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1217
MMRESULT SetSoundDeviceFunctionTable(IN PSOUND_DEVICE SoundDevice, IN PMMFUNCTION_TABLE FunctionTable)
Definition: functiontable.c:21
CHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1050
#define MMSUCCESS(result)
Definition: mmebuddy.h:80
#define DLL_THREAD_ATTACH
Definition: compat.h:121
uint16_t * PWSTR
Definition: typedefs.h:54
DeviceType
Definition: mmdrv.h:41
MMRESULT OpenNt4SoundDevice(IN PSOUND_DEVICE SoundDevice, OUT PVOID *Handle)
Definition: control.c:52
PWSTR SBMidiInDeviceName
Definition: sndblst.c:36
MMRESULT WriteFileEx_Committer(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PVOID OffsetPtr, IN DWORD Length, IN PSOUND_OVERLAPPED Overlap, IN LPOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine)
Definition: streaming.c:238
BOOLEAN FoundDevice(UCHAR DeviceType, PWSTR DevicePath)
Definition: sndblst.c:111
#define ZeroMemory
Definition: winbase.h:1635
PWSTR SBMixerDeviceName
Definition: sndblst.c:38
UINT MMRESULT
Definition: mmsystem.h:962
#define CopyWideString(dest, source)
Definition: mmebuddy.h:39
#define DRV_CLOSE
Definition: mmsystem.h:122
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
VOID CleanupEntrypointMutexes(VOID)
MIDIOUTCAPSA * LPMIDIOUTCAPS
Definition: mmsystem.h:2810
MMCLOSE_FUNC Close
Definition: mmebuddy.h:206
#define DRVCNF_OK
Definition: mmsystem.h:134
CHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1114
#define DLL_THREAD_DETACH
Definition: compat.h:122
WAVEINCAPSA * LPWAVEINCAPS
Definition: mmsystem.h:2809
static IN DWORD IN LPVOID lpvReserved
WAVE_COMMIT_FUNC CommitWaveBuffer
Definition: mmebuddy.h:213
#define DRV_QUERYCONFIGURE
Definition: mmsystem.h:126
#define DRV_OPEN
Definition: mmsystem.h:121
UCHAR MMDEVICE_TYPE
Definition: mmebuddy.h:88
MMWAVEQUERYFORMATSUPPORT_FUNC QueryWaveFormatSupport
Definition: mmebuddy.h:208
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
LONG APIENTRY DriverProc(DWORD DriverId, HANDLE DriverHandle, UINT Message, LONG Parameter1, LONG Parameter2)
Definition: sndblst.c:150
MMGETCAPS_FUNC GetCapabilities
Definition: mmebuddy.h:198
#define AllocateWideString(string_length)
Definition: mmebuddy.h:33
MIXERCAPSA * LPMIXERCAPS
Definition: mmsystem.h:2813
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define SND_ASSERT(condition)
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
WAVEOUTCAPSA * LPWAVEOUTCAPS
Definition: mmsystem.h:2808
#define DRV_LOAD(x)
#define DLL_PROCESS_DETACH
Definition: compat.h:119
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define DRV_CONFIGURE
Definition: mmsystem.h:125
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DRV_FREE
Definition: mmsystem.h:124
CHAR Message[80]
Definition: alive.c:5
UINT GetMemoryAllocationCount(VOID)
unsigned char UCHAR
Definition: xmlstorage.h:181
PWSTR SBWaveInDeviceName
Definition: sndblst.c:34
static const WCHAR L[]
Definition: oid.c:1250
MMRESULT GetSoundBlasterDeviceCapabilities(IN PSOUND_DEVICE SoundDevice, IN DWORD DeviceId, OUT PVOID Capabilities, IN DWORD CapabilitiesSize)
Definition: sndblst.c:42
VOID UnlistAllSoundDevices(VOID)
#define DRV_ENABLE
Definition: mmsystem.h:120
CHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1138
AUXCAPSA * LPAUXCAPS
Definition: mmsystem.h:2812
PWSTR SBMidiOutDeviceName
Definition: sndblst.c:35
MMRESULT GetSoundDeviceType(IN PSOUND_DEVICE SoundDevice, OUT PMMDEVICE_TYPE DeviceType)
Definition: devicelist.c:346
MMOPEN_FUNC Open
Definition: mmebuddy.h:205
MMRESULT InitEntrypointMutexes(VOID)
unsigned int UINT
Definition: ndis.h:50
MMRESULT EnumerateNt4ServiceSoundDevices(IN LPWSTR ServiceName, IN MMDEVICE_TYPE DeviceType, IN SOUND_DEVICE_DETECTED_PROC SoundDeviceDetectedProc)
Definition: detect.c:26
#define OUT
Definition: typedefs.h:39
LRESULT WINAPI DefDriverProc(DWORD_PTR dwDriverIdentifier, HDRVR hDrv, UINT Msg, LPARAM lParam1, LPARAM lParam2)
Definition: driver.c:554
PWSTR SBWaveOutDeviceName
Definition: sndblst.c:33
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: sndblst.c:243
CHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1028
CHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1192
MMRESULT GetNt4SoundDeviceCapabilities(IN PSOUND_DEVICE SoundDevice, OUT PVOID Capabilities, IN DWORD CapabilitiesSize)
Definition: control.c:80
MMWAVESETFORMAT_FUNC SetWaveFormat
Definition: mmebuddy.h:209
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
MMRESULT CloseNt4SoundDevice(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PVOID Handle)
Definition: control.c:65
#define SND_TRACE(...)
#define APIENTRY
Definition: api.h:79
PWSTR SBAuxDeviceName
Definition: sndblst.c:37