00001
#ifndef DSOUND_HELPERS
00002 #define DSOUND_HELPERS 1
00003
00004
#if defined(_WINDOWS)
00005
#include "windows.h"
00006
#include "wtypes.h"
00007
#endif
00008
00009
struct IDirectSound;
00010
struct IDirectSoundBuffer;
00011
00012 class DSound
00013 {
00014 IDirectSound *
ds;
00015
static BOOL CALLBACK
EnumCallback( LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext);
00016
00017
void SetPrimaryBufferMode();
00018
00019
public:
00020 IDirectSound *
GetDS()
const {
return ds; }
00021
bool IsEmulated() const;
00022
00023
DSound();
00024 ~
DSound();
00025 CString Init();
00026 };
00027
00028 class
DSoundBuf
00029 {
00030
public:
00031 enum hw { HW_HARDWARE, HW_SOFTWARE, HW_DONT_CARE };
00032
00033
00034
00035
enum { DYNAMIC_SAMPLERATE = -1 };
00036
00037 DSoundBuf();
00038
CString Init(
DSound &ds, hw hardware,
00039
int channels,
int samplerate,
int samplebits,
int writeahead );
00040
00041
bool get_output_buf(
char **buffer,
unsigned *bufsiz,
int chunksize);
00042
void release_output_buf(
char *buffer,
unsigned bufsiz);
00043
00044
void Play();
00045
void Stop();
00046
void SetVolume(
float vol);
00047
void SetSampleRate(
int hz);
00048 int GetSampleRate() {
return samplerate; }
00049
00050 ~DSoundBuf();
00051 int64_t GetPosition() const;
00052 int64_t GetOutputPosition()
const {
return write_cursor_pos; }
00053
00054
private:
00055 int buffersize_frames()
const {
return buffersize /
bytes_per_frame(); }
00056 int bytes_per_frame()
const {
return channels*samplebits/8; }
00057
00058
void CheckWriteahead(
int cursorstart,
int cursorend );
00059
void CheckUnderrun(
int cursorstart,
int cursorend );
00060
00061 IDirectSoundBuffer *buf;
00062
00063 int channels,
samplerate, samplebits, writeahead;
00064 int volume;
00065
00066 int buffersize;
00067
00068 int write_cursor, buffer_bytes_filled;
00069 int extra_writeahead;
00070 int64_t write_cursor_pos;
00071 mutable int64_t LastPosition;
00072 bool playing;
00073
00074 bool buffer_locked;
00075 char *locked_buf1, *locked_buf2;
00076 int locked_size1, locked_size2;
00077 char *temp_buffer;
00078
00079 int last_cursors[4][2];
00080 };
00081
00082
#endif
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107