[ros-diffs] [silverblade] 34338: Partial implementation of WODM_CLOSE and WODM_WRITE handling within MME-Buddy. Test code added to sndblst.dll to mimics WinMM's behaviour. Seems OK so far. WODM_WRITE just throws a single buffer at the Sound Blaster driver, needs a lot more work. Don't yet support the WinMM open/close/data/done callbacks.

silverblade at svn.reactos.org silverblade at svn.reactos.org
Sun Jul 6 18:37:42 CEST 2008


Author: silverblade
Date: Sun Jul  6 11:37:41 2008
New Revision: 34338

URL: http://svn.reactos.org/svn/reactos?rev=34338&view=rev
Log:
Partial implementation of WODM_CLOSE and WODM_WRITE handling within MME-Buddy.
Test code added to sndblst.dll to mimics WinMM's behaviour. Seems OK so far.
WODM_WRITE just throws a single buffer at the Sound Blaster driver, needs a
lot more work. Don't yet support the WinMM open/close/data/done callbacks.


Modified:
    branches/silverblade-audio/dll/win32/sndblst/sndblst.c
    branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h
    branches/silverblade-audio/lib/drivers/sound/mmebuddy/devices.c
    branches/silverblade-audio/lib/drivers/sound/mmebuddy/instances.c
    branches/silverblade-audio/lib/drivers/sound/mmebuddy/mme/wodMessage.c

Modified: branches/silverblade-audio/dll/win32/sndblst/sndblst.c
URL: http://svn.reactos.org/svn/reactos/branches/silverblade-audio/dll/win32/sndblst/sndblst.c?rev=34338&r1=34337&r2=34338&view=diff
==============================================================================
--- branches/silverblade-audio/dll/win32/sndblst/sndblst.c [iso-8859-1] (original)
+++ branches/silverblade-audio/dll/win32/sndblst/sndblst.c [iso-8859-1] Sun Jul  6 11:37:41 2008
@@ -19,13 +19,63 @@
 #include <debug.h>
 
 
+PWSTR SBWaveOutDeviceName = L"Sound Blaster Playback";
+PWSTR SBWaveInDeviceName  = L"Sound Blaster Recording";
+/* TODO: Mixer etc */
+
+
+MMRESULT
+GetSoundBlasterDeviceCapabilities(
+    IN  PSOUND_DEVICE Device,
+    OUT PUNIVERSAL_CAPS Capabilities)
+{
+    MMRESULT Result;
+
+    if ( ! Device )
+        return MMSYSERR_INVALPARAM;
+
+    if ( ! Capabilities )
+        return MMSYSERR_INVALPARAM;
+
+    Result = DefaultGetSoundDeviceCapabilities(Device, Capabilities);
+    if ( Result != MMSYSERR_NOERROR )
+        return Result;
+
+    switch ( Device->DeviceType )
+    {
+        case WAVE_OUT_DEVICE_TYPE :
+            CopyWideString(Capabilities->WaveOut.szPname,
+                           SBWaveOutDeviceName);
+            break;
+
+        case WAVE_IN_DEVICE_TYPE :
+            CopyWideString(Capabilities->WaveOut.szPname,
+                           SBWaveInDeviceName);
+            break;
+
+        /* ... TODO ... */
+
+        //default :
+            /* Do nothing special */
+    }
+
+    return MMSYSERR_NOERROR;
+}
+
+
 BOOLEAN FoundDevice(
     UCHAR DeviceType,
     PWSTR DevicePath,
     HANDLE Handle)
 {
+    MMFUNCTION_TABLE FuncTable;
+
+    ZeroMemory(&FuncTable, sizeof(MMFUNCTION_TABLE));
+
+    FuncTable.GetCapabilities = GetSoundBlasterDeviceCapabilities;
+
     /* Nothing particularly special required... */
-    return ( AddSoundDevice(DeviceType, DevicePath) == MMSYSERR_NOERROR );
+    return ( AddSoundDevice(DeviceType, DevicePath, &FuncTable) == MMSYSERR_NOERROR );
 }
 
 
@@ -66,16 +116,69 @@
     }
 }
 
