00001 #ifndef OUTPUT_AL_HPP
00002 #define OUTPUT_AL_HPP
00003
00004
00005 #include <list>
00006 #include <AL/al.h>
00007 #include <AL/alc.h>
00008 #include "input.hpp"
00009 #include "output.hpp"
00010
00011
00012
00013 #ifndef _WIN32
00014 typedef void ALCcontext;
00015 #endif
00016
00017
00018 class ALOutputStream;
00019
00020
00021 class ALOutputContext : public IOutputContext
00022 {
00023 public:
00024 ALOutputContext();
00025 ~ALOutputContext();
00026
00027 bool Initialize(const char* parameters);
00028 void Update();
00029 IOutputStream* OpenStream(ISampleSource* source);
00030
00031 private:
00032 ALCdevice* m_Device;
00033 ALCcontext* m_Context;
00034
00035 typedef std::list<ALOutputStream*> StreamList;
00036 StreamList m_OpenStreams;
00037
00038 friend class ALOutputStream;
00039 };
00040
00041
00042 class ALOutputStream : public IOutputStream
00043 {
00044 public:
00045 void Play();
00046 void Stop();
00047 void Reset();
00048 bool IsPlaying();
00049 void SetVolume(int volume);
00050 int GetVolume();
00051
00052 private:
00053 ALOutputStream(
00054 ALOutputContext* context,
00055 ISampleSource* source,
00056 ALuint al_source,
00057 ALuint* buffers,
00058 ALenum format,
00059 int sample_rate);
00060 ~ALOutputStream();
00061 void Update();
00062
00063 int Read(void* samples, int sample_count);
00064 void FillBuffers();
00065
00066 private:
00067 ALOutputContext* m_Context;
00068
00069
00070 ISampleSource* m_Source;
00071
00072
00073 ALenum m_Format;
00074 int m_SampleSize;
00075 int m_SampleRate;
00076
00077
00078 ALubyte* m_LastSample;
00079
00080
00081 ALuint m_ALSource;
00082 ALuint* m_Buffers;
00083
00084 int m_BufferLength;
00085 bool m_IsPlaying;
00086 int m_Volume;
00087
00088 friend class ALOutputContext;
00089 };
00090
00091
00092 #endif