try to make build portable: remove SDL_mixer dependency, remove -f from cp command...
[openc2e.git] / OpenALBackend.h
blob78855037e24e06ef212d94842f3c030d0e03ff7a
1 /*
2 * OpenALBackend.h
3 * openc2e
5 * Created by Bryan Donlan on Sun Aug 12 2007.
6 * Copyright (c) 2007 Bryan Donlan. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #ifndef _OPENALBACKEND_H
21 #define _OPENALBACKEND_H
23 #include "SkeletonAudioBackend.h"
25 #include <al.h>
26 #include <alc.h>
27 #include <string>
29 class OpenALBuffer;
31 namespace boost {
32 static inline void intrusive_ptr_add_ref(OpenALBuffer *p);
33 static inline void intrusive_ptr_release(OpenALBuffer *p);
36 class OpenALBuffer : public SkeletonAudioBuffer {
37 friend void boost::intrusive_ptr_add_ref(OpenALBuffer *p);
38 friend void boost::intrusive_ptr_release(OpenALBuffer *p);
40 protected:
41 boost::shared_ptr<class OpenALBackend> backend;
42 OpenALBuffer(boost::shared_ptr<class OpenALBackend>, ALuint);
43 friend class OpenALBackend;
44 friend class OpenALSource;
46 ALuint buffer;
48 public:
49 ~OpenALBuffer() { alDeleteBuffers(1, &buffer); }
50 virtual unsigned int length_ms(); /* milliseconds */
51 virtual unsigned int length_samples();
54 typedef boost::intrusive_ptr<OpenALBuffer> OpenALClip;
55 namespace boost {
56 static inline void intrusive_ptr_add_ref(OpenALBuffer *p) {
57 p->add_ref();
59 static inline void intrusive_ptr_release(OpenALBuffer *p) {
60 p->del_ref();
64 class OpenALSource : public SkeletonAudioSource {
65 protected:
66 boost::shared_ptr<class OpenALBackend> backend;
67 OpenALSource(boost::shared_ptr<class OpenALBackend>);
68 friend class OpenALBackend;
70 OpenALClip clip;
71 ALuint source;
73 public:
74 ~OpenALSource() { stop(); alDeleteSources(1, &source); }
76 virtual AudioClip getClip();
77 virtual void setClip(AudioClip &); /* Valid only in STOP state */
78 virtual SourceState getState();
79 virtual void play(); /* requires that getClip() not be a null ref */
80 virtual void stop();
81 virtual void pause();
82 virtual void fadeOut();
83 virtual void setPos(float x, float y, float plane);
84 virtual void setVelocity(float x, float y);
85 virtual bool isLooping();
86 virtual void setLooping(bool);
87 virtual void setVolume(float v);
88 virtual void setMute(bool);
91 class OpenALBackend : public AudioBackend {
92 protected:
93 ALfloat ListenerOri[6];
94 ALfloat ListenerVel[3];
95 ALfloat ListenerPos[3];
96 bool muted;
98 public:
99 boost::shared_ptr<OpenALBackend> shared_from_this() {
100 return boost::static_pointer_cast<OpenALBackend, AudioBackend>(this->AudioBackend::shared_from_this());
102 boost::shared_ptr<const OpenALBackend> shared_from_this() const {
103 return boost::static_pointer_cast<const OpenALBackend, const AudioBackend>(this->AudioBackend::shared_from_this());
106 OpenALBackend() { }
107 void init();
108 void shutdown();
109 void updateListener();
110 void setViewpointCenter(float x, float y);
111 void setMute(bool m);
112 bool isMuted() { return muted; }
114 boost::shared_ptr<AudioSource> newSource();
115 AudioClip loadClip(const std::string &filename);
117 void begin();
118 void commit();
121 #endif
123 /* vim: set noet: */