]> git.tdb.fi Git - libs/al.git/blob - source/buffer.cpp
Two more atribute setting functions in Source
[libs/al.git] / source / buffer.cpp
1 /* $Id$
2
3 This file is part of libmspal
4 Copyright © 2008 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "buffer.h"
9 #include "sound.h"
10
11 using namespace std;
12
13 namespace Msp {
14 namespace AL {
15
16 Buffer::Buffer()
17 {
18         alGenBuffers(1, &id);
19 }
20
21 Buffer::~Buffer()
22 {
23         alDeleteBuffers(1, &id);
24 }
25
26 void Buffer::data(Format fmt, const void *dt, sizei size, sizei freq)
27 {
28         alBufferData(id, fmt, dt, size, freq);
29 }
30
31 void Buffer::data(const Sound &snd)
32 {
33         data(snd.get_format(), snd.get_data(), snd.get_size(), snd.get_frequency());
34 }
35
36 void Buffer::load_data(const string &fn)
37 {
38         Sound sound;
39         sound.load_file(fn);
40
41         data(sound);
42 }
43
44
45 Buffer::Loader::Loader(Buffer &b):
46         buf(b)
47 {
48         add("sound_data", &Loader::sound_data);
49 }
50
51 void Buffer::Loader::sound_data(const string &data)
52 {
53         Sound sound;
54         sound.load_memory(data.data(), data.size());
55
56         buf.data(sound);
57 }
58
59 } // namespace AL
60 } // namespace Msp