Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

output_ds.hpp

Go to the documentation of this file.
00001 #ifndef OUTPUT_DS_HPP
00002 #define OUTPUT_DS_HPP
00003 
00004 
00005 // disable 'identifier too long' warning
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;  // in milliseconds
00040 
00041   HWND m_AnonymousWindow;
00042 
00043 
00044   // these must be overridden
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,   // in bytes
00060     int buffer_length, // in samples
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   // returns true if |position| is between |start| (inclusive) and
00077   // |end| (exclusive) in the buffer
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;  // in samples
00085   int m_NextRead;  // offset (in samples) where we will read next
00086 
00087   ISampleSource* m_Source;
00088   int m_SampleSize;  // convenience: bits per sample * channel count / 8
00089 
00090   int m_Volume;
00091   BYTE* m_LastSample; // the last sample read (used for clickless silence)
00092 
00093   friend class DSOutputContext;
00094 };
00095 
00096 
00097 #endif

Generated at Mon Jun 10 02:55:12 2002 for audiere by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001