| 1 | /* $Id: DAudioBuffer.h,v 1.2 2001-04-30 21:06:37 sandervl Exp $ */
 | 
|---|
| 2 | 
 | 
|---|
| 3 | /*
 | 
|---|
| 4 |  * DirectSound SoundBuffer class (DAudio)
 | 
|---|
| 5 |  *
 | 
|---|
| 6 |  * Copyright 1998-2001 Sander van Leeuwen (sandervl@xs4all.nl)
 | 
|---|
| 7 |  *
 | 
|---|
| 8 |  * Project Odin Software License can be found in LICENSE.TXT
 | 
|---|
| 9 |  *
 | 
|---|
| 10 |  */
 | 
|---|
| 11 | #ifndef __DAUDIOBUFFER_H__
 | 
|---|
| 12 | #define __DAUDIOBUFFER_H__
 | 
|---|
| 13 | 
 | 
|---|
| 14 | #include "os2sndbuffer.h"
 | 
|---|
| 15 | #include <vmutex.h>
 | 
|---|
| 16 | #include "waveoutdaud.h"
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #undef THIS
 | 
|---|
| 19 | #define THIS VOID*This
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #undef THIS_
 | 
|---|
| 22 | #define THIS_ VOID*This,
 | 
|---|
| 23 | 
 | 
|---|
| 24 | // a forward declaration of some classes is needed here!
 | 
|---|
| 25 | class IDirectAudioNotify;
 | 
|---|
| 26 | class OS2IDirectSound3DBuffer;
 | 
|---|
| 27 | class OS2IDirectSound;
 | 
|---|
| 28 | 
 | 
|---|
| 29 | class IDirectAudioBuffer
 | 
|---|
| 30 | {
 | 
|---|
| 31 |  public:
 | 
|---|
| 32 |     //this one has to go first!
 | 
|---|
| 33 |     IDirectSoundBufferVtbl *lpVtbl;
 | 
|---|
| 34 |     IDirectSoundBufferVtbl  Vtbl;
 | 
|---|
| 35 | 
 | 
|---|
| 36 |     IDirectAudioBuffer(OS2IDirectSound *DSound, const DSBUFFERDESC *lpDSBufferDesc);
 | 
|---|
| 37 |     IDirectAudioBuffer(OS2IDirectSound *DSound, IDirectAudioBuffer *srcBuf);
 | 
|---|
| 38 |     IDirectAudioBuffer() {};
 | 
|---|
| 39 |     ~IDirectAudioBuffer();
 | 
|---|
| 40 | 
 | 
|---|
| 41 |     static void DestroyAllBuffers(); // called when DSound is closed
 | 
|---|
| 42 | 
 | 
|---|
| 43 |     int     Referenced;
 | 
|---|
| 44 |     inline  HRESULT       GetLastError()    { return lastError;    };
 | 
|---|
| 45 |     inline  void          SetNotify(IDirectAudioNotify *_notify) {
 | 
|---|
| 46 |                           notify = _notify; };
 | 
|---|
| 47 |     inline  void          Set3DBuffer(OS2IDirectSound3DBuffer *_buffer3D) {
 | 
|---|
| 48 |                           buffer3D = _buffer3D; };
 | 
|---|
| 49 | 
 | 
|---|
| 50 |     HRESULT QueryInterface(REFIID riid, LPVOID * ppvObj);
 | 
|---|
| 51 |     ULONG   AddRef();
 | 
|---|
| 52 |     ULONG   Release();
 | 
|---|
| 53 |     HRESULT GetCaps(LPDSBCAPS );
 | 
|---|
| 54 |     HRESULT GetCurrentPosition(LPDWORD,LPDWORD ) ;
 | 
|---|
| 55 |     HRESULT GetFormat(LPWAVEFORMATEX, DWORD, LPDWORD ) ;
 | 
|---|
| 56 |     HRESULT GetVolume(LPLONG ) ;
 | 
|---|
| 57 |     HRESULT GetPan(LPLONG ) ;
 | 
|---|
| 58 |     HRESULT GetFrequency(LPDWORD ) ;
 | 
|---|
| 59 |     HRESULT GetStatus(LPDWORD ) ;
 | 
|---|
| 60 |     HRESULT Initialize(LPDIRECTSOUND, LPDSBUFFERDESC ) ;
 | 
|---|
| 61 |     HRESULT Lock(DWORD,DWORD,LPVOID,LPDWORD,LPVOID,LPDWORD,DWORD ) ;
 | 
|---|
| 62 |     HRESULT Play(DWORD,DWORD,DWORD ) ;
 | 
|---|
| 63 |     HRESULT SetCurrentPosition(DWORD ) ;
 | 
|---|
| 64 |     HRESULT SetFormat(LPWAVEFORMATEX ) ;
 | 
|---|
| 65 |     HRESULT SetVolume(LONG ) ;
 | 
|---|
| 66 |     HRESULT SetPan(LONG ) ;
 | 
|---|
| 67 |     HRESULT SetFrequency( DWORD ) ;
 | 
|---|
| 68 |     HRESULT Stop() ;
 | 
|---|
| 69 |     HRESULT Unlock( LPVOID,DWORD,LPVOID,DWORD ) ;
 | 
|---|
| 70 |     HRESULT Restore() ;
 | 
|---|
| 71 | 
 | 
|---|
| 72 |  private:
 | 
|---|
| 73 |     void    initVtbl();
 | 
|---|
| 74 | 
 | 
|---|
| 75 |  protected:
 | 
|---|
| 76 |     HRESULT lastError;
 | 
|---|
| 77 | 
 | 
|---|
| 78 |     ULONG writepos, playpos;   // DSound write and play cursors
 | 
|---|
| 79 |     ULONG frequency;           // DSB frequency - may differ from source sample
 | 
|---|
| 80 |     WAVEFORMATEX *lpfxFormat;  // source sample format
 | 
|---|
| 81 |     ULONG status;              // DSB status - playing, looping etc.
 | 
|---|
| 82 |     BOOL  fLocked;             // is buffer currently locked?
 | 
|---|
| 83 |     BOOL  fPrimary;            // is this a primary buffer?
 | 
|---|
| 84 |     LONG  DSvolume;            // DSB volume (in dB)
 | 
|---|
| 85 |     LONG  volume;              // volume (linear)
 | 
|---|
| 86 |     LONG  DSpan;               // DSB pan (in dB)
 | 
|---|
| 87 |     LONG  pan;                 // pan (linear)
 | 
|---|
| 88 |     BOOL  fPlaying,fLoop;      // is buffer playing/looping?
 | 
|---|
| 89 |     DSBUFFERDESC bufferdesc;   // DSB description
 | 
|---|
| 90 |     LONG  frac;                // saved mixer position overflow
 | 
|---|
| 91 | 
 | 
|---|
| 92 |     SOUNDBUF *lpSndBuffer;     // sound data + reference count
 | 
|---|
| 93 |     char     *lpBuffer;        // actual sound data
 | 
|---|
| 94 | 
 | 
|---|
| 95 |     IDirectAudioNotify*   notify;    // pointer to the associated Notify object (if exists)
 | 
|---|
| 96 |     OS2IDirectSound3DBuffer* buffer3D;  // pointer to the associated 3DBuffer object (if exists)
 | 
|---|
| 97 |     OS2IDirectSound*         parentDS;
 | 
|---|
| 98 | 
 | 
|---|
| 99 |     DAudioWaveOut           *daudio;
 | 
|---|
| 100 | 
 | 
|---|
| 101 |     VMutex                   wmutex;
 | 
|---|
| 102 | 
 | 
|---|
| 103 |               // Linked list management
 | 
|---|
| 104 |               IDirectAudioBuffer* next;                   // Next OS2IDirectSoundBuffer
 | 
|---|
| 105 |     static    IDirectAudioBuffer* dsbroot;                // List of OS2IDirectSoundBuffers
 | 
|---|
| 106 |     static    IDirectAudioBuffer* primary;                // The primary SoundBuffer
 | 
|---|
| 107 | };
 | 
