00001 #ifndef MIXER_H 00002 #define MIXER_H 00003 00004 00005 #ifdef _MSC_VER 00006 #pragma warning(disable : 4786) 00007 #endif 00008 00009 00010 #include <list> 00011 #include "audiere.h" 00012 #include "device.h" 00013 #include "resampler.h" 00014 #include "threads.h" 00015 #include "types.h" 00016 #include "utility.h" 00017 00018 00019 namespace audiere { 00020 00021 class MixerStream; 00022 00023 00025 class MixerDevice : public AbstractDevice, public Mutex { 00026 public: 00027 MixerDevice(int rate); 00028 00029 // update() must be implementated by the specific device to call read() 00030 // and write the samples to the output device. 00031 00032 OutputStream* ADR_CALL openStream(SampleSource* source); 00033 00034 OutputStream* ADR_CALL openBuffer( 00035 void* samples, 00036 int frame_count, 00037 int channel_count, 00038 int sample_rate, 00039 SampleFormat sample_format); 00040 00041 protected: 00042 int read(int sample_count, void* samples); 00043 00044 private: 00045 std::list<MixerStream*> m_streams; 00046 int m_rate; 00047 00048 friend class MixerStream; 00049 }; 00050 00051 00052 class MixerStream : public RefImplementation<OutputStream> { 00053 public: 00054 MixerStream(MixerDevice* device, SampleSource* source, int rate); 00055 ~MixerStream(); 00056 00057 void ADR_CALL play(); 00058 void ADR_CALL stop(); 00059 bool ADR_CALL isPlaying(); 00060 void ADR_CALL reset(); 00061 00062 void ADR_CALL setRepeat(bool repeat); 00063 bool ADR_CALL getRepeat(); 00064 void ADR_CALL setVolume(float volume); 00065 float ADR_CALL getVolume(); 00066 void ADR_CALL setPan(float pan); 00067 float ADR_CALL getPan(); 00068 void ADR_CALL setPitchShift(float shift); 00069 float ADR_CALL getPitchShift(); 00070 00071 bool ADR_CALL isSeekable(); 00072 int ADR_CALL getLength(); 00073 void ADR_CALL setPosition(int position); 00074 int ADR_CALL getPosition(); 00075 00076 private: 00077 void read(int frame_count, s16* buffer); 00078 00079 private: 00080 RefPtr<MixerDevice> m_device; 00081 00082 RefPtr<Resampler> m_source; 00083 s16 m_last_l; 00084 s16 m_last_r; 00085 bool m_is_playing; 00086 int m_volume; 00087 int m_pan; 00088 00089 friend class MixerDevice; 00090 }; 00091 00092 } 00093 00094 #endif