ccdevnet / openc2e

openc2e

This URL has Read+Write access

openc2e / src / AudioBackend.h
100644 114 lines (94 sloc) 3.299 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* AudioBackend.h
* openc2e
*
* Created by Bryan Donlan on Sun Aug 12 2007.
* Copyright (c) 2007 Bryan Donlan. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
 
#ifndef SOUNDBACKEND_H
#define SOUNDBACKEND_H 1
 
#include <boost/intrusive_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
 
#include <string>
 
class AudioBuffer;
 
namespace boost {
static inline void intrusive_ptr_add_ref(AudioBuffer *p);
static inline void intrusive_ptr_release(AudioBuffer *p);
};
 
class AudioBuffer {
friend void boost::intrusive_ptr_add_ref(AudioBuffer *p);
friend void boost::intrusive_ptr_release(AudioBuffer *p);
 
protected:
virtual void add_ref() = 0;
virtual void del_ref() = 0;
 
public:
virtual ~AudioBuffer() { }
virtual unsigned int length_ms() const = 0; /* milliseconds */
virtual unsigned int length_samples() const = 0;
};
 
typedef boost::intrusive_ptr<AudioBuffer> AudioClip;
namespace boost {
static inline void intrusive_ptr_add_ref(AudioBuffer *p) {
p->add_ref();
}
static inline void intrusive_ptr_release(AudioBuffer *p) {
p->del_ref();
}
};
 
enum SourceState { SS_STOP, SS_PLAY, SS_PAUSE };
 
class AudioSource : public boost::enable_shared_from_this<AudioSource> {
protected:
AudioSource() { }
 
public:
virtual ~AudioSource() { }
virtual AudioClip getClip() = 0;
virtual void setClip(const AudioClip &) = 0; /* Valid only in STOP state */
virtual SourceState getState() const = 0;
virtual void play() = 0; /* requires that getClip() not be a null ref */
virtual void stop() = 0;
virtual void pause() = 0;
virtual void fadeOut() = 0;
virtual void setPos(float x, float y, float plane) = 0;
virtual void getPos(float &x, float &y, float &plane) const = 0;
virtual void setVelocity(float x, float y) = 0;
virtual bool isLooping() const = 0;
virtual void setLooping(bool) = 0;
virtual void setVolume(float vol) = 0;
virtual float getVolume() const = 0;
float getEffectiveVolume() const { return isMuted() ? 0 : getVolume(); }
virtual bool isMuted() const = 0;
virtual void setMute(bool) = 0;
 
// Set true to lock the location of this source to the viewpoint
virtual bool isFollowingView() const = 0;
virtual void setFollowingView(bool) = 0;
};
 
class AudioBackend : public boost::enable_shared_from_this<AudioBackend> {
protected:
AudioBackend() { }
 
public:
virtual void init() = 0;
virtual void shutdown() = 0;
virtual ~AudioBackend() { }
virtual void setViewpointCenter(float x, float y) = 0;
virtual void setMute(bool) = 0;
virtual bool isMuted() const = 0;
 
/* TODO: global vol controls */
virtual boost::shared_ptr<AudioSource> newSource() = 0;
virtual AudioClip loadClip(const std::string &filename) = 0;
 
virtual void begin() { }
virtual void commit() { }
};
 
#endif
 
/* vim: set noet: */