|---|
| 108 | //******************************************************************************
 | 
|---|
| 109 | //******************************************************************************
 | 
|---|
| 110 | HRESULT WINAPI DAudioBufQueryInterface(THIS, REFIID riid, LPVOID * ppvObj);
 | 
|---|
| 111 | ULONG   WINAPI DAudioBufAddRef(THIS);
 | 
|---|
| 112 | ULONG   WINAPI DAudioBufRelease(THIS);
 | 
|---|
| 113 | HRESULT WINAPI DAudioBufGetCaps(THIS_ LPDSBCAPS );
 | 
|---|
| 114 | HRESULT WINAPI DAudioBufGetCurrentPosition(THIS_ LPDWORD,LPDWORD ) ;
 | 
|---|
| 115 | HRESULT WINAPI DAudioBufGetFormat(THIS_ LPWAVEFORMATEX, DWORD, LPDWORD ) ;
 | 
|---|
| 116 | HRESULT WINAPI DAudioBufGetVolume(THIS_ LPLONG ) ;
 | 
|---|
| 117 | HRESULT WINAPI DAudioBufGetPan(THIS_ LPLONG ) ;
 | 
|---|
| 118 | HRESULT WINAPI DAudioBufGetFrequency(THIS_ LPDWORD ) ;
 | 
|---|
| 119 | HRESULT WINAPI DAudioBufGetStatus(THIS_ LPDWORD ) ;
 | 
|---|
| 120 | HRESULT WINAPI DAudioBufInitialize(THIS_ LPDIRECTSOUND, LPDSBUFFERDESC ) ;
 | 
|---|
| 121 | HRESULT WINAPI DAudioBufLock(THIS_ DWORD,DWORD,LPVOID,LPDWORD,LPVOID,LPDWORD,DWORD ) ;
 | 
|---|
| 122 | HRESULT WINAPI DAudioBufPlay(THIS_ DWORD,DWORD,DWORD ) ;
 | 
|---|
| 123 | HRESULT WINAPI DAudioBufSetCurrentPosition(THIS_ DWORD ) ;
 | 
|---|
| 124 | HRESULT WINAPI DAudioBufSetFormat(THIS_ LPWAVEFORMATEX ) ;
 | 
|---|
| 125 | HRESULT WINAPI DAudioBufSetVolume(THIS_ LONG ) ;
 | 
|---|
| 126 | HRESULT WINAPI DAudioBufSetPan(THIS_ LONG ) ;
 | 
|---|
| 127 | HRESULT WINAPI DAudioBufSetFrequency(THIS_ DWORD ) ;
 | 
|---|
| 128 | HRESULT WINAPI DAudioBufStop(THIS  ) ;
 | 
|---|
| 129 | HRESULT WINAPI DAudioBufUnlock(THIS_ LPVOID,DWORD,LPVOID,DWORD ) ;
 | 
|---|
| 130 | HRESULT WINAPI DAudioBufRestore(THIS  ) ;
 | 
|---|
| 131 | 
 | 
|---|
| 132 | #endif
 | 
|---|