Author: silverblade
Date: Tue Jul 1 11:09:10 2008
New Revision: 34234
URL:
http://svn.reactos.org/svn/reactos?rev=34234&view=rev
Log:
Split sb16_nt4 into a common sound static library and made sb16_nt4
compile against this (intention is to re-use the lib for portcls later on).
Added:
branches/silverblade-audio/include/reactos/libs/sound/
branches/silverblade-audio/include/reactos/libs/sound/devname.h (with props)
branches/silverblade-audio/include/reactos/libs/sound/midi.h (with props)
branches/silverblade-audio/include/reactos/libs/sound/midiuart.h (with props)
branches/silverblade-audio/include/reactos/libs/sound/time.h (with props)
branches/silverblade-audio/lib/drivers/sound/
branches/silverblade-audio/lib/drivers/sound/devname.c
- copied unchanged from r34233,
branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/devname.c
branches/silverblade-audio/lib/drivers/sound/hardware.c (with props)
branches/silverblade-audio/lib/drivers/sound/midiuart.c (with props)
branches/silverblade-audio/lib/drivers/sound/sbdsp.c (with props)
branches/silverblade-audio/lib/drivers/sound/sound.rbuild (with props)
branches/silverblade-audio/lib/drivers/sound/time.c (with props)
Removed:
branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/devname.c
Modified:
branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/main.c
branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/sb16_nt4.rbuild
branches/silverblade-audio/lib/drivers/directory.rbuild
Removed: branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/devname.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/drivers/multi…
==============================================================================
--- branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/devname.c [iso-8859-1]
(original)
+++ branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/devname.c (removed)
@@ -1,384 +1,0 @@
-/*
- ReactOS Sound System
- Device naming & creation helper routines
-
- Author:
- Andrew Greenwood (andrew.greenwood(a)silverblade.co.uk)
-
- History:
- 25 May 2008 - Created
-*/
-
-#include <ntddk.h>
-#include <ntddsnd.h>
-#include <debug.h>
-
-/*
- Default device names
-
- Just to keep things tidy, we define a structure to hold both the \\Device
- and \\DosDevices names, and then fill this structure with the default
- device names that can be found in NTDDSND.H
-*/
-
-typedef struct _DEVICE_NAME_GROUP
-{
- PCWSTR DeviceName;
- PCWSTR DosDeviceName;
-} DEVICE_NAME_GROUP;
-
-DEVICE_NAME_GROUP SoundDeviceNameBodies[6] =
-{
- {
- DD_WAVE_IN_DEVICE_NAME_U,
- DD_WAVE_IN_DOS_DEVICE_NAME_U
- },
- {
- DD_WAVE_OUT_DEVICE_NAME_U,
- DD_WAVE_OUT_DOS_DEVICE_NAME_U
- },
- {
- DD_MIDI_IN_DEVICE_NAME_U,
- DD_MIDI_IN_DOS_DEVICE_NAME_U
- },
- {
- DD_MIDI_OUT_DEVICE_NAME_U,
- DD_MIDI_OUT_DOS_DEVICE_NAME_U
- },
- {
- DD_MIX_DEVICE_NAME_U,
- DD_MIX_DOS_DEVICE_NAME_U
- },
- {
- DD_AUX_DEVICE_NAME_U,
- DD_AUX_DOS_DEVICE_NAME_U
- }
-};
-
-
-/*
- ConstructDeviceName
-
- This takes a wide-character string containing the device name body (for
- example, "\\Device\\WaveOut") and appends the device index, forming a
- string like "\\Device\\WaveOut0", and so on.
-
- The resulting device name is a unicode string.
-*/
-
-NTSTATUS
-ConstructDeviceName(
- IN PCWSTR Path,
- IN UCHAR Index,
- OUT PUNICODE_STRING DeviceName)
-{
- UNICODE_STRING UnicodePath;
- UNICODE_STRING UnicodeIndex;
- WCHAR IndexStringBuffer[5];
- USHORT Size;
- USHORT LastCharacterIndex;
-
- /* Check for NULL parameters */
- if ( ( ! Path ) || ( ! DeviceName ) )
- {
- ERR_(IHVAUDIO, "Unexpected NULL parameter");
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Range-check */
- if ( Index >= SOUND_MAX_DEVICES )
- {
- ERR_(IHVAUDIO, "Device index %d out of range", Index);
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Initialise the unicode path string */
- RtlInitUnicodeString(&UnicodePath, Path);
-
- /* Calculate the length to hold the full string */
- Size = UnicodePath.Length +
- sizeof(IndexStringBuffer) +
- sizeof(UNICODE_NULL);
-
- /* Allocate memory for DeviceName */
- DeviceName->Buffer = ExAllocatePool(PagedPool, Size);
- DeviceName->MaximumLength = Size;
-
- if ( ! DeviceName->Buffer )
- {
- ERR_(IHVAUDIO, "Couldn't allocate memory for device name string");
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- /* Copy the path */
- RtlCopyUnicodeString(DeviceName, &UnicodePath);
-
- /* Convert Index to string and append */
- UnicodeIndex.Buffer = IndexStringBuffer;
- UnicodeIndex.MaximumLength = sizeof(IndexStringBuffer);
-
- RtlIntegerToUnicodeString((ULONG)Index, 10, &UnicodeIndex);
- RtlAppendUnicodeStringToString(DeviceName, &UnicodeIndex);
-
- /* Terminate the string */
- LastCharacterIndex = DeviceName->Length / sizeof(UNICODE_NULL);
- DeviceName->Buffer[LastCharacterIndex] = UNICODE_NULL;
-
- return STATUS_SUCCESS;
-}
-
-
-/*
- FreeUnicodeStringBuffer
-
- A small helper routine to free a unicode string buffer, nullify the
- buffer and reset the lengths to zero.
-*/
-
-VOID
-FreeUnicodeStringBuffer(IN PUNICODE_STRING String)
-{
- ASSERT(String != NULL);
- ASSERT(String->Buffer != NULL);
-
- ExFreePool(String->Buffer);
-
- String->Buffer = NULL;
- String->Length = 0;
- String->MaximumLength = 0;
-}
-
-
-/*
- GetDefaultSoundDeviceNameBodies
-
- Simply accesses the SoundDeviceNameBodies struct defined earlier and
- fills the DeviceNameBody and DosDeviceNameBody parameters accordingly.
-
- Basically a "safe" way to access the array and perform two assignments
- with one call, as this will assign the name and DOS name if a valid
- DeviceType is passed, otherwise it will fail with STATUS_INVALID_PARAMETER.
-*/
-
-NTSTATUS
-GetDefaultSoundDeviceNameBodies(
- IN UCHAR DeviceType,
- OUT PCWSTR* DeviceNameBody,
- OUT PCWSTR* DosDeviceNameBody)
-{
- ASSERT(DeviceNameBody != NULL);
- ASSERT(DosDeviceNameBody != NULL);
-
- if ( DeviceType > MAX_DEVICE_TYPE )
- {
- ERR_(IHVAUDIO, "Invalid device type");
- return STATUS_INVALID_PARAMETER;
- }
-
- *DeviceNameBody = SoundDeviceNameBodies[DeviceType].DeviceName;
- *DosDeviceNameBody = SoundDeviceNameBodies[DeviceType].DosDeviceName;
-
- return STATUS_SUCCESS;
-}
-
-
-/*
- ConstructSoundDeviceNames
-
- Given two wide-character strings and a device index, convert these into
- two unicode strings with the index appended to the end.
-
- This is intended for converting a device name and a DOS device name at
- the same time.
-*/
-
-NTSTATUS
-ConstructSoundDeviceNames(
- IN PCWSTR DeviceNameBody,
- IN PCWSTR DosDeviceNameBody,
- IN UCHAR Index,
- OUT PUNICODE_STRING FullDeviceName,
- OUT PUNICODE_STRING FullDosDeviceName)
-{
- NTSTATUS Status;
-
- /* Check for NULL parameters */
- if ( ( ! DeviceNameBody ) || ( ! DosDeviceNameBody ) ||
- ( ! FullDeviceName ) || ( ! FullDosDeviceName ) )
- {
- ERR_(IHVAUDIO, "Unexpected NULL parameter");
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Range-check */
- if ( Index >= SOUND_MAX_DEVICES )
- {
- ERR_(IHVAUDIO, "Device %d exceeds maximum", Index);
- return STATUS_INVALID_PARAMETER;
- }
-
- Status = ConstructDeviceName(DeviceNameBody, Index, FullDeviceName);
-
- if ( ! NT_SUCCESS(Status) )
- {
- /* No need to clean up on failure here */
- return Status;
- }
-
- Status = ConstructDeviceName(DosDeviceNameBody, Index, FullDosDeviceName);
-
- if ( ! NT_SUCCESS(Status) )
- {
- /* We need to free the string we successfully got earlier */
- FreeUnicodeStringBuffer(FullDeviceName);
- return Status;
- }
-
- return STATUS_SUCCESS;
-}
-
-
-/*
- CreateSoundDevice
-
- Creates a device and symbolically-links a DOS device to this. Use this
- when you want to specify alternative device names to the defaults
- (eg: "\\Device\\MySoundDev" rather than "\\Device\\WaveOut")
-*/
-
-NTSTATUS
-CreateSoundDevice(
- IN PDRIVER_OBJECT DriverObject,
- IN PCWSTR WideDeviceName,
- IN PCWSTR WideDosDeviceName,
- IN UCHAR Index,
- IN ULONG ExtensionSize,
- OUT PDEVICE_OBJECT DeviceObject)
-{
- NTSTATUS Status;
-
- UNICODE_STRING DeviceName;
- UNICODE_STRING DosDeviceName;
-
- /* Check for NULL parameters */
- if ( ( ! DriverObject ) || ( ! DeviceObject ) ||
- ( ! WideDeviceName ) || ( ! WideDosDeviceName ) )
- {
- ERR_(IHVAUDIO, "Unexpected NULL parameter");
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Range-check */
- if ( Index >= SOUND_MAX_DEVICES )
- {
- ERR_(IHVAUDIO, "Device index %d exceeds maximum", Index);
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Construct the device and DOS device names */
- Status = ConstructSoundDeviceNames(WideDeviceName,
- WideDosDeviceName,
- Index,
- &DeviceName,
- &DosDeviceName);
-
- if ( ! NT_SUCCESS(Status) )
- {
- return Status;
- }
-
- /* Now create the device */
- Status = IoCreateDevice(DriverObject,
- ExtensionSize,
- &DeviceName,
- FILE_DEVICE_SOUND,
- 0,
- FALSE,
- &DeviceObject);
-
- if ( ! NT_SUCCESS(Status) )
- {
- /* These will have been allocated by ConstructSoundDeviceNames */
- FreeUnicodeStringBuffer(&DeviceName);
- FreeUnicodeStringBuffer(&DosDeviceName);
-
- return Status;
- }
-
- /* Create a symbolic link for the DOS deviec name */
- Status = IoCreateSymbolicLink(&DosDeviceName, &DeviceName);
-
- if ( ! NT_SUCCESS(Status) )
- {
- /* IoDeleteDevice( --- What are we deleting? */
-
- /* These will have been allocated by ConstructSoundDeviceNames */
- FreeUnicodeStringBuffer(&DeviceName);
- FreeUnicodeStringBuffer(&DosDeviceName);
-
- return Status;
- }
-
- return STATUS_SUCCESS;
-}
-
-
-/*
- CreateSoundDeviceWithDefaultName
-
- Similar to CreateSoundDevice, except this uses the default device names
- ("\\Device\\WaveOut" etc.) based on the DeviceType parameter.
-*/
-
-NTSTATUS
-CreateSoundDeviceWithDefaultName(
- IN PDRIVER_OBJECT DriverObject,
- IN UCHAR DeviceType,
- IN UCHAR Index,
- IN ULONG ExtensionSize,
- OUT PDEVICE_OBJECT DeviceObject)
-{
- NTSTATUS Status;
- PCWSTR WideDeviceName = NULL;
- PCWSTR WideDosDeviceName = NULL;
-
- /* Check for NULL parameters */
- if ( ( ! DriverObject ) || ( ! DeviceObject ) )
- {
- ERR_(IHVAUDIO, "Unexpected NULL parameter");
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Range-check */
- if ( Index >= SOUND_MAX_DEVICES )
- {
- ERR_(IHVAUDIO, "Device index %d exceeds maximum", Index);
- return STATUS_INVALID_PARAMETER;
- }
-
- /* Look-up the default name based on the device type */
- Status = GetDefaultSoundDeviceNameBodies(DeviceType,
- &WideDeviceName,
- &WideDosDeviceName);
-
- if ( ! NT_SUCCESS(Status) )
- {
- return Status;
- }
-
- /* Go create the device! */
- Status = CreateSoundDevice(DriverObject,
- WideDeviceName,
- WideDosDeviceName,
- Index,
- ExtensionSize,
- DeviceObject);
-
- if ( ! NT_SUCCESS(Status) )
- {
- /* No clean-up to do */
- return Status;
- }
-
- return STATUS_SUCCESS;
-}
Modified: branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/main.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/drivers/multi…
==============================================================================
--- branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/main.c [iso-8859-1]
(original)
+++ branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/main.c [iso-8859-1] Tue
Jul 1 11:09:10 2008
@@ -13,6 +13,8 @@
#include <ntddk.h>
#include <ntddsnd.h>
#include <debug.h>
+
+#include <devname.h>
typedef struct _SOUND_BLASTER_EXTENSION
{
@@ -90,6 +92,49 @@
INFO_(IHVAUDIO, "Sound Blaster driver being unloaded");
}
+
+#define SOUND_PARAMETERS_KEYNAME_W L"Parameters"
+#define SOUND_DEVICES_KEYNAME_W L"Devices"
+#define SOUND_DEVICE_KEYNAME_PREFIX_W L"Device"
+
+/* NT4 */
+ULONG
+GetSoundDeviceCount(
+ IN PUNICODE_STRING RegistryPath)
+{
+ NTSTATUS Status;
+ OBJECT_ATTRIBUTES Attributes;
+ HANDLE KeyHandle;
+ ULONG DeviceCount = 0;
+ PCWSTR RegistryPathBuffer;
+ UNICODE_STRING FullRegistryPath;
+ ULONG PathLength;
+
+ //PathLength = RegistryPath.Length +;
+
+ /* TODO */
+ /*RegistryPathBuffer = ExAllocatePoolWithTag(PAGED_POOL,*/
+
+ InitializeObjectAttributes(&Attributes,
+ RegistryPath,
+ OBJ_KERNEL_HANDLE,
+ NULL,
+ NULL);
+
+ Status = ZwOpenKey(&KeyHandle,
+ KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
+ &Attributes);
+
+ if ( ! NT_SUCCESS(Status) )
+ {
+ return 0;
+ }
+
+ //ZwEnumerateKey(Key
+}
+
+
+
NTSTATUS STDCALL
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
@@ -108,6 +153,9 @@
DriverObject->MajorFunction[IRP_MJ_WRITE] = WriteSoundBlaster;
DriverObject->DriverUnload = UnloadSoundBlaster;
+ DEVICE_OBJECT device;
+ CreateSoundDeviceWithDefaultName(DriverObject, 0, 69, 0, &device);
+
return STATUS_SUCCESS;
}
Modified: branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/sb16_nt4.rbuild
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/drivers/multi…
==============================================================================
--- branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/sb16_nt4.rbuild
[iso-8859-1] (original)
+++ branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/sb16_nt4.rbuild
[iso-8859-1] Tue Jul 1 11:09:10 2008
@@ -1,11 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "../../../../tools/rbuild/project.dtd">
<module name="sb16_nt4" type="kernelmodedriver"
installbase="system32/drivers" installname="sndblst.sys"
allowwarnings="true">
+ <linkerflag>-lgcc</linkerflag>
<include base="sb16_nt4">.</include>
<include base="sb16_nt4">..</include>
+ <include base="ReactOS">include/reactos/libs/sound</include>
<importlibrary definition="sb16_nt4.def" />
+ <library>sound</library>
<library>ntoskrnl</library>
<library>hal</library>
- <file>test.c</file>
- <file>devname.c</file>
+ <file>main.c</file>
</module>
Added: branches/silverblade-audio/include/reactos/libs/sound/devname.h
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/include/react…
==============================================================================
--- branches/silverblade-audio/include/reactos/libs/sound/devname.h (added)
+++ branches/silverblade-audio/include/reactos/libs/sound/devname.h [iso-8859-1] Tue Jul
1 11:09:10 2008
@@ -1,0 +1,113 @@
+/*
+ ReactOS Sound System
+ Device naming & creation helper routines
+
+ Author:
+ Andrew Greenwood (andrew.greenwood(a)silverblade.co.uk)
+
+ History:
+ 25 May 2008 - Created
+*/
+
+#ifndef ROS_DEVNAME
+#define ROS_DEVNAME
+
+/*
+ ConstructDeviceName
+
+ This takes a wide-character string containing the device name body (for
+ example, "\\Device\\WaveOut") and appends the device index, forming a
+ string like "\\Device\\WaveOut0", and so on.
+
+ The resulting device name is a unicode string.
+*/
+
+NTSTATUS
+ConstructDeviceName(
+ IN PCWSTR Path,
+ IN UCHAR Index,
+ OUT PUNICODE_STRING DeviceName);
+
+
+/*
+ FreeUnicodeStringBuffer
+
+ A small helper routine to free a unicode string buffer, nullify the
+ buffer and reset the lengths to zero.
+*/
+
+VOID
+FreeUnicodeStringBuffer(IN PUNICODE_STRING String);
+
+
+/*
+ GetDefaultSoundDeviceNameBodies
+
+ Simply accesses the SoundDeviceNameBodies struct defined earlier and
+ fills the DeviceNameBody and DosDeviceNameBody parameters accordingly.
+
+ Basically a "safe" way to access the array and perform two assignments
+ with one call, as this will assign the name and DOS name if a valid
+ DeviceType is passed, otherwise it will fail with STATUS_INVALID_PARAMETER.
+*/
+
+NTSTATUS
+GetDefaultSoundDeviceNameBodies(
+ IN UCHAR DeviceType,
+ OUT PCWSTR* DeviceNameBody,
+ OUT PCWSTR* DosDeviceNameBody);
+
+
+/*
+ ConstructSoundDeviceNames
+
+ Given two wide-character strings and a device index, convert these into
+ two unicode strings with the index appended to the end.
+
+ This is intended for converting a device name and a DOS device name at
+ the same time.
+*/
+
+NTSTATUS
+ConstructSoundDeviceNames(
+ IN PCWSTR DeviceNameBody,
+ IN PCWSTR DosDeviceNameBody,
+ IN UCHAR Index,
+ OUT PUNICODE_STRING FullDeviceName,
+ OUT PUNICODE_STRING FullDosDeviceName);
+
+
+/*
+ CreateSoundDevice
+
+ Creates a device and symbolically-links a DOS device to this. Use this
+ when you want to specify alternative device names to the defaults
+ (eg: "\\Device\\MySoundDev" rather than "\\Device\\WaveOut")
+*/
+
+NTSTATUS
+CreateSoundDevice(
+ IN PDRIVER_OBJECT DriverObject,
+ IN PCWSTR WideDeviceName,
+ IN PCWSTR WideDosDeviceName,
+ IN UCHAR Index,
+ IN ULONG ExtensionSize,
+ OUT PDEVICE_OBJECT DeviceObject);
+
+
+/*
+ CreateSoundDeviceWithDefaultName
+
+ Similar to CreateSoundDevice, except this uses the default device names
+ ("\\Device\\WaveOut" etc.) based on the DeviceType parameter.
+*/
+
+NTSTATUS
+CreateSoundDeviceWithDefaultName(
+ IN PDRIVER_OBJECT DriverObject,
+ IN UCHAR DeviceType,
+ IN UCHAR Index,
+ IN ULONG ExtensionSize,
+ OUT PDEVICE_OBJECT DeviceObject);
+
+#endif
Propchange: branches/silverblade-audio/include/reactos/libs/sound/devname.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/silverblade-audio/include/reactos/libs/sound/midi.h
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/include/react…
==============================================================================
--- branches/silverblade-audio/include/reactos/libs/sound/midi.h (added)
+++ branches/silverblade-audio/include/reactos/libs/sound/midi.h [iso-8859-1] Tue Jul 1
11:09:10 2008
@@ -1,0 +1,39 @@
+/*
+ ReactOS Sound System
+ MIDI constants
+
+ Author:
+ Andrew Greenwood (andrew.greenwood(a)silverblade.co.uk)
+
+ History:
+ 26 May 2008 - Created
+*/
+
+#ifndef ROS_MIDI
+#define ROS_MIDI
+
+/* Channel-based MIDI status bytes */
+#define MIDI_NOTE_OFF 0x80
+#define MIDI_NOTE_ON 0x90
+#define MIDI_KEY_PRESSURE 0xA0
+#define MIDI_CONTROL_CHANGE 0xB0
+#define MIDI_PROGRAM_CHANGE 0xC0
+#define MIDI_CHANNEL_PRESSURE 0xD0
+#define MIDI_PITCH_BEND 0xE0
+
+/* System MIDI status bytes */
+#define MIDI_SYSEX_START 0xF0
+#define MIDI_QUARTER_FRAME 0xF1
+#define MIDI_SONG_POSITION 0xF2
+#define MIDI_SONG_SELECT 0xF3
+#define MIDI_TUNE_REQUEST 0xF6
+#define MIDI_SYSEX_END 0xF7
+#define MIDI_CLOCK 0xF8
+#define MIDI_TICK 0xF9
+#define MIDI_START 0xFA
+#define MIDI_CONTINUE 0xFB
+#define MIDI_STOP 0xFC
+#define MIDI_ACTIVE_SENSE 0xFE
+#define MIDI_RESET 0xFF
+
+#endif
Propchange: branches/silverblade-audio/include/reactos/libs/sound/midi.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/silverblade-audio/include/reactos/libs/sound/midiuart.h
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/include/react…
==============================================================================
--- branches/silverblade-audio/include/reactos/libs/sound/midiuart.h (added)
+++ branches/silverblade-audio/include/reactos/libs/sound/midiuart.h [iso-8859-1] Tue Jul
1 11:09:10 2008
@@ -1,0 +1,111 @@
+/*
+ ReactOS Sound System
+ MIDI UART support
+
+ Author:
+ Andrew Greenwood (andrew.greenwood(a)silverblade.co.uk)
+
+ History:
+ 26 May 2008 - Created
+
+ Notes:
+ MIDI UART is fairly simple. There are two ports - one is a data
+ port and is read/write, the other is a command/status port where
+ you can write commands, and read status.
+
+ We use a subset of the functionality offered by the original MPU-401
+ hardware, which is pretty much the only part implemented in sound
+ cards these days, known as "MIDI UART" mode.
+*/
+
+#ifndef ROS_MIDIUART
+#define ROS_MIDIUART
+
+/* Port read/write abstraction (no wait) */
+#define WRITE_MIDIUART_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp, x)
+#define READ_MIDIUART_DATA(bp) READ_PORT_UCHAR((PUCHAR) bp)
+#define WRITE_MIDIUART_COMMAND(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+1, x)
+#define READ_MIDIUART_STATUS(bp) READ_PORT_UCHAR((PUCHAR) bp+1)
+
+/* Status flags */
+#define MIDIUART_STATUS_DTR 0x40
+#define MIDIUART_STATUS_CTS 0x80
+
+
+/*
+ WaitForMidiUartStatus
+
+ A universal routine for waiting for one or more bits to be set on the
+ MIDI UART command/status port. (Not a particularly efficient wait as
+ this polls the port until it's ready!)
+
+ If the timeout is reached, the function returns FALSE. Otherwise, when
+ the specified flag(s) become set, the function returns TRUE.
+*/
+
+BOOLEAN
+WaitForMidiUartStatus(
+ IN PUCHAR UartBasePort,
+ IN UCHAR StatusFlags,
+ IN ULONG Timeout);
+
+/* Waits for the CTS status bit to be set */
+#define WaitForMidiUartCTS(UartBasePort, Timeout) \
+ WaitForMidiUartStatus(UartBasePort, MIDIUART_STATUS_CTS, Timeout)
+
+/* Waits for the DTR status bit to be set */
+#define WaitForMidiUartDTR(UartBasePort, Timeout) \
+ WaitForMidiUartStatus(UartBasePort, MIDIUART_STATUS_DTR, Timeout)
+
+/*
+ WriteMidiUartByte
+
+ Wait for the CTS bit to be set on the command/status port, before
+ writing to the data port. If CTS does not get set within the timeout
+ period, returns FALSE. Otherwise, returns TRUE.
+*/
+
+BOOLEAN
+WriteMidiUartByte(
+ IN PUCHAR UartBasePort,
+ IN UCHAR Data,
+ IN ULONG Timeout);
+
+
+/*
+ WriteMidiUartMulti
+
+ Write multiple bytes to the MIDI UART data port. The timeout applies on a
+ per-byte basis. If it is reached for any byte, the function will return
+ FALSE.
+
+ All data is written "as-is" - there are no checks made as to the validity
+ of the data.
+*/
+
+BOOLEAN
+WriteMidiUartMulti(
+ IN PUCHAR UartBasePort,
+ IN PUCHAR Data,
+ IN ULONG DataLength,
+ IN ULONG Timeout);
+
+
+/*
+ ReadMidiUartByte
+
+ Wait for the DTR bit to be set on the command/status port, before
+ reading from the data port. If DTR does not get set within the
+ timeout period, returns FALSE. Otherwise, returns TRUE.
+
+ On success, the read data is stored in the location specified by
+ the Data parameter.
+*/
+
+BOOLEAN
+ReadMidiUartByte(
+ IN PUCHAR UartBasePort,
+ OUT UCHAR* Data,
+ IN ULONG Timeout);
+
+#endif
Propchange: branches/silverblade-audio/include/reactos/libs/sound/midiuart.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/silverblade-audio/include/reactos/libs/sound/time.h
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/include/react…
==============================================================================
--- branches/silverblade-audio/include/reactos/libs/sound/time.h (added)
+++ branches/silverblade-audio/include/reactos/libs/sound/time.h [iso-8859-1] Tue Jul 1
11:09:10 2008
@@ -1,0 +1,21 @@
+/*
+ ReactOS Sound System
+ Timing helper
+
+ Author:
+ Andrew Greenwood (andrew.greenwood(a)silverblade.co.uk)
+
+ History:
+ 1 July 2008 - Created
+*/
+
+#ifndef ROS_SOUND_TIME
+#define ROS_SOUND_TIME
+
+VOID
+SleepMs(ULONG Milliseconds);
+
+ULONG
+QuerySystemTimeMs();
+
+#endif
Propchange: branches/silverblade-audio/include/reactos/libs/sound/time.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: branches/silverblade-audio/lib/drivers/directory.rbuild
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/d…
==============================================================================
--- branches/silverblade-audio/lib/drivers/directory.rbuild [iso-8859-1] (original)
+++ branches/silverblade-audio/lib/drivers/directory.rbuild [iso-8859-1] Tue Jul 1
11:09:10 2008
@@ -13,4 +13,7 @@
<directory name="chew">
<xi:include href="chew/chew.rbuild" />
</directory>
+ <directory name="sound">
+ <xi:include href="sound/sound.rbuild" />
+ </directory>
</group>
Added: branches/silverblade-audio/lib/drivers/sound/hardware.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/hardware.c (added)
+++ branches/silverblade-audio/lib/drivers/sound/hardware.c [iso-8859-1] Tue Jul 1
11:09:10 2008
@@ -1,0 +1,66 @@
+/*
+ ReactOS Sound System
+ Hardware interaction helper
+
+ Author:
+ Andrew Greenwood (andrew.greenwood(a)silverblade.co.uk)
+
+ History:
+ 25 May 2008 - Created
+
+ Notes:
+ This uses some obsolete calls (eg: HalGetInterruptVector).
+ Might be worth updating this in future to use some of the
+ recommended functions like IoReportDetectedDevice and
+ IoReportResourceForDetection...
+*/
+
+#include <ntddk.h>
+#include <ntddsnd.h>
+#include <debug.h>
+
+/* NOTE: Disconnect using IoDisconnectInterrupt */
+
+NTSTATUS
+LegacyAttachInterrupt(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN UCHAR Irq,
+ IN PKSERVICE_ROUTINE ServiceRoutine,
+ OUT PKINTERRUPT* InterruptObject)
+{
+ NTSTATUS Status;
+ ULONG Vector;
+ KIRQL IrqLevel;
+ KAFFINITY Affinity;
+
+ INFO_(IHVAUDIO, "Obtaining interrupt vector");
+
+ Vector = HalGetInterruptVector(Isa,
+ 0,
+ Irq,
+ Irq,
+ &IrqLevel,
+ &Affinity);
+
+ INFO_(IHVAUDIO, "Vector %d", Vector);
+ INFO_(IHVAUDIO, "Connecting IRQ %d", Irq);
+
+ Status = IoConnectInterrupt(InterruptObject,
+ ServiceRoutine,
+ DeviceObject,
+ NULL,
+ Vector,
+ IrqLevel,
+ IrqLevel,
+ Latched,
+ FALSE,
+ Affinity,
+ FALSE);
+
+ if ( Status == STATUS_INVALID_PARAMETER )
+ {
+ Status = STATUS_DEVICE_CONFIGURATION_ERROR;
+ }
+
+ return Status;
+}
Propchange: branches/silverblade-audio/lib/drivers/sound/hardware.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/silverblade-audio/lib/drivers/sound/midiuart.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/midiuart.c (added)
+++ branches/silverblade-audio/lib/drivers/sound/midiuart.c [iso-8859-1] Tue Jul 1
11:09:10 2008
@@ -1,0 +1,172 @@
+/*
+ ReactOS Sound System
+ MIDI UART support
+
+ Author:
+ Andrew Greenwood (andrew.greenwood(a)silverblade.co.uk)
+
+ History:
+ 26 May 2008 - Created
+
+ Notes:
+ Functions documented in midiuart.h
+*/
+
+#include <ntddk.h>
+#include "midiuart.h"
+
+BOOLEAN
+WaitForMidiUartStatus(
+ IN PUCHAR UartBasePort,
+ IN UCHAR StatusFlags,
+ IN ULONG Timeout)
+{
+ ULONG RemainingTime = Timeout;
+
+ while ( RemainingTime -- )
+ {
+ if ( READ_MIDIUART_STATUS(UartBasePort) & StatusFlags )
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+BOOLEAN
+WriteMidiUartByte(
+ IN PUCHAR UartBasePort,
+ IN UCHAR Data,
+ IN ULONG Timeout)
+{
+ if ( ! WaitForMidiUartCTS(UartBasePort, Timeout) )
+ {
+ return FALSE;
+ }
+
+ WRITE_MIDIUART_DATA(UartBasePort, Data);
+
+ return TRUE;
+}
+
+BOOLEAN
+WriteMidiUartMulti(
+ IN PUCHAR UartBasePort,
+ IN PUCHAR Data,
+ IN ULONG DataLength,
+ IN ULONG Timeout)
+{
+ ULONG DataIndex;
+
+ for ( DataIndex = 0; DataIndex < DataLength; ++ DataIndex )
+ {
+ if ( ! WriteMidiUartByte(UartBasePort, Data[DataIndex], Timeout) )
+ {
+ /* We failed - don't try writing any more */
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+BOOLEAN
+ReadMidiUartByte(
+ IN PUCHAR UartBasePort,
+ OUT UCHAR* Data,
+ IN ULONG Timeout)
+{
+ if ( ! Data )
+ {
+ return FALSE;
+ }
+
+ if ( ! WaitForMidiUartDTR(UartBasePort, Timeout) )
+ {
+ return FALSE;
+ }
+
+ *Data = READ_MIDIUART_DATA(UartBasePort);
+
+ return TRUE;
+}
+
+
+/* Experimental OO-style stuff */
+/*
+typedef struct _MIDIUART
+{
+ PUCHAR BasePort;
+ ULONG Timeout;
+} MIDIUART, *PMIDIUART;
+
+NTSTATUS
+MidiUart_Create(
+ IN PUCHAR BasePort,
+ IN ULONG Timeout,
+ OUT PMIDIUART* MidiUart)
+{
+ PMIDIUART NewMidiUart;
+
+ if ( ! MidiUart )
+ return STATUS_INVALID_PARAMETER;
+
+ NewMidiUart = ExAllocatePoolWithTag(sizeof(MIDIUART), PAGED_POOL, 'MIDU');
+
+ if ( ! NewMidiUart )
+ return STATUS_INSUFFICIENT_RESOURCES;
+
+ NewMidiUart->BasePort = BasePort;
+ NewMidiUart->Timeout = Timeout;
+
+ *MidiUart = NewMidiUart;
+
+ return STATUS_SUCCESS;
+}
+
+BOOLEAN
+MidiUart_WaitForStatus(
+ IN PMIDIUART MidiUart,
+ IN UCHAR StatusFlags)
+{
+ if ( ! MidiUart)
+ return FALSE;
+
+ return WaitForMidiUartStatus(MidiUart->BasePort,
+ StatusFlags,
+ MidiUart->Timeout);
+}
+
+#define MidiUart_WaitForCTS(inst) \
+ MidiUart_WaitForStatus(inst, MIDIUART_STATUS_CTS)
+
+#define MidiUart_WaitForDTR(inst) \
+ MidiUart_WaitForStatus(inst, MIDIUART_STATUS_DTR)
+
+BOOLEAN
+MidiUart_WriteByte(
+ IN PMIDIUART MidiUart,
+ IN UCHAR Data)
+{
+ if ( ! MidiUart )
+ return FALSE;
+
+ return WriteMidiUartByte(MidiUart->BasePort,
+ Data,
+ MidiUart->Timeout);
+}
+
+BOOLEAN
+MidiUart_ReadByte(
+ IN PMIDIUART MidiUart,
+ OUT PUCHAR Data)
+{
+ if ( ! MidiUart )
+ return FALSE;
+
+ return ReadMidiUartByte(MidiUart->BasePort,
+ Data,
+ MidiUart->Timeout);
+}
+*/
Propchange: branches/silverblade-audio/lib/drivers/sound/midiuart.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/silverblade-audio/lib/drivers/sound/sbdsp.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/sbdsp.c (added)
+++ branches/silverblade-audio/lib/drivers/sound/sbdsp.c [iso-8859-1] Tue Jul 1 11:09:10
2008
@@ -1,0 +1,119 @@
+/*
+ ReactOS Sound System
+ Sound Blaster DSP support
+
+ Author:
+ Andrew Greenwood (andrew.greenwood(a)silverblade.co.uk)
+
+ History:
+ 26 May 2008 - Created
+
+ Notes:
+ ...
+*/
+
+#include <ntddk.h>
+#include <sound/time.h>
+
+/*
+ Sound Blaster ports I/O
+*/
+#define READ_SB_FM1_STATUS(bp) READ_PORT_UCHAR((PUCHAR) bp)
+#define WRITE_SB_FM1_REGISTER(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp, x)
+#define WRITE_SB_FM1_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x01, x)
+
+#define READ_SB_AFM_STATUS(bp) READ_PORT_UCHAR((PUCHAR) bp+0x02)
+#define WRITE_SB_AFM_REGISTER(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x02, x)
+#define WRITE_SB_AFM_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x03, x)
+
+#define WRITE_SB_MIXER_REGISTER(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x04, x)
+#define READ_SB_MIXER_DATA(bp) READ_PORT_UCHAR((PUCHAR) bp+0x05)
+#define WRITE_SB_MIXER_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x05, x)
+
+#define WRITE_SB_DSP_RESET(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x06, x)
+
+#define READ_SB_FM2_STATUS(bp) READ_PORT_UCHAR((PUCHAR) bp+0x08)
+#define WRITE_SB_FM2_REGISTER(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x08, x)
+#define WRITE_SB_FM2_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x09, x)
+
+#define READ_SB_DSP_DATA(bp) READ_PORT_UCHAR((PUCHAR) bp+0x0A)
+#define WRITE_SB_DSP_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x0C, x)
+#define WRITE_SB_DSP_COMMAND(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x0C, x)
+
+#define READ_SB_DSP_WRITE_BUFFER_STATUS(bp) \
+ ( READ_PORT_UCHAR((PUCHAR) bp+0x0C) & 0x01 )
+
+#define READ_SB_DSP_READ_BUFFER_STATUS(bp) \
+ ( READ_PORT_UCHAR((PUCHAR) bp+0x0E) & 0x01 )
+
+
+#define SB_DSP_READY 0xAA
+
+/*
+ Sound Blaster DSP commands
+ (partial list)
+*/
+#define SB_DSP_OUTPUT_RATE 0x41
+#define SB_DSP_INPUT_RATE 0x42
+#define SB_DSP_BLOCK_SIZE 0x48
+#define SB_DSP_SPEAKER_ON 0xD1
+#define SB_DSP_SPEAKER_OFF 0xD3
+#define SB_DSP_SPEAKER_STATUS 0xD8
+#define SB_DSP_VERSION 0xE1
+
+BOOLEAN
+ResetSoundBlasterDSP(
+ IN PUCHAR BasePort,
+ IN ULONG Timeout)
+{
+ ULONG Expiry;
+ KTIMER Timer;
+ KIRQL CurrentIrqLevel = KeGetCurrentIrql();
+
+ /* Should be called from DriverEntry with this IRQL */
+ ASSERT(CurrentIrqLevel == PASSIVE_LEVEL);
+
+ KeInitializeTimer(&Timer);
+
+ WRITE_SB_DSP_RESET(BasePort, 0x01);
+ SleepMs(50); /* Should be enough */
+ WRITE_SB_DSP_RESET(BasePort, 0x00);
+
+ Expiry = QuerySystemTimeMs() + Timeout;
+
+ while ( (QuerySystemTimeMs() < Expiry) || ( Timeout == 0) )
+ {
+ if ( READ_SB_DSP_DATA(BasePort) == SB_DSP_READY )
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+BOOLEAN
+WaitForSoundBlasterDSPReady(
+ IN PUCHAR BasePort,
+ IN ULONG Timeout)
+{
+ ULONG Expiry = QuerySystemTimeMs() + Timeout;
+
+ while ( (QuerySystemTimeMs() < Expiry) || (Timeout == 0) )
+ {
+ // ...
+ }
+
+ return FALSE;
+}
+
+NTSTATUS
+GetSoundBlasterDSPVersion(
+ IN PUCHAR BasePort,
+ OUT PUCHAR MajorVersion,
+ OUT PUCHAR MinorVersion,
+ IN ULONG Timeout)
+{
+ /* TODO */
+ return STATUS_NOT_SUPPORTED;
+}
Propchange: branches/silverblade-audio/lib/drivers/sound/sbdsp.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/silverblade-audio/lib/drivers/sound/sound.rbuild
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/sound.rbuild (added)
+++ branches/silverblade-audio/lib/drivers/sound/sound.rbuild [iso-8859-1] Tue Jul 1
11:09:10 2008
@@ -1,0 +1,13 @@
+<?xml version="1.0"?>
+<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
+<module name="sound" type="staticlibrary"
allowwarnings="true">
+ <define name="__NTDRIVER__"/>
+ <define name="KERNEL"/>
+ <include base="sound">.</include>
+ <include base="ReactOS">include/reactos/libs/sound</include>
+ <file>devname.c</file>
+ <file>hardware.c</file>
+ <file>midiuart.c</file>
+ <file>sbdsp.c</file>
+ <file>time.c</file>
+</module>
Propchange: branches/silverblade-audio/lib/drivers/sound/sound.rbuild
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/silverblade-audio/lib/drivers/sound/time.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/time.c (added)
+++ branches/silverblade-audio/lib/drivers/sound/time.c [iso-8859-1] Tue Jul 1 11:09:10
2008
@@ -1,0 +1,47 @@
+/*
+ ReactOS Sound System
+ Timing helper
+
+ Author:
+ Andrew Greenwood (andrew.greenwood(a)silverblade.co.uk)
+
+ History:
+ 31 May 2008 - Created
+
+ Notes:
+ Timing may require testing!
+*/
+
+/*
+ Nanoseconds are fun! You must try some!
+ 1 ns = .000000001 seconds = .0000001 ms
+ 100 ns = .0000001 seconds = .00001 ms
+ 10000 ns = .00001 seconds = .001 ms
+ 1000000 ns = .001 seconds = 1 ms
+*/
+
+#include <ntddk.h>
+
+VOID
+SleepMs(ULONG Milliseconds)
+{
+ LARGE_INTEGER Period;
+
+ Period.QuadPart = -Milliseconds;
+ Period.QuadPart *= 10000;
+
+ KeDelayExecutionThread(KernelMode, FALSE, &Period);
+}
+
+ULONG
+QuerySystemTimeMs()
+{
+ LARGE_INTEGER Time;
+
+ KeQuerySystemTime(&Time);
+
+ Time.QuadPart /= 10000;
+
+ return (ULONG) Time.QuadPart;
+}
+
Propchange: branches/silverblade-audio/lib/drivers/sound/time.c
------------------------------------------------------------------------------
svn:eol-style = native