Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
Loading...
Searching...
No Matches
DataBuffer.h
1
11class DataBuffer
12{
13 private:
14 // Buffer type: char (c), int32 (d), float (f)
15 char _type;
16 // Container for raw byte buffer
17 std::vector<char> _buffer;
18
19 void setType (char type)
20 {
21 if(type == 'c' || type == 'd' || type == 'f')
22 {
23 _type = type;
24 }
25 else
26 {
27 printf("Type unkown. Creating byte (char) buffer.\n");
28 }
29 }
30 public:
31 DataBuffer(){};
32 DataBuffer(char type, unsigned int size)
33 {
34 setup(type, size);
35 }
36 ~DataBuffer(){};
37 void cleanup();
38
45 void setup(char type, unsigned int size)
46 {
47 setType(type);
48 unsigned int bufferSize = (_type == 'c' ? size : size * sizeof(float));
49 _buffer.resize(bufferSize);
50 }
51
57 unsigned int getNumElements()
58 {
59 if (_type == 'd')
60 {
61 return _buffer.size() / sizeof(int32_t);
62 }
63 else if (_type == 'f')
64 {
65 return _buffer.size() / sizeof(float);
66 }
67 else
68 {
69 return _buffer.size();
70 }
71 }
72
77 unsigned int getNumBytes(){ return _buffer.size(); };
83 unsigned int getCapacity(){ return _buffer.capacity(); };
87 char getType(){ return _type; };
91 std::vector<char>* getBuffer() { return &_buffer; };
95 char* getAsChar() { return _buffer.data(); };
99 int32_t* getAsInt() { return (int32_t*) _buffer.data(); };
103 float* getAsFloat() { return (float*) _buffer.data(); };
104
105};
std::vector< char > * getBuffer()
Definition DataBuffer.h:91
void setup(char type, unsigned int size)
Definition DataBuffer.h:45
unsigned int getNumElements()
Definition DataBuffer.h:57
float * getAsFloat()
Definition DataBuffer.h:103
unsigned int getCapacity()
Definition DataBuffer.h:83
char getType()
Definition DataBuffer.h:87
unsigned int getNumBytes()
Definition DataBuffer.h:77
int32_t * getAsInt()
Definition DataBuffer.h:99
char * getAsChar()
Definition DataBuffer.h:95