+
+WORD Buffer[65536];
+WAVEHDR WaveHeader;
+
 int APIENTRY wWinMain(
     HINSTANCE hInstance,
     HINSTANCE hPrevInstance,
     LPWSTR lpCmdLine,
     int nCmdShow)
 {
+    WCHAR msg[1024];
+    WAVEOUTCAPS Caps;
+    WAVEOPENDESC OpenDesc;
+    WAVEFORMATEX Format;
+    MMRESULT Result;
+    PVOID InstanceData;
+
+    /* DRV_LOAD */
     DriverProc(0, 0, DRV_LOAD, 0, 0);
 
+    /* WODM_GETNUMDEVS */
     SOUND_DEBUG_HEX(wodMessage(0, WODM_GETNUMDEVS, 0, 0, 0));
 
+    Result = wodMessage(0, WODM_GETDEVCAPS, 0,
+                        (DWORD) &Caps, sizeof(WAVEOUTCAPS));
+
+    /* WODM_GETDEVCAPS */
+    wsprintf(msg, L"Device name: %ls\nManufacturer ID: %d\nProduct ID: %d\nDriver version: %x\nChannels: %d", Caps.szPname, Caps.wMid, Caps.wPid, Caps.vDriverVersion, Caps.wChannels);
+
+    MessageBox(0, msg, L"Device capabilities", MB_OK | MB_TASKMODAL);
+
+    /* WODM_OPEN */
+    Format.wFormatTag = WAVE_FORMAT_PCM;
+    Format.nChannels = 1;
+    Format.nSamplesPerSec = 22050;
+    Format.wBitsPerSample = 16;
+    Format.nBlockAlign = Format.nChannels * (Format.wBitsPerSample / 8);
+    Format.nAvgBytesPerSec = Format.nSamplesPerSec * Format.nBlockAlign;
+    Format.cbSize = 0;
+
+    SOUND_DEBUG(L"WODM_OPEN test 1 (query format support only)");
+    OpenDesc.lpFormat = &Format;
+    Result = wodMessage(0, WODM_OPEN, 0, (DWORD) &OpenDesc, WAVE_FORMAT_QUERY);
+    SOUND_DEBUG_HEX(Result);
+
+    SOUND_DEBUG(L"WODM_OPEN test 2");
+    OpenDesc.lpFormat = &Format;
+    Result = wodMessage(0, WODM_OPEN, (DWORD) &InstanceData, (DWORD) &OpenDesc, 0);
+    SOUND_DEBUG_HEX(Result);
+
+    SOUND_DEBUG(L"WODM_WRITE test");
+    WaveHeader.lpData = (PVOID) Buffer;
+    WaveHeader.dwBufferLength = 65536;
+    WaveHeader.dwFlags = WHDR_PREPARED;
+
+    Result = wodMessage(0, WODM_WRITE, (DWORD) InstanceData, (DWORD) &WaveHeader, 0);
+    SOUND_DEBUG_HEX(Result);
+
+    SOUND_DEBUG(L"WODM_CLOSE test");
+    Result = wodMessage(0, WODM_CLOSE, (DWORD) InstanceData, (DWORD) 0, 0);
+    SOUND_DEBUG_HEX(Result);
+
+    /* DRV_UNLOAD */
     DriverProc(0, 0, DRV_FREE, 0, 0);
 
     return 0;

Modified: branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h
URL: http://svn.reactos.org/svn/reactos/branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h?rev=34338&r1=34337&r2=34338&view=diff
==============================================================================
--- branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h [iso-8859-1] (original)
+++ branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h [iso-8859-1] Sun Jul  6 11:37:41 2008
@@ -253,7 +253,8 @@
 BOOLEAN
 AddSoundDevice(
     IN  UCHAR DeviceType,
-    IN  PWSTR DevicePath);
+    IN  PWSTR DevicePath,
+    IN  PMMFUNCTION_TABLE FunctionTable);
 
 MMRESULT
 RemoveSoundDevice(

Modified: branches/silverblade-audio/lib/drivers/sound/mmebuddy/devices.c
URL: http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/sound/mmebuddy/devices.c?rev=34338&r1=34337&r2=34338&view=diff
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/devices.c [iso-8859-1] (original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/devices.c [iso-8859-1] Sun Jul  6 11:37:41 2008
@@ -47,21 +47,34 @@
 
 VOID
 InitSoundDeviceFunctionTable(
-    IN  PSOUND_DEVICE Device)
-{
+    IN  PSOUND_DEVICE Device,
+    IN  PMMFUNCTION_TABLE SourceFunctionTable)
+{
+    /* Defaults... TODO - Make all these over-rideable! */
     Device->Functions.Constructor = DefaultInstanceConstructor;
     Device->Functions.Destructor = DefaultInstanceDestructor;
 
     Device->Functions.GetCapabilities = DefaultGetSoundDeviceCapabilities;
     Device->Functions.QueryWaveFormat = DefaultQueryWaveDeviceFormatSupport;
     Device->Functions.SetWaveFormat = DefaultSetWaveDeviceFormat;
+
+    if ( ! SourceFunctionTable )
+        return;
+
+    /* If we get here, the function table is being over-ridden */
+    if ( SourceFunctionTable->GetCapabilities )
+    {
+        Device->Functions.GetCapabilities =
+            SourceFunctionTable->GetCapabilities;
+    }
 }
 
 
 BOOLEAN
 AddSoundDevice(
     IN  UCHAR DeviceType,
-    IN  LPWSTR DevicePath)
+    IN  LPWSTR DevicePath,
+    IN  PMMFUNCTION_TABLE FunctionTable)
 {
     PSOUND_DEVICE NewDevice;
     UCHAR TypeIndex;
@@ -108,7 +121,7 @@
     /*CopyMemory(NewDevice->DevicePath, DevicePath, DevicePathSize);*/
 
     /* Set up function table */
-    InitSoundDeviceFunctionTable(NewDevice);
+    InitSoundDeviceFunctionTable(NewDevice, FunctionTable);
 
     /* Start or add to list */
     if ( ! SoundDeviceLists[TypeIndex] )
@@ -261,7 +274,7 @@
         return MMSYSERR_INVALPARAM;
 
     if ( DeviceIndex >= SoundDeviceTotals[DeviceType - MIN_SOUND_DEVICE_TYPE] )
-        return MMSYSERR_INVALPARAM;
+        return MMSYSERR_BADDEVICEID;
 
     if ( ! Device )
         return MMSYSERR_INVALPARAM;

Modified: branches/silverblade-audio/lib/drivers/sound/mmebuddy/instances.c
URL: http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/sound/mmebuddy/instances.c?rev=34338&r1=34337&r2=34338&view=diff
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/instances.c [iso-8859-1] (original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/instances.c [iso-8859-1] Sun Jul  6 11:37:41 2008
@@ -206,20 +206,15 @@
     IN  PSOUND_DEVICE SoundDevice)
 {
     PSOUND_DEVICE_INSTANCE CurrentInstance = NULL;
-    PSOUND_DEVICE_INSTANCE NextInstance = NULL;
     MMRESULT Result;
 
     if ( ! SoundDevice )
         return MMSYSERR_INVALPARAM;
 
-    CurrentInstance = SoundDevice->FirstInstance;
-
-    while ( CurrentInstance )
-    {
-        NextInstance = CurrentInstance->Next;
-
+    /* Just munch away at the first item repeatedly */
+    while ( (CurrentInstance = SoundDevice->FirstInstance) )
+    {
         Result = DestroySoundDeviceInstance(CurrentInstance);
-        ASSERT(Result == MMSYSERR_NOERROR);
     }
 
     return MMSYSERR_NOERROR;

Modified: branches/silverblade-audio/lib/drivers/sound/mmebuddy/mme/wodMessage.c
URL: http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/sound/mmebuddy/mme/wodMessage.c?rev=34338&r1=34337&r2=34338&view=diff
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/mme/wodMessage.c [iso-8859-1] (original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/mme/wodMessage.c [iso-8859-1] Sun Jul  6 11:37:41 2008
@@ -30,8 +30,10 @@
 {
     MMRESULT Result = MMSYSERR_NOERROR;
     PSOUND_DEVICE Device = NULL;
-    PSOUND_DEVICE_INSTANCE Instance = NULL;
-    DPRINT("wodMessageStub called\n");
+    PSOUND_DEVICE_INSTANCE Instance =
+        (PSOUND_DEVICE_INSTANCE)private_handle;
+
+    SOUND_DEBUG(L"wodMessageStub called\n");
 
     switch ( message )
     {
@@ -62,6 +64,7 @@
         {
             WAVEOPENDESC* OpenParameters = (WAVEOPENDESC*) parameter1;
 
+            SOUND_DEBUG(L"In WODM_OPEN");
             Result = GetSoundDevice(WAVE_OUT_DEVICE_TYPE, device_id, &Device);
             if ( Result != MMSYSERR_NOERROR )
                 return Result;
@@ -74,6 +77,8 @@
 
                 return Result;
             }
+
+            ASSERT(private_handle != 0);
 
             Result = CreateSoundDeviceInstance(Device, &Instance);
             if ( Result != MMSYSERR_NOERROR )
@@ -89,16 +94,48 @@
                 return Result;
             }
 
-            /* TODO: Provide winmm with instance handle */
+            /* Start the wave handling thread */
+            Result = StartWaveThread(Instance);
+            if ( Result != MMSYSERR_NOERROR )
+            {
+                /* TODO: Do we need to do anything more */
+                DestroySoundDeviceInstance(Instance);
+                return Result;
+            }
+
+            /* Provide winmm with instance handle */
+            *((PSOUND_DEVICE_INSTANCE*)private_handle) = Instance;
+
             /* TODO: Send callback... */
 
             return MMSYSERR_NOERROR;
         }
 
         case WODM_CLOSE :
+        {
+            //SOUND_DEBUG_HEX(Instance);
+            SOUND_ASSERT(Instance != NULL);
+
+            /* TODO: Ensure its OK to close */
+
+            Result = StopWaveThread(Instance);
+            SOUND_ASSERT(Result == MMSYSERR_NOERROR);
+
+            Result = DestroySoundDeviceInstance(Instance);
+            SOUND_DEBUG_HEX(Result);
+
+            return Result;
             /* CloseSoundDevice() */
+        }
 
         case WODM_WRITE :
+        {
+            SOUND_ASSERT(Instance != NULL);
+            SOUND_ASSERT(parameter1 != 0);
+
+            return QueueWaveDeviceBuffer(Instance, (PWAVEHDR) parameter1);
+        }
+
         case WODM_PAUSE :
         case WODM_RESTART :
         case WODM_RESET :



More information about the Ros-diffs mailing list