Ver Fonte

Enabled directsound functionality.
Added directsound glue.

woollybah há 10 anos atrás
pai
commit
f92425ff0b
4 ficheiros alterados com 306 adições e 3 exclusões
  1. 1 1
      directx.mod/directx.bmx
  2. 25 2
      directx.mod/dsound.bmx
  3. 128 0
      directx.mod/dsound.cpp
  4. 152 0
      directx.mod/dsound.h

+ 1 - 1
directx.mod/directx.bmx

@@ -31,5 +31,5 @@ Import "d3d.bmx"
 Import "d3d7.bmx"
 Import "d3d9.bmx"
 Import "d3d9x.bmx"
-Import "dsound.bmx"
 ?
+Import "dsound.bmx"

+ 25 - 2
directx.mod/dsound.bmx

@@ -3,6 +3,8 @@ Strict
 
 Import Pub.Win32
 
+Import "dsound.cpp"
+
 Const DIRECTSOUND_VERSION=$0700
 
 Const DSSCL_NORMAL=$00000001
@@ -64,7 +66,7 @@ Const DSBSTATUS_TERMINATED=$00000020
 
 Const DSBLOCK_FROMWRITECURSOR=$00000001
 Const DSBLOCK_ENTIREBUFFER=$00000002
-
+?disabled
 Type DSCAPS
 	Field dwSize
 	Field dwFlags
@@ -156,6 +158,27 @@ Type IDirectSoundBuffer Extends IUnknown
 	Method Restore()
 End Type
 
+End Extern
+?
+
+Extern
+	Function bmx_directsound_IDirectSound_release:Int(handle:Byte Ptr)
+	Function bmx_directsound_IDirectSound_create:Int(dsound:Byte Ptr Ptr)
+	Function bmx_directsound_IDirectSound_setcooperativeLevel:Int(handle:Byte Ptr, hwnd:Byte Ptr, flags:Int)
+	Function bmx_directsound_IDirectSound_duplicatesoundbuffer:Int(handle:Byte Ptr, buffer:Byte Ptr, buf:Byte Ptr Ptr)
+	Function bmx_directsound_IDirectSound_createsoundbuffer:Int(handle:Byte Ptr, buf:Byte Ptr Ptr, length:Int, hertz:Int, format:Int, chans:Int, bps:Int, size:Int, flags:Int, _mode:Int)
+
+	Function bmx_directsound_IDirectSoundBuffer_release:Int(handle:Byte Ptr)
+	Function bmx_directsound_IDirectSoundBuffer_stop:Int(handle:Byte Ptr)
+	Function bmx_directsound_IDirectSoundBuffer_play:Int(handle:Byte Ptr, res:Int, priority:Int, flags:Int)
+	Function bmx_directsound_IDirectSoundBuffer_setvolume:Int(handle:Byte Ptr, volume:Int)
+	Function bmx_directsound_IDirectSoundBuffer_setpan:Int(handle:Byte Ptr, pan:Int)
+	Function bmx_directsound_IDirectSoundBuffer_setfrequency:Int(handle:Byte Ptr, freq:Int)
+	Function bmx_directsound_IDirectSoundBuffer_setcurrentposition:Int(handle:Byte Ptr, pos:Int)
+	Function bmx_directsound_IDirectSoundBuffer_lock:Int(handle:Byte Ptr, offset:Int, size:Int, ptr1:Byte Ptr Ptr, bytes1:Int Ptr, ptr2:Byte Ptr Ptr, bytes2:Int Ptr, flags:Int )
+	Function bmx_directsound_IDirectSoundBuffer_unlock:Int(handle:Byte Ptr, ptr1:Byte Ptr,bytes1:Int,ptr2:Byte Ptr,bytes2:Int)
+	Function bmx_directsound_IDirectSoundBuffer_getstatus:Int(handle:Byte Ptr, status:Int Ptr)
+	
 End Extern
 
 Private
@@ -164,4 +187,4 @@ Global _ds=LoadLibraryA( "dsound" )
 
 Public
 
