Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

DSoundHelpers.h

Go to the documentation of this file.
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 /* If samplerate is DYNAMIC_SAMPLERATE, then call SetSampleRate before 00034 * you use the sample. */ 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; /* bytes */ 00069 int extra_writeahead; 00070 int64_t write_cursor_pos; /* frames */ 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 * (c) 2002-2004 Glenn Maynard 00086 * All rights reserved. 00087 * 00088 * Permission is hereby granted, free of charge, to any person obtaining a 00089 * copy of this software and associated documentation files (the 00090 * "Software"), to deal in the Software without restriction, including 00091 * without limitation the rights to use, copy, modify, merge, publish, 00092 * distribute, and/or sell copies of the Software, and to permit persons to 00093 * whom the Software is furnished to do so, provided that the above 00094 * copyright notice(s) and this permission notice appear in all copies of 00095 * the Software and that both the above copyright notice(s) and this 00096 * permission notice appear in supporting documentation. 00097 * 00098 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00099 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00100 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00101 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00102 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00103 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00104 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00105 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00106 * PERFORMANCE OF THIS SOFTWARE. 00107 */

Generated on Thu Jan 27 20:57:19 2005 for StepMania by doxygen 1.3.7