DSBuffer.h
上传用户:sdpcwz
上传日期:2009-12-14
资源大小:1237k
文件大小:2k
- // DSBuffer.h : Definition of CDSBuffer class
- //
- #if !defined(AFX_DSBUFFER_H__7517D749_96E3_11D2_BBF3_9EB4940D843C__INCLUDED_)
- #define AFX_DSBUFFER_H__7517D749_96E3_11D2_BBF3_9EB4940D843C__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include <mmsystem.h>
- #include <dsound.h>
- //设置如下两个全局变量控制音量:
- extern int m_nBkGrdVolume; //用于控制背景音乐音量大小
- extern int m_nYinXiaoVolume; //用于控制音效音量大小
- //wav文件头格式
- struct WaveHeader
- {
- BYTE RIFF[4]; // "RIFF"
- DWORD dwSize; // Size of data to follow
- BYTE WAVE[4]; // "WAVE"
- BYTE fmt_[4]; // "fmt "
- DWORD dw16; // 16
- WORD wOne_0; // 1
- WORD wChnls; // Number of Channels
- DWORD dwSRate; // Sample Rate
- DWORD BytesPerSec; // Sample Rate
- WORD wBlkAlign; // 1
- WORD BitsPerSample; // Sample size
- BYTE DATA[4]; // "DATA"
- DWORD dwDSize; // Number of Samples
- };
- class CDSBuffer : public CObject
- {
- // Attribute
- protected:
- LPDIRECTSOUNDBUFFER m_lpDSBuffer; // 声音缓冲区对象
- public:
- CDSBuffer();
- CDSBuffer(const char* FileName,BOOL m_bBackGroundMusic,LPDIRECTSOUND lpDS,DWORD dwFlags = DSBCAPS_CTRLVOLUME );
- ~CDSBuffer();
- public:
- BOOL PlaySound(BOOL bContinue=FALSE); //播放声音
- BOOL StopSound(); //停止播放
- BOOL CreateSoundBuffer(LPDIRECTSOUND lpDS, DWORD dwFlags, DWORD dwBufSize, DWORD dwFreq, DWORD dwBitsPerSample, DWORD dwBlkAlign, BOOL bStereo);
- BOOL ReadData(FILE* pFile, DWORD dwSize, DWORD dwPos);
- BOOL IsValid();
- LPDIRECTSOUNDBUFFER GetBuffer() { return m_lpDSBuffer;}
- void SetVolume(int percent=50); //设置音量
- void VolumeDown(int percent=10); //音量增大(percent为百分数,范围为
- void VolumeUp(int percent=10); //音量减小 1~100)
-
- private:
- BOOL m_bBkGrdMusic; //是否是背景音乐,TRUE为是
- };
- #endif // !defined(AFX_DSBUFFER_H__7517D749_96E3_11D2_BBF3_9EB4940D843C__INCLUDED_)