-Global DirectSoundCreate( guid:Byte Ptr,dsound:IDirectSound Var,unk:Byte Ptr )"win32"=GetProcAddress( _ds,"DirectSoundCreate" )
+Global DirectSoundCreate( guid:Byte Ptr,dsound:Byte Ptr,unk:Byte Ptr )"win32"=GetProcAddress( _ds,"DirectSoundCreate" )

+ 128 - 0
directx.mod/dsound.cpp

@@ -0,0 +1,128 @@
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <objbase.h>
+#include <mmsystem.h>
+#include <stdio.h>
+#include "dsound.h"
+
+extern "C" {
+
+	int bmx_directsound_IDirectSound_release(IDirectSound * dsound);
+	int bmx_directsound_IDirectSound_create(IDirectSound ** dsound);
+	int bmx_directsound_IDirectSound_setcooperativeLevel(IDirectSound * dsound, HWND hwnd, int flags);
+	int bmx_directsound_IDirectSound_duplicatesoundbuffer(IDirectSound * dsound, IDirectSoundBuffer * buffer, IDirectSoundBuffer ** buf);
+	int bmx_directsound_IDirectSound_createsoundbuffer(IDirectSound * dsound, IDirectSoundBuffer ** buf, int length, int hertz, int format, int chans, int bps, int size, int flags, int mode);
+
+	int bmx_directsound_IDirectSoundBuffer_release(IDirectSoundBuffer * buffer);
+	int bmx_directsound_IDirectSoundBuffer_stop(IDirectSoundBuffer * buffer);
+	int bmx_directsound_IDirectSoundBuffer_play(IDirectSoundBuffer * buffer, int res, int priority, int flags);
+	int bmx_directsound_IDirectSoundBuffer_setvolume(IDirectSoundBuffer * buffer, int volume);
+	int bmx_directsound_IDirectSoundBuffer_setpan(IDirectSoundBuffer * buffer, int pan);
+	int bmx_directsound_IDirectSoundBuffer_setfrequency(IDirectSoundBuffer * buffer, int freq);
+	int bmx_directsound_IDirectSoundBuffer_setcurrentposition(IDirectSoundBuffer * buffer, int pos);
+	int bmx_directsound_IDirectSoundBuffer_lock(IDirectSoundBuffer * buffer, int offset, int size, void ** ptr1, int * bytes1, void ** ptr2, int * bytes2, int flags);
+	int bmx_directsound_IDirectSoundBuffer_unlock(IDirectSoundBuffer * buffer, void * ptr1, int bytes1, void * ptr2, int bytes2);
+	int bmx_directsound_IDirectSoundBuffer_getstatus(IDirectSoundBuffer * buffer, int * status);
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+int bmx_directsound_IDirectSound_release(IDirectSound * dsound) {
+	return dsound->Release();
+}
+
+int bmx_directsound_IDirectSound_create(IDirectSound ** dsound) {
+	HINSTANCE dsoundlib;
+	HRESULT WINAPI (*DirectSoundCreate)(LPGUID,LPDIRECTSOUND*,LPUNKNOWN);
+
+	dsoundlib=LoadLibraryA("dsound");	
+	DirectSoundCreate=(HRESULT WINAPI (*)(LPGUID,LPDIRECTSOUND*,LPUNKNOWN))GetProcAddress(dsoundlib,"DirectSoundCreate");
+	int res=DirectSoundCreate(0,dsound,0);
+	return res;
+}
+
+int bmx_directsound_IDirectSound_setcooperativeLevel(IDirectSound * dsound, HWND hwnd, int flags) {
+	return dsound->SetCooperativeLevel(hwnd, flags);
+}
+
+int bmx_directsound_IDirectSound_duplicatesoundbuffer(IDirectSound * dsound, IDirectSoundBuffer * buffer, IDirectSoundBuffer ** buf) {
+	return dsound->DuplicateSoundBuffer(buffer, buf);
+}
+
+int bmx_directsound_IDirectSound_createsoundbuffer(IDirectSound * dsound, IDirectSoundBuffer ** buf, int length, int hertz, int format, int chans, int bps, int size, int flags, int mode) {
+	WAVEFORMATEX fmt;
+	memset(&fmt, 0, sizeof(WAVEFORMATEX)); 
+
+	fmt.wFormatTag = 1;
+	fmt.nChannels = chans;
+	fmt.nSamplesPerSec = hertz;
+	fmt.wBitsPerSample = bps*8;
+	fmt.nBlockAlign = fmt.wBitsPerSample/8*fmt.nChannels;
+	fmt.nAvgBytesPerSec = fmt.nSamplesPerSec*fmt.nBlockAlign;
+
+	DSBUFFERDESC desc;
+	memset(&desc, 0, sizeof(DSBUFFERDESC)); 
+
+	desc.dwSize = sizeof(DSBUFFERDESC);
+	desc.dwFlags = DSBCAPS_GLOBALFOCUS|DSBCAPS_STATIC|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLFREQUENCY;
+	if (mode==1 || ((flags & 2)!=2)) {
+		desc.dwFlags |= DSBCAPS_LOCSOFTWARE;
+	}
+	desc.dwBufferBytes = size;
+	desc.lpwfxFormat = &fmt;
+
+	return dsound->CreateSoundBuffer( &desc,buf,0 );
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+int bmx_directsound_IDirectSoundBuffer_release(IDirectSoundBuffer * buffer) {
+	return buffer->Release();
+}
+
+int bmx_directsound_IDirectSoundBuffer_stop(IDirectSoundBuffer * buffer) {
+	return buffer->Stop();
+}
+
+int bmx_directsound_IDirectSoundBuffer_play(IDirectSoundBuffer * buffer, int res, int priority, int flags) {
+	return buffer->Play(res, priority, flags);
+}
+
+int bmx_directsound_IDirectSoundBuffer_setvolume(IDirectSoundBuffer * buffer, int volume) {
+	return buffer->SetVolume(volume);
+}
+
+int bmx_directsound_IDirectSoundBuffer_setpan(IDirectSoundBuffer * buffer, int pan) {
+	return buffer->SetPan(pan);
+}
+
+int bmx_directsound_IDirectSoundBuffer_setfrequency(IDirectSoundBuffer * buffer, int freq) {
+	return buffer->SetFrequency(freq);
+}
+
+int bmx_directsound_IDirectSoundBuffer_setcurrentposition(IDirectSoundBuffer * buffer, int pos) {
+	return buffer->SetCurrentPosition(pos);
+}
+
+int bmx_directsound_IDirectSoundBuffer_lock(IDirectSoundBuffer * buffer, int offset, int size, void ** ptr1, int * bytes1, void ** ptr2, int * bytes2, int flags) {
+	DWORD b1, b2;
+	int res = buffer->Lock(offset, size, ptr1, &b1, ptr2, &b2, flags);
+	*bytes1 = b1;
+	*bytes2 = b2;
+	return res;
+}
+
+int bmx_directsound_IDirectSoundBuffer_unlock(IDirectSoundBuffer * buffer, void * ptr1, int bytes1, void * ptr2, int bytes2) {
+	return buffer->Unlock(ptr1, bytes1, ptr2, bytes2);
+}
+
+int bmx_directsound_IDirectSoundBuffer_getstatus(IDirectSoundBuffer * buffer, int * status) {
+	DWORD s;
+	int res = buffer->GetStatus(&s);
+	*status = s;
+	return res;
+}
+
+// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+

+ 152 - 0
directx.mod/dsound.h

@@ -0,0 +1,152 @@
+// dsound.h
+
+#ifndef dsound_h
+#define dsound_h
+
+#define DSBCAPS_PRIMARYBUFFER       0x00000001
+#define DSBCAPS_STATIC              0x00000002
+#define DSBCAPS_LOCHARDWARE         0x00000004
+#define DSBCAPS_LOCSOFTWARE         0x00000008
+#define DSBCAPS_CTRL3D              0x00000010
+#define DSBCAPS_CTRLFREQUENCY       0x00000020
+#define DSBCAPS_CTRLPAN             0x00000040
+#define DSBCAPS_CTRLVOLUME          0x00000080
+#define DSBCAPS_CTRLPOSITIONNOTIFY  0x00000100
+#define DSBCAPS_CTRLFX              0x00000200
+#define DSBCAPS_STICKYFOCUS         0x00004000
+#define DSBCAPS_GLOBALFOCUS         0x00008000
+#define DSBCAPS_GETCURRENTPOSITION2 0x00010000
+#define DSBCAPS_MUTE3DATMAXDISTANCE 0x00020000
+#define DSBCAPS_LOCDEFER            0x00040000
+
+#define DSBPLAY_LOOPING             0x00000001
+#define DSBPLAY_LOCHARDWARE         0x00000002
+#define DSBPLAY_LOCSOFTWARE         0x00000004
+#define DSBPLAY_TERMINATEBY_TIME    0x00000008
+#define DSBPLAY_TERMINATEBY_DISTANCE    0x000000010
+#define DSBPLAY_TERMINATEBY_PRIORITY    0x000000020
+
+#define DSBLOCK_FROMWRITECURSOR     0x00000001
+#define DSBLOCK_ENTIREBUFFER        0x00000002
+
+#define DSSCL_NORMAL                0x00000001
+#define DSSCL_PRIORITY              0x00000002
+#define DSSCL_EXCLUSIVE             0x00000003
+#define DSSCL_WRITEPRIMARY          0x00000004
+
+struct DSCAPS{ 
+  DWORD  dwSize; 
+  DWORD  dwFlags;  
+  DWORD  dwMinSecondarySampleRate; 
+  DWORD  dwMaxSecondarySampleRate; 
+  DWORD  dwPrimaryBuffers; 
+  DWORD  dwMaxHwMixingAllBuffers; 
+  DWORD  dwMaxHwMixingStaticBuffers; 
+  DWORD  dwMaxHwMixingStreamingBuffers; 
+  DWORD  dwFreeHwMixingAllBuffers; 
+  DWORD  dwFreeHwMixingStaticBuffers; 
+  DWORD  dwFreeHwMixingStreamingBuffers; 
+  DWORD  dwMaxHw3DAllBuffers; 
+  DWORD  dwMaxHw3DStaticBuffers; 
+  DWORD  dwMaxHw3DStreamingBuffers; 
+  DWORD  dwFreeHw3DAllBuffers; 
+  DWORD  dwFreeHw3DStaticBuffers; 
+  DWORD  dwFreeHw3DStreamingBuffers; 
+  DWORD  dwTotalHwMemBytes; 
+  DWORD  dwFreeHwMemBytes; 
+  DWORD  dwMaxContigFreeHwMemBytes; 
+  DWORD  dwUnlockTransferRateHwBuffers; 
+  DWORD  dwPlayCpuOverheadSwBuffers; 
+  DWORD  dwReserved1; 
+  DWORD  dwReserved2; 
+};
+typedef DSCAPS *LPDSCAPS; 
+
+struct DSBUFFERDESC{
+    DWORD           dwSize;
+    DWORD           dwFlags;
+    DWORD           dwBufferBytes;
+    DWORD           dwReserved;
+    LPWAVEFORMATEX  lpwfxFormat;
+    GUID            guid3DAlgorithm;
+};
+typedef DSBUFFERDESC *LPDSBUFFERDESC;
+typedef const DSBUFFERDESC *LPCDSBUFFERDESC;
+
+struct DSBPOSITIONNOTIFY{
+    DWORD           dwOffset;
+    HANDLE          hEventNotify;
+};
+typedef DSBPOSITIONNOTIFY *LPDSBPOSITIONNOTIFY;
+typedef const DSBPOSITIONNOTIFY *LPCDSBPOSITIONNOTIFY;
+
+
+typedef void *LPDSBCAPS;
+typedef struct IDirectSound *LPDIRECTSOUND;
+typedef struct IDirectSoundBuffer *LPDIRECTSOUNDBUFFER;
+
+#undef INTERFACE
+#define INTERFACE IDirectSoundBuffer
+
+DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown){
+    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID FAR *) PURE;
+    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
+    STDMETHOD_(ULONG,Release)       (THIS) PURE;
+    
+    STDMETHOD(GetCaps)              (THIS_ LPDSBCAPS) PURE;
+    STDMETHOD(GetCurrentPosition)   (THIS_ LPDWORD, LPDWORD) PURE;
+    STDMETHOD(GetFormat)            (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
+    STDMETHOD(GetVolume)            (THIS_ LPLONG) PURE;
+    STDMETHOD(GetPan)               (THIS_ LPLONG) PURE;
+    STDMETHOD(GetFrequency)         (THIS_ LPDWORD) PURE;
+    STDMETHOD(GetStatus)            (THIS_ LPDWORD) PURE;
+    STDMETHOD(Initialize)           (THIS_ LPDIRECTSOUND, LPCDSBUFFERDESC) PURE;
+    STDMETHOD(Lock)                 (THIS_ DWORD, DWORD, LPVOID *, LPDWORD, LPVOID *, LPDWORD, DWORD) PURE;
+    STDMETHOD(Play)                 (THIS_ DWORD, DWORD, DWORD) PURE;
+    STDMETHOD(SetCurrentPosition)   (THIS_ DWORD) PURE;
+    STDMETHOD(SetFormat)            (THIS_ LPCWAVEFORMATEX) PURE;
+    STDMETHOD(SetVolume)            (THIS_ LONG) PURE;
+    STDMETHOD(SetPan)               (THIS_ LONG) PURE;
+    STDMETHOD(SetFrequency)         (THIS_ DWORD) PURE;
+    STDMETHOD(Stop)                 (THIS) PURE;
+    STDMETHOD(Unlock)               (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
+    STDMETHOD(Restore)              (THIS) PURE;
+};
+
+#undef INTERFACE
+#define INTERFACE IDirectSound
+
+DECLARE_INTERFACE_(IDirectSound, IUnknown){
+
+    STDMETHOD(QueryInterface)       (THIS_ REFIID, LPVOID FAR *) PURE;
+    STDMETHOD_(ULONG,AddRef)        (THIS) PURE;
+    STDMETHOD_(ULONG,Release)       (THIS) PURE;
+    
+    STDMETHOD(CreateSoundBuffer)    (THIS_ LPCDSBUFFERDESC, LPDIRECTSOUNDBUFFER *, LPUNKNOWN) PURE;
+    STDMETHOD(GetCaps)              (THIS_ LPDSCAPS) PURE;
+    STDMETHOD(DuplicateSoundBuffer) (THIS_ LPDIRECTSOUNDBUFFER, LPDIRECTSOUNDBUFFER *) PURE;
+    STDMETHOD(SetCooperativeLevel)  (THIS_ HWND, DWORD) PURE;
+    STDMETHOD(Compact)              (THIS) PURE;
+    STDMETHOD(GetSpeakerConfig)     (THIS_ LPDWORD) PURE;
+    STDMETHOD(SetSpeakerConfig)     (THIS_ DWORD) PURE;
+    STDMETHOD(Initialize)           (THIS_ LPGUID) PURE;
+};
+
+
+#undef INTERFACE
+#define INTERFACE IDirectSoundNotify
+
+DECLARE_INTERFACE_(IDirectSoundNotify, IUnknown)
+{
+    // IUnknown methods
+    STDMETHOD(QueryInterface)           (THIS_ REFIID, LPVOID *) PURE;
+    STDMETHOD_(ULONG,AddRef)            (THIS) PURE;
+    STDMETHOD_(ULONG,Release)           (THIS) PURE;
+
+    // IDirectSoundNotify methods
+    STDMETHOD(SetNotificationPositions) (THIS_ DWORD dwPositionNotifies, LPCDSBPOSITIONNOTIFY pcPositionNotifies) PURE;
+};
+
+const IID IID_IDirectSoundNotify={0xb0210783,0x89cd,0x11d0,{0xaf,0x8,0x0,0xa0,0xc9,0x25,0xcd,0x16}};
+
+#endif