📄 wavdrv.h
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// -----------------------------------------------------------------------------
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// -----------------------------------------------------------------------------
//
// Module Name:
//
// wavdrv.h
//
// Abstract:
//
// Functions:
//
// Notes:
//
// -----------------------------------------------------------------------------
#ifndef __WAVDRV_H__
#define __WAVDRV_H__
//
// Includes common to all the wave driver files.
//
#include <windows.h>
#include <wavedev.h>
#include <mmddk.h>
#include <mmreg.h>
#include "debug.h"
#include "wavhdrq.h"
#include "cregkey.h"
#include "es1371.h"
#define DEVICE_NAME L"Creative ES1371"
#define DRIVER_VERSION 0x100
#define MMFAILED(mmresult) ((mmresult)!=MMSYSERR_NOERROR)
#define VOLUME_MIN -10000
typedef class CDriverContext * PDriverContext, * HDRIVER;
typedef class CStreamContext * PStreamContext, * HSTREAM;
// Mixer API structures
typedef struct tagMXCONTROLSTATE
{
union {
USHORT us;
DWORD dw;
BOOL b;
} uSetting;
BOOL fVirtualized; // this control is virtualized by a mux
} * PMXCONTROLSTATE, MXCONTROLSTATE;
typedef struct tagMXLINESTATE {
DWORD dwState;
} * PMXLINESTATE, MXLINESTATE;
/////////////////////////////////////////////////////////////////////////////
// class: CDriverContext
// Driver Context Data
//
// This class abstracts the notion of a device driver instance. Each instance
// of the driver (WAV1, WAV2) gets one of these.
// A fully general driver that supports multiple physical devices (e.g. two
// separate PCI cards, one appearing as WAV1 and the other as WAV2)
// should create separate CDriverContext objects for each driver instance.
//
// There's an important distinction between physical devices that are exposed to
// the Device Manager and separate waveform devices as understood by
// the waveform API. Consider the hypothetical case of a PCI audio adapter
// that has two separate stereo channels (e.g. Speaker A, Speaker B).
// The Windows CE Device Manager will view this a single physical device
// but the waveform API will treat each speaker set a separate waveform
// device.
//
/////////////////////////////////////////////////////////////////////////////
class CIndexable // helper class for stream table
{
protected:
ULONG index;
friend class CDriverContext;
};
typedef DWORD MIXHANDLE;
typedef struct _tagMCB MIXER_CALLBACK, * PMIXER_CALLBACK;
class CDriverContext
{
public:
CDriverContext (void);
~CDriverContext ();
DWORD WaveMessage(PMMDRV_MESSAGE_PARAMS pParams);
DWORD MixerMessage(PMMDRV_MESSAGE_PARAMS pParams);
BOOL Initialize (PCTSTR pszActiveKey);
MMRESULT GetCaps (ULONG msg, PWAVEOUTCAPS pCaps);
MMRESULT GetExtCaps (PWAVEOUTEXTCAPS pCaps);
MMRESULT GetVolume (PULONG pulVolume);
MMRESULT SetVolume (ULONG ulVolume);
MMRESULT OpenStream (ULONG msg, HSTREAM * ppStream, LPWAVEOPENDESC pWOD, DWORD dwFlags);
MMRESULT GetMixerCaps(PMIXERCAPS pCaps);
MMRESULT OpenMixerHandle(PDWORD phmix, PMIXEROPENDESC pMOD, DWORD dwFlags); //mixerOpen
MMRESULT CloseMixerHandle( MIXHANDLE mxh); // mixerClose
MMRESULT GetMixerLineControls ( PMIXERLINECONTROLS pmxlc, DWORD dwFlags); // mixerGetLineControls
MMRESULT GetMixerLineInfo( PMIXERLINE pmxl, DWORD dwFlags); // mixerGetLineInfo
MMRESULT GetMixerControlDetails( PMIXERCONTROLDETAILS pmxcd, DWORD dwFlags); // mixerGetControlDetails
MMRESULT SetMixerControlDetails( PMIXERCONTROLDETAILS pmxcd, DWORD dwFlags); // mixerSetControlDetails
// power management support
void PowerUp (void);
void PowerDown (void);
private:
// Device configuration
CRegKey * m_pRegKey;
// data members
CES1371 * m_pDevice;
ULONG m_ulBufferSize; // required DMA buffer size, in bytes
ULONG m_ulVolume;
// mixer driver support
PMIXER_CALLBACK m_pHead;
PMXLINESTATE m_pMxLineState;
PMXCONTROLSTATE m_pMxControlState;
BOOL InitializeMixerState (void);
void PerformMixerCallbacks(DWORD dwMessage, DWORD dwId);
MYTHIS_DECLARATION;
};
/////////////////////////////////////////////////////////////////////////////
// class: CStreamContext
// Stream Context Data
//
// This class provides the driver-level implementation of waveform handles
// (HWAVEOUT and HWAVEIN). When an application invokes waveOutOpen or
// waveInOpen, the driver respondes by create a CStreamContext object.
// For the typical audio adapter, the driver will support two CStreamContext
// objects, one for input and one for output.
// For devices that support mixing of multiple sources, the driver can
// allow more than one output stream to be created a time.
//
// A Stream Context consists, fundamentally, of two parts, a queue of
// Wave headers and a DMA channel of some sort.
// The Wave Header Queue is essentially device-independent and is
// implemented in the CWavehdrQueue class.
// The DMA channel support is device-specific and will have to be
// adapted to each device's programming model.
//
/////////////////////////////////////////////////////////////////////////////
class CStreamContext : public CIndexable
{
public:
CStreamContext (BOOL fPlayback, BOOL fPaused);
~CStreamContext ();
MMRESULT Initialize (CES1371 * pDevice, ULONG ulChannelIndex, LPWAVEOPENDESC pWOD);
void AddRef (void);
void Release (void);
// waveapi methods
MMRESULT PrepareHeader (LPWAVEHDR lpHeader);
MMRESULT UnprepareHeader (LPWAVEHDR lpHeader);
MMRESULT AddBuffer (LPWAVEHDR lpHeader); // aka waveOutWrite()
MMRESULT Unpause (void); // aka waveOutRestart()
MMRESULT Pause (void); // aka waveOutPause()
MMRESULT GetPosition (LPMMTIME lpMMTime);
MMRESULT Close (void);
MMRESULT Reset (void);
MMRESULT BreakLoop (void);
MMRESULT GetPlaybackRate (PULONG pulRate);
MMRESULT SetPlaybackRate (ULONG ulRate);
MMRESULT GetVolume (PULONG pulVolume);
MMRESULT SetVolume (ULONG ulVolume);
protected:
// internal methods
static VOID InterruptHandler (PVOID pThis);
virtual VOID HandleInterrupt (void) = 0; // called by the driver every so often to keep things moving
virtual VOID DoTransfer (PBYTE pBuffer, DWORD dwCount) = 0;
VOID DoSplitTransfer(DWORD dwSize);
VOID Start (void);
VOID Stop (void);
// buffer stuff
CES1371* m_pDevice; // Pointer to the ces1371 hw-driver class
ULONG m_ulDmaChannel; // The dma channel the buffer is associated with
DWORD m_dwInterruptInterval; // how many bytes between interrupt positions?
PBYTE m_pBufferBits; // DMA buffer address
DWORD m_dwBufferSize; // size of DMA buffer
DWORD m_dwBufferWrapTime; // how long it takes the DMA buffer to wrap
DWORD m_dwLastDMACursor; // last known position of the DMA cursor cursor
DWORD m_dwPreTime; // earliest possible time at which m_dwLastPlayCursor was accurate
DWORD m_dwTransferCursor; // the offset in the DMA buffer where we'll start the next transfer
// (will lag behind the silence pad if the header queue us running low)
LONG m_nBytesToTransfer; // tracks how much data to read/write from the DMA buffer.
UCHAR m_ucSilence; // 0 for 16-bit streams, 0x80 for 8-bit streams
DWORD m_dwVolume;
DWORD m_dwPlaybackRate; // 16:16 fixed point multiplier for m_wfx.nSampleRate
// stream stuff
CWavehdrQueue m_HdrQ; // device-independent WAVEHDR Queue
BOOL m_fStarted; // buffer is playing
BOOL m_fPaused; // Is stream paused?
WAVEFORMATEX m_wfx;
CRITICAL_SECTION m_cs;
BOOL m_fIsPlayback; // FALSE for capture, TRUE for playback
LONG m_lRefCount;
MYTHIS_DECLARATION;
};
class COutputStreamContext : public CStreamContext
{
public:
COutputStreamContext (void);
virtual void DoTransfer (PBYTE pBuffer, DWORD dwCount);
virtual void HandleInterrupt (void); // called by the driver every so often to keep things moving
void GetAdvance(DWORD &dwAdvance, DWORD &dwRoomInBuffer);
};
class CInputStreamContext : public CStreamContext
{
public:
CInputStreamContext (void);
virtual void DoTransfer (PBYTE pBuffer, DWORD dwCount);
virtual void HandleInterrupt (void); // called by the driver every so often to keep things moving
void GetAdvance(DWORD & dwAdvance);
};
// CAutoLock helper class
class CAutoLock
{
public:
CAutoLock (CRITICAL_SECTION * cs)
{
pcs = cs;
EnterCriticalSection(pcs);
}
~CAutoLock ()
{
LeaveCriticalSection(pcs);
}
private:
CRITICAL_SECTION * pcs;
};
#endif // __WAVDRV_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -