-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBuffer.cpp
More file actions
65 lines (55 loc) · 1.88 KB
/
Buffer.cpp
File metadata and controls
65 lines (55 loc) · 1.88 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
/*
This file is part of the Sound library.
Copyright (C) 2008-2012 Benjamin Eikel <benjamin@eikel.org>
Copyright (C) 2008-2012 Claudius Jähn <claudius@uni-paderborn.de>
Copyright (C) 2008-2012 Ralf Petring <ralf@petring.net>
This library is subject to the terms of the Mozilla Public License, v. 2.0.
You should have received a copy of the MPL along with this library; see the
file LICENSE. If not, you can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "Buffer.h"
#include "Sound.h"
#include "SoundInternals.h"
#include <cstddef>
#include <sstream>
namespace Sound {
//! [static] factory
Buffer * Buffer::create() {
checkErrorStatus(__FILE__, __LINE__);
uint32_t bufferId;
alGenBuffers( 1, &bufferId );
if(!checkErrorStatus(__FILE__, __LINE__, "Could not create Buffer.") || bufferId==0 )
return nullptr;
return new Buffer(bufferId);
}
//! [ctor]
Buffer::Buffer(uint32_t _bufferId):bufferId(_bufferId) {
//ctor
}
//! [dtor]
Buffer::~Buffer() {
if(bufferId>0) {
alDeleteSources(1, &bufferId);
bufferId=0;
}
// std::cout << " ~buffer ";
//dtor
}
void Buffer::setData(unsigned int format,const void * buffer,unsigned int byte,unsigned int freq) {
alBufferData(bufferId, static_cast<ALenum>(format), buffer, static_cast<ALsizei>(byte), static_cast<ALsizei>(freq));
}
std::string Buffer::toString()const {
std::ostringstream s;
s << "Buffer("<<getBufferId()<<","<<getChannels()<<"ch," <<getFrequency()<<"hz,"<<getDataSize()<<"byte)";
return s.str();
}
int Buffer::getAttribute_i(unsigned int attrib)const {
int v=0;
alGetBufferi(bufferId, static_cast<ALenum>(attrib), &v);
return v;
}
int Buffer::getFrequency()const { return getAttribute_i(AL_FREQUENCY); }
int Buffer::getBits()const { return getAttribute_i(AL_BITS); }
int Buffer::getChannels()const { return getAttribute_i(AL_CHANNELS); }
int Buffer::getDataSize()const { return getAttribute_i(AL_SIZE); }
}