1 /** @file sound.cpp Interface for playing sounds.
2 *
3 * @authors Copyright (c) 2014-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4 *
5 * @par License
6 * LGPL: http://www.gnu.org/licenses/lgpl.html
7 *
8 * <small>This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or (at your
11 * option) any later version. This program is distributed in the hope that it
12 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
14 * General Public License for more details. You should have received a copy of
15 * the GNU Lesser General Public License along with this program; if not, see:
16 * http://www.gnu.org/licenses</small>
17 */
18
19 #include "de/Sound"
20
21 namespace de {
22
DENG2_PIMPL(Sound)23 DENG2_PIMPL(Sound)
24 {
25 dfloat volume;
26 dfloat pan;
27 dfloat frequency;
28 Vector3f position;
29 Vector3f velocity;
30 Positioning positioning;
31 dfloat minDistance;
32 dfloat spread;
33
34 Impl(Public *i)
35 : Base(i)
36 , volume(1.f)
37 , pan(0.f)
38 , frequency(1.f)
39 , positioning(Stereo)
40 , minDistance(1.f)
41 , spread(0)
42 {}
43
44 void update()
45 {
46 DENG2_FOR_PUBLIC_AUDIENCE2(Change, i)
47 {
48 i->soundPropertyChanged(self());
49 }
50 self().update();
51 }
52
53 DENG2_PIMPL_AUDIENCE(Play)
54 DENG2_PIMPL_AUDIENCE(Change)
55 DENG2_PIMPL_AUDIENCE(Stop)
56 DENG2_PIMPL_AUDIENCE(Deletion)
57 };
58
DENG2_AUDIENCE_METHOD(Sound,Play)59 DENG2_AUDIENCE_METHOD(Sound, Play)
60 DENG2_AUDIENCE_METHOD(Sound, Change)
61 DENG2_AUDIENCE_METHOD(Sound, Stop)
62 DENG2_AUDIENCE_METHOD(Sound, Deletion)
63
64 Sound::Sound() : d(new Impl(this))
65 {}
66
setVolume(dfloat volume)67 Sound &Sound::setVolume(dfloat volume)
68 {
69 d->volume = volume;
70 d->update();
71 return *this;
72 }
73
setPan(dfloat pan)74 Sound &Sound::setPan(dfloat pan)
75 {
76 d->pan = pan;
77 d->update();
78 return *this;
79 }
80
setFrequency(dfloat factor)81 Sound &Sound::setFrequency(dfloat factor)
82 {
83 d->frequency = factor;
84 d->update();
85 return *this;
86 }
87
setPosition(Vector3f const & position,Positioning positioning)88 Sound &Sound::setPosition(Vector3f const &position, Positioning positioning)
89 {
90 d->position = position;
91 d->positioning = positioning;
92 d->update();
93 return *this;
94 }
95
setVelocity(Vector3f const & velocity)96 Sound &Sound::setVelocity(Vector3f const &velocity)
97 {
98 d->velocity = velocity;
99 d->update();
100 return *this;
101 }
102
setMinDistance(dfloat minDistance)103 Sound &Sound::setMinDistance(dfloat minDistance)
104 {
105 d->minDistance = minDistance;
106 d->update();
107 return *this;
108 }
109
setSpatialSpread(dfloat degrees)110 Sound &Sound::setSpatialSpread(dfloat degrees)
111 {
112 d->spread = degrees;
113 d->update();
114 return *this;
115 }
116
isPlaying() const117 bool Sound::isPlaying() const
118 {
119 return mode() != NotPlaying;
120 }
121
volume() const122 dfloat Sound::volume() const
123 {
124 return d->volume;
125 }
126
pan() const127 dfloat Sound::pan() const
128 {
129 return d->pan;
130 }
131
frequency() const132 dfloat Sound::frequency() const
133 {
134 return d->frequency;
135 }
136
position() const137 Vector3f Sound::position() const
138 {
139 return d->position;
140 }
141
positioning() const142 Sound::Positioning Sound::positioning() const
143 {
144 return d->positioning;
145 }
146
velocity() const147 Vector3f Sound::velocity() const
148 {
149 return d->velocity;
150 }
151
minDistance() const152 dfloat Sound::minDistance() const
153 {
154 return d->minDistance;
155 }
156
spatialSpread() const157 dfloat Sound::spatialSpread() const
158 {
159 return d->spread;
160 }
161
162 } // namespace de
163