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"
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
);
41 boost::shared_ptr
<class OpenALBackend
> backend
;
42 OpenALBuffer(boost::shared_ptr
<class OpenALBackend
>, ALuint
);
43 friend class OpenALBackend
;
44 friend class OpenALSource
;
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
;
56 static inline void intrusive_ptr_add_ref(OpenALBuffer
*p
) {
59 static inline void intrusive_ptr_release(OpenALBuffer
*p
) {
64 class OpenALSource
: public SkeletonAudioSource
{
66 boost::shared_ptr
<class OpenALBackend
> backend
;
67 OpenALSource(boost::shared_ptr
<class OpenALBackend
>);
68 friend class OpenALBackend
;
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 */
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
{
93 ALfloat ListenerOri
[6];
94 ALfloat ListenerVel
[3];
95 ALfloat ListenerPos
[3];
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());
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
);