📄 waveout.h
字号:
#ifndef _WAVEOUT_H_
#define _WAVEOUT_H_
#define HERTZ_POOR 8000
#define HERTZ_LOW 11025
#define HERTZ_NORMAL 22050
#define HERTZ_HIGH 44100
#define PLAY_DELAY 5
#include <mmsystem.h>
#include <afxmt.h>
//音频输出(播放数字音频)-将音频数据在硬件上进行播放
class CWaveOut
{
private:
static void CALLBACK waveOutProc(HWAVEOUT hwo,UINT uMsg,DWORD dwInstance,DWORD dwParam1,DWORD dwParam2);
private:
WAVEOUTCAPS waveCaps;
BOOL bDevOpen;
HWAVEOUT m_hWave;
private:
WORD nChannels;
DWORD dwHertZ;
WORD wBits;
private:
CCriticalSection m_Lock;
int m_BufferQueue;
inline int GetBufferNum();
inline void AddBuffer();
inline void SubBuffer();
private:
BOOL Open();
void Close();
public:
CWaveOut();
~CWaveOut();
//check
public:
BOOL IsExistDevice();
WAVEOUTCAPS* GetDeviceCap();
//setting
public:
enum CHANNEL { SINGLE , STEREO };
inline void SetChannel(CHANNEL Channel);
inline void SetHertZ(DWORD HertZ);
inline void SetBit(WORD Bits);
//operation
public:
BOOL Start();
BOOL Play(char* buf,UINT nSize);
void Stop();
};
inline void CWaveOut::SetChannel(CHANNEL Channel)
{
switch( Channel )
{
case SINGLE:
nChannels = 1;
break;
case STEREO:
nChannels = 2;
break;
}
}
inline void CWaveOut::SetHertZ(DWORD HertZ)
{
dwHertZ = HertZ;
}
inline void CWaveOut::SetBit(WORD Bits)
{
wBits = Bits;
}
inline int CWaveOut::GetBufferNum()
{
int nRet = 5;
m_Lock.Lock();
nRet = m_BufferQueue;
m_Lock.Unlock();
return nRet;
}
inline void CWaveOut::AddBuffer()
{
m_Lock.Lock();
m_BufferQueue++;
m_Lock.Unlock();
}
inline void CWaveOut::SubBuffer()
{
m_Lock.Lock();
m_BufferQueue--;
m_Lock.Unlock();
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -