00001 #ifndef DEVICE_OAL_H
00002 #define DEVICE_OAL_H
00003
00004
00005 #include <list>
00006 #include <AL/al.h>
00007 #include <AL/alc.h>
00008 #include "audiere.h"
00009 #include "internal.h"
00010 #include "utility.h"
00011
00012
00013 namespace audiere {
00014
00015 class OALOutputStream;
00016
00017
00018 class OALAudioDevice : public RefImplementation<AudioDevice> {
00019 public:
00020 static OALAudioDevice* create(const ParameterList& list);
00021
00022 private:
00023 OALAudioDevice(ALCdevice* device, ALCcontext* context);
00024 ~OALAudioDevice();
00025
00026 public:
00027 void update();
00028 OutputStream* openStream(SampleSource* source);
00029 OutputStream* openBuffer(
00030 void* samples, int frame_count,
00031 int channel_count, int sample_rate, SampleFormat sample_format);
00032
00033 private:
00034 void removeStream(OALOutputStream* stream);
00035
00036 ALCdevice* m_device;
00037 ALCcontext* m_context;
00038
00039 typedef std::list<OALOutputStream*> StreamList;
00040 StreamList m_open_streams;
00041
00042 friend class OALOutputStream;
00043 };
00044
00045
00046 class OALOutputStream : public RefImplementation<OutputStream> {
00047 public:
00048 void play();
00049 void stop();
00050 bool isPlaying();
00051 void reset();
00052 void setRepeat(bool repeat);
00053 bool getRepeat();
00054 void setVolume(float volume);
00055 float getVolume();
00056 void setPan(float pan);
00057 float getPan();
00058 void setPitchShift(float shift);
00059 float getPitchShift();
00060
00061 bool isSeekable();
00062 int getLength();
00063 void setPosition(int position);
00064 int getPosition();
00065
00066 private:
00067 OALOutputStream(
00068 OALAudioDevice* device,
00069 SampleSource* source,
00070 ALuint al_source,
00071 ALuint* buffers,
00072 ALenum format,
00073 int sample_rate);
00074 ~OALOutputStream();
00075
00076 void update();
00077 int read(void* samples, int sample_count);
00078 void fillBuffers();
00079
00080 private:
00081 RefPtr<OALAudioDevice> m_device;
00082 RefPtr<SampleSource> m_source;
00083
00084
00085 ALenum m_format;
00086 int m_sample_size;
00087 int m_sample_rate;
00088
00089
00090 ALubyte* m_last_sample;
00091
00092
00093 ALuint m_ALsource;
00094 ALuint* m_buffers;
00095
00096 int m_buffer_length;
00097 bool m_is_playing;
00098 float m_volume;
00099
00100 friend class OALAudioDevice;
00101 };
00102
00103 }
00104
00105
00106 #endif