Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
DataBuffer.h
1 
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  }
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 };
unsigned int getCapacity()
Definition: DataBuffer.h:83
unsigned int getNumElements()
Definition: DataBuffer.h:57
Definition: DataBuffer.h:11
unsigned int getNumBytes()
Definition: DataBuffer.h:77
int32_t * getAsInt()
Definition: DataBuffer.h:99
char getType()
Definition: DataBuffer.h:87
void setup(char type, unsigned int size)
Definition: DataBuffer.h:45
float * getAsFloat()
Definition: DataBuffer.h:103
char * getAsChar()
Definition: DataBuffer.h:95
std::vector< char > * getBuffer()
Definition: DataBuffer.h:91