]> git.tdb.fi Git - libs/al.git/blob - source/soundscape.cpp
Add gain to SoundScape
[libs/al.git] / source / soundscape.cpp
1 #include "source.h"
2 #include "soundscape.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace AL {
8
9 SoundScape::SoundScape():
10         gain(1)
11 { }
12
13 SoundScape::~SoundScape()
14 {
15         for(list<Source *>::iterator i=sources.begin(); i!=sources.end(); ++i)
16                 delete *i;
17 }
18
19 void SoundScape::set_gain(float g)
20 {
21         gain = g;
22         for(list<Source *>::iterator i=sources.begin(); i!=sources.end(); ++i)
23                 (*i)->set_gain(gain);
24 }
25
26 void SoundScape::add_source(Source &src)
27 {
28         sources.push_back(&src);
29 }
30
31 Source &SoundScape::play(const Buffer &buf, float x, float y, float z)
32 {
33         Source *src = new Source;
34         add_source(*src);
35         src->set_buffer(buf);
36         src->set_position(x, y, z);
37         src->set_gain(gain);
38         src->play();
39         return *src;
40 }
41
42 void SoundScape::tick()
43 {
44         for(list<Source *>::iterator i=sources.begin(); i!=sources.end();)
45         {
46                 if((*i)->get_state()==STOPPED)
47                 {
48                         delete *i;
49                         i = sources.erase(i);
50                 }
51                 else
52                         ++i;
53         }
54 }
55
56 } // namespace AL
57 } // namespace Msp