00001 #ifndef OUTPUT_DS_HPP
00002 #define OUTPUT_DS_HPP
00003
00004
00005
00006 #ifdef _MSC_VER
00007 #pragma warning(disable : 4786)
00008 #endif
00009
00010
00011 #include <windows.h>
00012 #include <mmreg.h>
00013 #include <dsound.h>
00014 #include <list>
00015 #include "output.hpp"
00016
00017
00018 class DSOutputStream;
00019
00020
00021 class DSOutputContext : public IOutputContext
00022 {
00023 public:
00024 DSOutputContext();
00025 ~DSOutputContext();
00026
00027 bool Initialize(const char* parameters);
00028 void Update();
00029 IOutputStream* OpenStream(ISampleSource* source);
00030
00031 private:
00032 typedef std::list<DSOutputStream*> StreamList;
00033
00034 void RemoveStream(DSOutputStream* stream);
00035
00036 IDirectSound* m_DirectSound;
00037 StreamList m_OpenStreams;
00038
00039 int m_BufferLength;
00040
00041 HWND m_AnonymousWindow;
00042
00043
00044
00045 virtual REFCLSID GetCLSID() = 0;
00046 virtual DWORD GetCooperativeLevel() = 0;
00047 virtual bool CreatePrimarySoundBuffer(IDirectSound* ds) = 0;
00048
00049 friend class DSOutputStream;
00050 };
00051
00052
00053 class DSOutputStream : public IOutputStream
00054 {
00055 private:
00056 DSOutputStream(
00057 DSOutputContext* context,
00058 IDirectSoundBuffer* buffer,
00059 int sample_size,
00060 int buffer_length,
00061 ISampleSource* source);
00062 ~DSOutputStream();
00063
00064 public:
00065 void Play();
00066 void Stop();
00067 void Reset();
00068 bool IsPlaying();
00069 void SetVolume(int volume);
00070 int GetVolume();
00071
00072 void FillStream();
00073 void Update();
00074 int StreamRead(int samples_to_read, void* buffer);
00075
00076
00077
00078 bool IsBetween(int position, int start, int end);
00079
00080 private:
00081 DSOutputContext* m_Context;
00082
00083 IDirectSoundBuffer* m_Buffer;
00084 int m_BufferLength;
00085 int m_NextRead;
00086
00087 ISampleSource* m_Source;
00088 int m_SampleSize;
00089
00090 int m_Volume;
00091 BYTE* m_LastSample;
00092
00093 friend class DSOutputContext;
00094 };
00095
00096
00097 #endif