read Blackboard data correctly from the SFC file, and construct a BlackboardPart...
[openc2e.git] / AudioBackend.h
blobbdc750fdf76e846581317b0427019aef07cf9eaf
1 /*
2 * AudioBackend.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 SOUNDBACKEND_H
21 #define SOUNDBACKEND_H 1
23 #include <boost/intrusive_ptr.hpp>
24 #include <boost/shared_ptr.hpp>
25 #include <boost/enable_shared_from_this.hpp>
27 #include <string>
29 class AudioBuffer;
31 namespace boost {
32 static inline void intrusive_ptr_add_ref(AudioBuffer *p);
33 static inline void intrusive_ptr_release(AudioBuffer *p);
36 class AudioBuffer {
37 friend void boost::intrusive_ptr_add_ref(AudioBuffer *p);
38 friend void boost::intrusive_ptr_release(AudioBuffer *p);
40 protected:
41 virtual void add_ref() = 0;
42 virtual void del_ref() = 0;
44 public:
45 virtual ~AudioBuffer() { }
46 virtual unsigned int length_ms() = 0; /* milliseconds */
47 virtual unsigned int length_samples() = 0;
50 typedef boost::intrusive_ptr<AudioBuffer> AudioClip;
51 namespace boost {
52 static inline void intrusive_ptr_add_ref(AudioBuffer *p) {
53 p->add_ref();
55 static inline void intrusive_ptr_release(AudioBuffer *p) {
56 p->del_ref();
60 enum SourceState { SS_STOP, SS_PLAY, SS_PAUSE };
62 class AudioSource : public boost::enable_shared_from_this<AudioSource> {
63 protected:
64 AudioSource() { }
66 public:
67 virtual ~AudioSource() { }
68 virtual AudioClip getClip() = 0;
69 virtual void setClip(AudioClip &) = 0; /* Valid only in STOP state */
70 virtual SourceState getState() = 0;
71 virtual void play() = 0; /* requires that getClip() not be a null ref */
72 virtual void stop() = 0;
73 virtual void pause() = 0;
74 virtual void fadeOut() = 0;
75 virtual void setPos(float x, float y, float plane) = 0;
76 virtual void getPos(float &x, float &y, float &plane) = 0;
77 virtual void setVelocity(float x, float y) = 0;
78 virtual bool isLooping() = 0;
79 virtual void setLooping(bool) = 0;
80 virtual void setVolume(float vol) = 0;
81 virtual float getVolume() = 0;
82 float getEffectiveVolume() { return isMuted() ? 0 : getVolume(); }
83 virtual bool isMuted() = 0;
84 virtual void setMute(bool) = 0;
87 class AudioBackend : public boost::enable_shared_from_this<AudioBackend> {
88 protected:
89 AudioBackend() { }
91 public:
92 virtual void init() = 0;
93 virtual void shutdown() = 0;
94 virtual ~AudioBackend() { }
95 virtual void setViewpointCenter(float x, float y) = 0;
96 virtual void setMute(bool) = 0;
97 virtual bool isMuted() = 0;
99 /* TODO: global vol controls */
100 virtual boost::shared_ptr<AudioSource> newSource() = 0;
101 virtual AudioClip loadClip(const std::string &filename) = 0;
103 virtual void begin() { }
104 virtual void commit() { }
107 #endif
109 /* vim: set noet: */