2020-06-30 15:43:06 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "linux/windows/winbase.h"
|
|
|
|
#include "linux/windows/winerror.h"
|
2020-07-01 18:27:40 +01:00
|
|
|
#include "linux/windows/mmreg.h"
|
|
|
|
#include "linux/windows/guiddef.h"
|
2020-06-30 15:43:06 +01:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#define IID_IDirectSoundNotify 1234
|
|
|
|
#define DS_OK 0
|
|
|
|
#define DSBPN_OFFSETSTOP -1
|
|
|
|
|
|
|
|
#define DSBCAPS_CTRLVOLUME 0x00000080
|
|
|
|
#define DSBCAPS_LOCSOFTWARE 0x00000008
|
2020-07-01 18:27:40 +01:00
|
|
|
#define DSBCAPS_CTRLPOSITIONNOTIFY 0x00000100
|
|
|
|
#define DSBCAPS_STICKYFOCUS 0x00004000
|
|
|
|
#define DSBCAPS_GETCURRENTPOSITION2 0x00010000
|
2020-06-30 15:43:06 +01:00
|
|
|
|
|
|
|
#define DSBVOLUME_MIN -10000
|
|
|
|
#define DSBVOLUME_MAX 0
|
|
|
|
|
|
|
|
#define DSBPLAY_LOOPING 0x00000001
|
|
|
|
|
|
|
|
#define DSBSTATUS_PLAYING 0x00000001
|
|
|
|
#define DSBSTATUS_BUFFERLOST 0x00000002
|
|
|
|
#define DSBSTATUS_LOOPING 0x00000004
|
|
|
|
|
|
|
|
#define DSERR_BUFFERLOST MAKE_DSHRESULT(150)
|
|
|
|
|
|
|
|
#define DSBLOCK_ENTIREBUFFER 0x00000002
|
|
|
|
|
|
|
|
#define _FACDS 0x878
|
|
|
|
#define MAKE_DSHRESULT(code) MAKE_HRESULT(1,_FACDS,code)
|
|
|
|
|
2020-07-01 18:27:40 +01:00
|
|
|
#define DSSCL_NORMAL 1
|
|
|
|
|
|
|
|
typedef BOOL (CALLBACK *LPDSENUMCALLBACK)(LPGUID,LPCSTR,LPCSTR,LPVOID);
|
|
|
|
|
|
|
|
HRESULT DirectSoundEnumerate(LPDSENUMCALLBACK lpDSEnumCallback, LPVOID lpContext);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DWORD dwSize;
|
|
|
|
DWORD dwFlags;
|
|
|
|
DWORD dwFormats;
|
|
|
|
DWORD dwChannels;
|
|
|
|
} DSCCAPS, DSCAPS, *LPDSCCAPS;
|
|
|
|
|
|
|
|
typedef const DSCCAPS *LPCDSCCAPS;
|
|
|
|
|
|
|
|
typedef struct _DSBUFFERDESC
|
|
|
|
{
|
|
|
|
DWORD dwSize;
|
|
|
|
DWORD dwFlags;
|
|
|
|
DWORD dwBufferBytes;
|
|
|
|
DWORD dwReserved;
|
|
|
|
LPWAVEFORMATEX lpwfxFormat;
|
|
|
|
GUID guid3DAlgorithm;
|
|
|
|
} DSBUFFERDESC,*LPDSBUFFERDESC;
|
|
|
|
typedef const DSBUFFERDESC *LPCDSBUFFERDESC;
|
|
|
|
|
2020-06-30 15:43:06 +01:00
|
|
|
typedef struct _DSBPOSITIONNOTIFY
|
|
|
|
{
|
2020-07-01 18:27:40 +01:00
|
|
|
DWORD dwOffset;
|
|
|
|
HANDLE hEventNotify;
|
2020-06-30 15:43:06 +01:00
|
|
|
} DSBPOSITIONNOTIFY,*LPDSBPOSITIONNOTIFY;
|
|
|
|
typedef const DSBPOSITIONNOTIFY *LPCDSBPOSITIONNOTIFY;
|
|
|
|
|
|
|
|
struct IDirectSoundNotify
|
|
|
|
{
|
|
|
|
HRESULT SetNotificationPositions(DWORD cPositionNotifies, LPCDSBPOSITIONNOTIFY lpcPositionNotifies);
|
|
|
|
};
|
|
|
|
typedef struct IDirectSoundNotify *LPDIRECTSOUNDNOTIFY,**LPLPDIRECTSOUNDNOTIFY;
|
|
|
|
|
2020-07-01 18:27:40 +01:00
|
|
|
class IDirectSoundBuffer : public IUnknown
|
2020-06-30 15:43:06 +01:00
|
|
|
{
|
2020-07-01 18:27:40 +01:00
|
|
|
std::unique_ptr<IDirectSoundNotify> mySoundNotify;
|
2020-07-02 11:02:57 +01:00
|
|
|
std::vector<char> mySoundBuffer;
|
2020-06-30 15:43:06 +01:00
|
|
|
|
2020-07-01 18:27:40 +01:00
|
|
|
size_t myPlayPosition = 0;
|
|
|
|
size_t myWritePosition = 0;
|
|
|
|
WORD myStatus = 0;
|
2020-07-08 16:52:00 +01:00
|
|
|
LONG myVolume = DSBVOLUME_MAX;
|
2020-06-30 15:43:06 +01:00
|
|
|
|
2020-07-01 18:27:40 +01:00
|
|
|
public:
|
2020-07-02 11:02:57 +01:00
|
|
|
const size_t bufferSize;
|
|
|
|
const size_t sampleRate;
|
|
|
|
const size_t channels;
|
|
|
|
const size_t bitsPerSample;
|
|
|
|
const size_t flags;
|
|
|
|
|
2020-07-01 18:27:40 +01:00
|
|
|
IDirectSoundBuffer(const size_t bufferSize, const size_t channels, const size_t sampleRate, const size_t bitsPerSample, const size_t flags);
|
2021-01-31 13:55:43 +00:00
|
|
|
HRESULT Release() override;
|
2020-06-30 15:43:06 +01:00
|
|
|
|
|
|
|
HRESULT QueryInterface(int riid, void **ppvObject);
|
|
|
|
|
|
|
|
HRESULT SetCurrentPosition( DWORD dwNewPosition );
|
|
|
|
HRESULT GetCurrentPosition( LPDWORD lpdwCurrentPlayCursor, LPDWORD lpdwCurrentWriteCursor );
|
|
|
|
|
2020-07-02 11:02:57 +01:00
|
|
|
// Read is NOT part of Windows API
|
|
|
|
HRESULT Read( DWORD dwReadBytes, LPVOID * lplpvAudioPtr1, DWORD * lpdwAudioBytes1, LPVOID * lplpvAudioPtr2, DWORD * lpdwAudioBytes2);
|
2020-11-21 09:15:46 +00:00
|
|
|
DWORD GetBytesInBuffer() const;
|
2020-07-02 11:02:57 +01:00
|
|
|
|
2020-06-30 15:43:06 +01:00
|
|
|
HRESULT Lock( DWORD dwWriteCursor, DWORD dwWriteBytes, LPVOID * lplpvAudioPtr1, DWORD * lpdwAudioBytes1, LPVOID * lplpvAudioPtr2, DWORD * lpdwAudioBytes2, DWORD dwFlags );
|
|
|
|
HRESULT Unlock( LPVOID lpvAudioPtr1, DWORD dwAudioBytes1, LPVOID lpvAudioPtr2, DWORD dwAudioBytes2 );
|
|
|
|
|
|
|
|
HRESULT Stop();
|
|
|
|
HRESULT Play( DWORD dwReserved1, DWORD dwReserved2, DWORD dwFlags );
|
|
|
|
|
|
|
|
HRESULT SetVolume( LONG lVolume );
|
2020-07-01 18:27:40 +01:00
|
|
|
HRESULT GetVolume( LONG * lplVolume );
|
2020-06-30 15:43:06 +01:00
|
|
|
|
2020-11-14 20:02:04 +00:00
|
|
|
double GetLogarithmicVolume() const; // in [0, 1]
|
|
|
|
|
2020-06-30 15:43:06 +01:00
|
|
|
HRESULT GetStatus( LPDWORD lpdwStatus );
|
|
|
|
HRESULT Restore();
|
|
|
|
};
|
|
|
|
typedef struct IDirectSoundBuffer *LPDIRECTSOUNDBUFFER,**LPLPDIRECTSOUNDBUFFER;
|
2020-07-01 18:27:40 +01:00
|
|
|
|
|
|
|
struct IDirectSound : public IUnknown
|
|
|
|
{
|
|
|
|
HRESULT CreateSoundBuffer( LPCDSBUFFERDESC lpcDSBufferDesc, IDirectSoundBuffer **lplpDirectSoundBuffer, IUnknown FAR* pUnkOuter );
|
|
|
|
HRESULT SetCooperativeLevel( HWND hwnd, DWORD dwLevel );
|
|
|
|
HRESULT GetCaps(LPDSCCAPS pDSCCaps);
|
|
|
|
};
|
|
|
|
typedef struct IDirectSound *LPDIRECTSOUND;
|
|
|
|
|
|
|
|
HRESULT WINAPI DirectSoundCreate(LPGUID lpGuid, LPDIRECTSOUND* ppDS, LPUNKNOWN pUnkOuter);
|